diff options
author | Sean Finney <seanius@debian.org> | 2009-07-26 19:35:16 +0200 |
---|---|---|
committer | Sean Finney <seanius@debian.org> | 2009-07-26 19:35:16 +0200 |
commit | 9d9c75b7666123273aeccd96248f1413c287b207 (patch) | |
tree | 3d575af86c751f43c389950626d9406446756b99 | |
parent | 214268f80d89d279be7fb046f7fa3bde048af793 (diff) | |
download | patch-tracker-9d9c75b7666123273aeccd96248f1413c287b207.tar.gz |
initial support for PTS index file generation
a new option (-i) to ./gen-patch-info.py allows for generating a global
"index" file with any and all information that the PTS might want from
this system. The format is:
{
"index-version": N
"packages":
{
"<pkg1>":
{
"url": url-for-all-versions
"versions":
{
"<vers1>":
{
<various attributes>
}
}
}
}
}
index-version is a monotonically increasing version number. when the
"schema" changes, this version is incremented. if we care enough, we
can do a major-minor versioning scheme where BC breaks are differentiated
from "new attribute" type changes by incrementing the major or minor
versions, respectively.
-rwxr-xr-x | gen-patch-info.py | 14 | ||||
-rwxr-xr-x | patchtracker/Conf.py | 6 | ||||
-rw-r--r-- | patchtracker/PtsIndex.py | 33 |
3 files changed, 52 insertions, 1 deletions
diff --git a/gen-patch-info.py b/gen-patch-info.py index 5d7d899..ef1621e 100755 --- a/gen-patch-info.py +++ b/gen-patch-info.py @@ -4,19 +4,23 @@ import os import sys import getopt +import gzip import errno +import simplejson import patchtracker.Conf as Conf from patchtracker.SourceArchive import Archive, SourcePackage from patchtracker.DB import PatchTrackerDB +from patchtracker.PtsIndex import PtsIndexFile if __name__ == '__main__': db = PatchTrackerDB() os.system("cheetah compile templates/skeleton") - opts,args = getopt.getopt(sys.argv[1:], "as:p:") + opts,args = getopt.getopt(sys.argv[1:], "ais:p:") suites = None packages = None update_archive = False + gen_pts_index = False for o,v in opts: if o == "-s": suites = v.split(',') @@ -24,6 +28,8 @@ if __name__ == '__main__': packages = v.split(',') elif o == "-a": update_archive = True + elif o == "-i": + gen_pts_index = True if update_archive: os.system("env PYTHONPATH=%s reprepro -b %s --confdir reprepro/conf update"% @@ -50,6 +56,12 @@ if __name__ == '__main__': db.relateSourcePackage(name=p.name, version=p.version, suite=s, component=c) + if gen_pts_index: + pts_idx = PtsIndexFile(a) + pts_fh = gzip.GzipFile(Conf.pts_index_file, mode="wb") + simplejson.dump(pts_idx, pts_fh) + pts_fh.close() + db.prune() db.unmark() db.finalize() diff --git a/patchtracker/Conf.py b/patchtracker/Conf.py index beb2b71..954001e 100755 --- a/patchtracker/Conf.py +++ b/patchtracker/Conf.py @@ -16,6 +16,12 @@ use_apt_pkg = None to False instead of None """ +pts_index_file = "pts-index.json.gz" +""" The name of the JSON encoded "whole system index" that we can optionally + export (the -i option to gen-patch-info) for mass-grabbing of statistics + by the PTS system +""" + try: from localconfig import * except ImportError: diff --git a/patchtracker/PtsIndex.py b/patchtracker/PtsIndex.py new file mode 100644 index 0000000..6f60863 --- /dev/null +++ b/patchtracker/PtsIndex.py @@ -0,0 +1,33 @@ +import os + +import Conf +from DiffGzHandler import DiffGzHandler + +class PtsIndexPackageInfo ( dict ): + def __init__ (self, srcpkg): + dict.__init__(self) + self['type'] = srcpkg.type + self['format'] = srcpkg.format + + if srcpkg.diffgz_name: + diffgz = os.sep.join([Conf.archive_root,srcpkg.loc,srcpkg.diffgz_name]) + dh = DiffGzHandler( diffgz ) + ser = dh.series() + if ser: + self['series-patches'] = len(ser) + self['url'] = '%s/packages/%s/%s'%(Conf.root_url, + srcpkg.name,srcpkg.version) + +class PtsIndexFile ( dict ): + def __init__ (self, archive, suites=None, packages=None): + dict.__init__(self) + self['index-version'] = 1 + self['packages'] = {} + for s in archive.suites(filter=suites): + for c in archive.components(s): + for p in archive.sourcepackages(s, c, filter=packages): + if not self['packages'].has_key(p.name): + url = '%s/packages/%s'%(Conf.root_url, p.name) + self['packages'][p.name] = { 'url': url, 'versions': {} } + if not self['packages'][p.name].has_key(p.version): + self['packages'][p.name]['versions'][p.version]=PtsIndexPackageInfo(p) |