aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-08-05 09:54:26 +0300
committerPriit Laes <plaes@plaes.org>2010-08-05 09:54:26 +0300
commit9773844bbd624e66949ac0e200c5cb0ac4386d81 (patch)
tree1fd5bade403630e0f74b846f8429eff982add837 /utils
parentAdded few convenience utils for version checks (diff)
downloadgsoc2010-grumpy-9773844bbd624e66949ac0e200c5cb0ac4386d81.tar.gz
gsoc2010-grumpy-9773844bbd624e66949ac0e200c5cb0ac4386d81.tar.bz2
gsoc2010-grumpy-9773844bbd624e66949ac0e200c5cb0ac4386d81.zip
Added version check plugin
Diffstat (limited to 'utils')
-rw-r--r--utils/version_check.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/utils/version_check.py b/utils/version_check.py
new file mode 100644
index 0000000..20d1caa
--- /dev/null
+++ b/utils/version_check.py
@@ -0,0 +1,105 @@
+#! /usr/bin/env python
+import os, sys
+from datetime import datetime
+from lxml.html import fromstring
+from optparse import OptionParser
+
+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, Package, PkgIssue, Setting
+from grumpy.utils import compare_version
+
+PLUGIN_NAME='ver_bumper::'
+
+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@gentoo.org' in invalid:
+ h = Developer.query.filter_by(email='maintainer-needed@gentoo.org').first()
+ for pkg in h.packages:
+ pkg.qaissues.append(PkgIssue(pkg, PLUGIN_NAME, 'maintainer-needed'))
+ invalid.remove('maintainer-needed@gentoo.org')
+ for dev in invalid:
+ d = Developer.query.filter_by(email=dev).first()
+ for pkg in d.packages:
+ pkg.qaissues.append(PkgIssue(pkg, PLUGIN_NAME, 'unknown-dev', \
+ 'Maintainer %s listed in metadata.xml is not as ' \
+ 'an active Gentoo developer.' % dev))
+ db.session.commit()
+
+if __name__ == '__main__':
+ from grumpy.vdb.pypi import PyPi
+ parser = OptionParser(usage="usage: %prog [options] CONFFILE")
+ (opts, args) = parser.parse_args()
+ if len(args) != 1:
+ parser.error("provide path to configuration file as first argument")
+ sys.exit(1)
+ # ...
+ pypi = PyPi()
+ items = pypi.fetch_and_parse_all()
+ # Gather package versions
+ updates = {}
+ missing = []
+ for p in pypi.pkgs:
+ pyp = pypi.pkgs[p]
+ if pyp not in items.keys():
+ missing.append([p, pyp])
+ else:
+ updates[p] = items[pyp]
+ PLUGIN_NAME = PLUGIN_NAME + pypi.__class__.__name__
+ with app.test_request_context():
+ timestamp = datetime.now()
+ app.config.from_pyfile(args[0])
+ try:
+ # Delete existing issues
+ print ("DEBUG: Deleted %d old issues." % PkgIssue.query \
+ .filter_by(plugin=PLUGIN_NAME) \
+ .filter(PkgIssue.created_on < timestamp).delete(False))
+ db.session.commit()
+
+ # File 'missing' package mapping issues
+ for item in missing:
+ p = Package.query.filter_by(key=item).first()
+ if not p:
+ print "DEBUG: package '%s' is missing from upstream." % item
+ continue
+ p.qaissues.append(PkgIssue(p, PLUGIN_NAME, \
+ 'missing-upstream', \
+ 'No package "%s" found in upstream: %s' % \
+ (item, pypi.__class__.__name__)))
+ # Run version checks
+ # TODO: Figure out slotted ebuilds
+ for pkg, ver in updates.iteritems():
+ p = Package.query.filter_by(key=pkg).first()
+ if not p:
+ print "DEBUG: package '%s' is missing from portage." % item
+ continue
+ # We need to sort pkg versions
+ ver = sorted(ver, compare_version, reverse=True)
+ res = compare_version(ver[0], p.versions[0])
+ if res == -1:
+ p.qaissues.append(PkgIssue(p, PLUGIN_NAME, \
+ 'version-mismatch', 'Package "%s" has newer version in ' \
+ 'Portage than on "%s" upstream' % \
+ (pkg, pypi.__class__.__name__)))
+ elif res == 1:
+ p.qaissues.append(PkgIssue(p, PLUGIN_NAME, \
+ 'version-bump', 'Package "%s" has newer version "%s" '
+ 'available in "%s" upstream ' % \
+ (pkg, p.versions[0], pypi.__class__.__name__)))
+ db.session.commit()
+ # 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()
+ except Exception:
+ db.session.rollback()