summaryrefslogtreecommitdiff
path: root/gen-patch-info.py
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2008-06-02 00:14:35 +0200
committerSean Finney <seanius@debian.org>2008-06-02 00:14:35 +0200
commitd84c4c56500e5de9109507cf46476505d4b1d0a9 (patch)
tree58de0ab4b1fe0fbd7dd5ed0c5cb20b5cb7bc6805 /gen-patch-info.py
downloadpatch-tracker-d84c4c56500e5de9109507cf46476505d4b1d0a9.tar.gz
initial work-in-progress code
Diffstat (limited to 'gen-patch-info.py')
-rwxr-xr-xgen-patch-info.py184
1 files changed, 184 insertions, 0 deletions
diff --git a/gen-patch-info.py b/gen-patch-info.py
new file mode 100755
index 0000000..74d819f
--- /dev/null
+++ b/gen-patch-info.py
@@ -0,0 +1,184 @@
+#!/usr/bin/python
+
+import os
+import errno
+import string
+import tempfile
+from fnmatch import fnmatch
+from gzip import GzipFile
+from debian_bundle import deb822
+from Cheetah.Template import Template
+
+class Conf:
+ archive_root = '/scratch/debian-archive/debian'
+ output_dir = '/scratch/patches'
+ template_dir = './templates'
+ static_dir = './static'
+ root_url = '/patches'
+
+class Archive:
+ root = None
+ distsdir = None
+
+ def __init__(self, dir):
+ self.root = dir
+ self.distsdir = os.sep.join([dir, "dists"])
+
+ def suites(self):
+ for s in os.listdir(self.distsdir):
+ yield s
+
+ def components(self, suite):
+ f = file(self.distsdir + os.sep + os.sep.join([suite, "Release"]))
+ rel = deb822.Release(f)
+ for comp in rel['Components'].split(' '):
+ yield comp
+
+ def sourcepackages(self, suite, component):
+ sfile=os.sep.join([self.distsdir,suite,component,"/source/Sources.gz"])
+ for ent in deb822.Sources.iter_paragraphs(GzipFile(sfile)):
+ yield SourcePackage(ent)
+
+ def __str__(self):
+ return "Archive rooted at "+self.root
+
+class PageWriter:
+ def __init__(self, filename, template):
+ try:
+ os.makedirs(os.path.dirname(filename))
+ except OSError, e:
+ if e.errno != errno.EEXIST:
+ raise e
+ o = file(filename, "w")
+ o.write(str(template))
+ o.close()
+
+class SourcePackage:
+ name = None
+ format = None
+ diffgz = None
+ loc = None
+ type = "Native"
+ version = None
+ seriespatches = []
+ directpatches = []
+ # todo
+ vcs = {}
+
+ def __init__(self, info):
+ self.name = info['Package']
+ self.format = info['Format']
+ self.loc = info['Directory']
+ self.version = info['Version']
+
+ for f in info['Files']:
+ if fnmatch(f['name'], '*.diff.gz'):
+ self.diffgz=f
+ self.type = "Debian-diff"
+
+ def idx(self):
+ name = str(self)
+ if len(name) < 4 or name[0:3] != "lib":
+ return name[0]
+ else:
+ return name[0:4]
+
+ def __str__(self):
+ return self.name
+
+class OurTemplate(Template):
+ def __init__(self, file):
+ Template.__init__(self, file=file, searchList={"conf":Conf})
+
+class PackageVersTemplate(OurTemplate):
+ src = None
+ suite = None
+
+ def __init__(self, srcpkg, suite):
+ self.src = srcpkg
+ self.suite = suite
+ tpl=os.sep.join([Conf.template_dir, "package-vers.tmpl"])
+ OurTemplate.__init__(self, file=tpl)
+
+class PackageVersWriter(PageWriter):
+ def __init__(self, template):
+ dst = os.sep.join([Conf.output_dir, "packages", template.src.name, template.src.version, "index.html"])
+ PageWriter.__init__(self, dst, template)
+
+ (tfd, tfn) = tempfile.mkstemp()
+ os.close(tfd)
+ #os.system("filterdiff -z -p 1 -x 'debian/*' blah > farsar")
+
+class SourcePackageIndex:
+ pkgs = {}
+
+ def ins(self, srcpkg, rel):
+ idx = srcpkg.idx()
+ if not self.pkgs.has_key(idx):
+ self.pkgs[idx] = {}
+ if not self.pkgs[idx].has_key(srcpkg.name):
+ self.pkgs[idx][srcpkg.name] = {}
+ if not self.pkgs[idx][srcpkg.name].has_key(rel):
+ self.pkgs[idx][srcpkg.name][rel] = srcpkg
+
+ def indices(self):
+ for k,v in self.pkgs.iteritems():
+ yield (k,v)
+
+class FrontPageTemplate(OurTemplate):
+ allindex = None
+ relindices = []
+
+ def __init__(self, allindex, release_indices=[]):
+ tpl = os.sep.join([Conf.template_dir, "frontpage.tmpl"])
+ OurTemplate.__init__(self, file=tpl)
+ self.allindex = allindex
+ self.relindices = release_indices
+
+class FrontPageWriter(PageWriter):
+ def __init__(self, template):
+ dest = os.sep.join([Conf.output_dir, "index.html"])
+ PageWriter.__init__(self, dest, template)
+
+class LetterTocTemplate(OurTemplate):
+ idx = None
+ pkgs = None
+ dists = None
+
+ def releases(self):
+ return dists
+
+ def __init__(self, letter, collection):
+ self.pkgs = collection
+ self.idx = letter
+ self.dists = {}
+ for name,packagelist in collection.iteritems():
+ for d in packagelist.iterkeys():
+ self.dists[d] = True
+ tpl = os.sep.join([Conf.template_dir, "letter-toc.tmpl"])
+ OurTemplate.__init__(self, file=tpl)
+
+class LetterTocWriter(PageWriter):
+
+ def __init__(self, template):
+ dest = os.sep.join([Conf.output_dir, "index", template.idx, "index.html"])
+ PageWriter.__init__(self, dest, template)
+
+if __name__ == '__main__':
+ a = Archive(Conf.archive_root)
+ print a
+ master_index = SourcePackageIndex()
+ for s in a.suites():
+ print "suite: ",s
+ for c in a.components(s):
+ print "\tcomponent:",c
+ for p in a.sourcepackages(s, c):
+ print "\t\tpackage:",p
+ print "\t\tdiff:",p.diffgz
+ PackageVersWriter(PackageVersTemplate(p, s))
+ master_index.ins(p,s)
+
+ os.system("cp -a "+Conf.static_dir+"/* "+Conf.output_dir)
+ FrontPageWriter(FrontPageTemplate(master_index))
+ for letter,stuff in master_index.indices():
+ LetterTocWriter(LetterTocTemplate(letter,stuff))