from ConfigParser import ConfigParser from contextlib import closing from datetime import datetime from subprocess import Popen, PIPE from urllib2 import urlopen from portage import portagetree from portage.versions import pkgsplit, vercmp import os, sys port = portagetree() parser = ConfigParser() HTML = """\ Version bump checker

Version bump checker

%(table)s
Package Our version Upstream version Up-to-date?

Last update: %(date)s UTC

""" def tuple2dict(tup): rv = {} for name, value in tup: rv[name] = value return rv def load_configs(argv): loaded_files = parser.read(argv) print >> sys.stderr, 'config files loaded: ' + ', '.join(loaded_files) print >> sys.stderr def search_bumps(): rv = {} for section in parser.sections(): print >> sys.stderr, 'searching: %s' % section rv[section] = {} pkg = tuple2dict(parser.items(section)) try: with closing(urlopen(pkg['url'])) as fp: content = fp.read() version = '' except: rv[section]['fail'] = 'fetch' for line in pkg['command'].split('\n'): p = Popen(line, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate(content) if p.returncode != os.EX_OK: rv[section]['fail'] = 'command' version += stdout.strip() versions = port.dep_match(section) last_atom = versions[-1] cp, current_version, r = pkgsplit(last_atom) if 'status' not in rv[section].keys(): rv[section]['current_version'] = current_version rv[section]['upstream_version'] = version rv[section]['up2date'] = vercmp(version, current_version) <= 0 return rv def generate_html(pkgs): tmp = '' for pkg in pkgs: if 'fail' not in pkgs[pkg]: tmp += '%s%s%s' % ( pkg, pkgs[pkg]['current_version'], pkgs[pkg]['upstream_version'], ) tmp += '%s\n' % ( pkgs[pkg]['up2date'] and 'green' or 'red', pkgs[pkg]['up2date'] and 'yes' or 'no', ) date = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') return HTML % dict(table = tmp, date=date) if __name__ == '__main__': load_configs(sys.argv[1:]) print generate_html(search_bumps())