aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-07-08 10:32:03 +0300
committerPriit Laes <plaes@plaes.org>2010-07-08 10:32:03 +0300
commitd8cc8edfc01a8033bbf28421785e90e7fcc5b93b (patch)
treefd81766587392f31b786d398f2213167b383b505
parentAdded PkgIssues class (diff)
downloadgsoc2010-grumpy-d8cc8edfc01a8033bbf28421785e90e7fcc5b93b.tar.gz
gsoc2010-grumpy-d8cc8edfc01a8033bbf28421785e90e7fcc5b93b.tar.bz2
gsoc2010-grumpy-d8cc8edfc01a8033bbf28421785e90e7fcc5b93b.zip
Added herd qa-checker
-rw-r--r--grumpy/models.py7
-rw-r--r--setup.py1
-rw-r--r--utils/qa_check_herd.py80
3 files changed, 86 insertions, 2 deletions
diff --git a/grumpy/models.py b/grumpy/models.py
index 7f0f13d..807557f 100644
--- a/grumpy/models.py
+++ b/grumpy/models.py
@@ -12,6 +12,7 @@
from . import app
from datetime import datetime
from flaskext.sqlalchemy import SQLAlchemy
+from sqlalchemy.sql import func
import json
@@ -172,15 +173,17 @@ class PkgIssue(db.Model):
plugin = db.Column('plugin', db.String)
type = db.Column('type', db.String)
data = db.Column('data', db.String)
+ created_on = db.Column('created_on', db.DateTime, default=func.now())
_package = db.Column('package_id', db.Integer, db.ForeignKey('packages.id'))
package = db.relationship(Package)
- def __init__(self, package, plugin, type, data):
+ def __init__(self, package, plugin, type, data=None):
self.package = package
self.plugin = plugin
self.data = data
self.type = type
def __repr__(self):
- return '<%s> - %s : %s' % (self.__class__.__name__, self.plugin, self.type)
+ return '<%s> - %s : %s' % \
+ (self.__class__.__name__, self.plugin, self.type)
diff --git a/setup.py b/setup.py
index 4d1926d..d4ef039 100644
--- a/setup.py
+++ b/setup.py
@@ -61,6 +61,7 @@ setup(
install_requires=[
'Flask',
'Flask-SQLAlchemy',
+ 'lxml',
'pkgcore',
'snakeoil',
'SQLAlchemy >= 0.6',
diff --git a/utils/qa_check_herd.py b/utils/qa_check_herd.py
new file mode 100644
index 0000000..21c5ead
--- /dev/null
+++ b/utils/qa_check_herd.py
@@ -0,0 +1,80 @@
+#! /usr/bin/env python
+import os, sys
+
+from datetime import datetime
+from lxml.etree import parse
+
+path = os.path.join(os.path.dirname(__file__), os.path.pardir)
+sys.path.insert(0, path)
+del path
+
+from grumpy import app
+from grumpy.models import db, Herd, PkgIssue, Setting
+
+PLUGIN_NAME='qa::valid_herd'
+
+def gc_collect(timestamp):
+ """Remove old QA issues from database returning number of rows deleted."""
+ db.session.expire_all()
+ print ("DEBUG: Deleted %d old issues." % PkgIssue.query \
+ .filter_by(plugin=PLUGIN_NAME) \
+ .filter(PkgIssue.created_on < timestamp).delete(False))
+
+def insert_issues(invalid):
+ """Insert QA issues into db."""
+ if 'maintainer-needed' in invalid:
+ h = Herd.query.filter_by(name='maintainer-needed').first()
+ for pkg in h.packages:
+ pkg.qaissues.append(PkgIssue(pkg, PLUGIN_NAME, 'maintainer-needed'))
+ invalid.remove('maintainer-needed')
+ if 'no-herd' in invalid:
+ h = Herd.query.filter_by(name='no-herd').first()
+ for pkg in h.packages:
+ pkg.qaissues.append(PkgIssue(pkg, PLUGIN_NAME, 'maintainer-needed'))
+ invalid.remove('no-herd')
+ if 'fix-me' in invalid:
+ h = Herd.query.filter_by(name='fix-me').first()
+ for pkg in h.packages:
+ pkg.qaissues.append(PkgIssue(pkg, PLUGIN_NAME, 'invalid-herd', \
+ 'Please use no-herd instead of empty tag'))
+ invalid.remove('fix-me')
+ for herd in invalid:
+ h = Herd.query.filter_by(name=herd).first()
+ for pkg in h.packages:
+ pkg.qaissues.append(PkgIssue(pkg, PLUGIN_NAME, 'unknown-herd', \
+ 'Herd %s is not listed in official herd list.' % herd))
+ db.session.commit()
+
+def parse_herds_xml(file):
+ """Return list of herd names from 'herds.xml'"""
+ herds = []
+ if not os.path.isfile(file):
+ print ("File '%s' does not exist" % file)
+ raise RuntimeError
+ for child in parse(file).getroot().getchildren():
+ for value in child.getchildren():
+ if value.tag == 'name':
+ herds.append(value.text)
+ return herds
+
+if __name__ == '__main__':
+ # TODO: Download latest herds file
+ # Parse list of herds from file
+ herds = parse_herds_xml('herds.xml')
+ b0rks = []
+ timestamp = datetime.now()
+ # Setup database for application
+ with app.test_request_context():
+ # Fetch list of herds from db
+ for herd in Herd.query.all():
+ if herd.name in herds:
+ herds.remove(herd.name)
+ else:
+ b0rks.append(herd.name)
+ insert_issues(b0rks)
+ # Clean up issues < timestamp
+ gc_collect(timestamp)
+ # Update settings and add info about last run..
+ Setting.query.filter_by(name=PLUGIN_NAME).delete(False)
+ db.session.add(Setting(PLUGIN_NAME, str(timestamp)))
+ db.session.commit()