1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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))
|