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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
#!/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
from Cheetah.Compiler import Compiler
class Conf:
archive_root = '/scratch/debian-archive/debian'
archive_root_url = 'ftp://ftp.se.debian.org/debian'
output_dir = '/scratch/patches'
template_dir = './templates'
static_dir = './static'
root_url = 'http://people.debian.org/~seanius/pts/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"
if self.diffgz != None:
self.debianonlydiff = "_".join([self.name, self.version, "debianonly.diff"])
self.nondebiandiff = "_".join([self.name, self.version, "nondebian.diff"])
def idx(self):
name = str(self)
if len(name) < 4 or name[0:3] != "lib":
return name[0]
else:
return name[0:4]
## XXX okay, all of this could be made quite a bit cleaner
def diff_series(self, outdir):
if self.diffgz:
debdiff = os.sep.join([outdir, self.debianonlydiff])
seriesdir = os.sep.join([outdir, "series"])
try:
os.mkdir(os.sep.join([outdir,"series"]))
except OSError, e:
if e.errno != errno.EEXIST:
raise e
os.system("filterdiff -p 1 -i 'debian/patches/*' "+debdiff+"| ( cd "+
seriesdir+"; patch -s )")
for (blah,blahblah,files) in os.walk(seriesdir):
try:
files.remove('series')
files.remove('00list')
except:
pass
for f in files:
p = os.sep.join([seriesdir, f])
# get the info for summary generation
fd = os.popen("diffstat "+p)
self.seriespatches[f] = fd.read()
fd.close()
os.system("source-highlight -s diff -f xhtml -i "+p+" -o "+p+".html")
def diff_debiandir(self, outdir):
try:
src = os.sep.join([Conf.archive_root, self.loc, self.diffgz['name']])
dst = os.sep.join([outdir, self.debianonlydiff])
os.system("filterdiff -z -p 1 -i 'debian/*' "+src+" > "+dst)
os.system("source-highlight -s diff -f xhtml -i "+dst+" -o "+dst+".html")
# in the case of native packages there is no diffgz
except TypeError:
pass
def diff_nondebiandir(self, outdir):
try:
src = os.sep.join([Conf.archive_root, self.loc, self.diffgz['name']])
dst = os.sep.join([outdir, self.nondebiandiff])
os.system("filterdiff -z -p 1 -x 'debian/*' "+src+" > "+dst)
os.system("source-highlight -s diff -f xhtml -i "+dst+" -o "+dst+".html")
# in the case of native packages there is no diffgz
except TypeError:
pass
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):
dstdir = os.sep.join([Conf.output_dir, "packages", template.src.name, template.src.version])
try:
os.makedirs(dstdir)
except OSError, e:
if e.errno != errno.EEXIST:
raise e
template.src.diff_debiandir(dstdir)
template.src.diff_nondebiandir(dstdir)
template.src.diff_series(dstdir)
dst = os.sep.join([dstdir, "index.html"])
PageWriter.__init__(self, dst, template)
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__':
os.system("cheetah compile templates/skeleton")
a = Archive(Conf.archive_root)
# just for now until development stablizes
os.system("rm -rf "+Conf.output_dir)
os.mkdir(Conf.output_dir)
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
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))
|