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
|
#!/usr/bin/python
from patchtracker.DB import PatchTrackerDB, PackageWithoutDiffException
from patchtracker.Util import print_used_memory
import sys
import json
def main():
db = PatchTrackerDB()
packages = []
previous = {}
# Load data from previous calculations
for fn in sys.argv[1:]:
with open(fn) as f:
data = json.load(f)
for line in data:
previous[(line['package'], line['version'])] = \
{'series_type': line['series_type'],
'nondebian': line['nondebian'],
'patches': line['patches']}
try:
i = 0
for package, suite, version in db.enumerate_packages():
# Just for testing and debugging...
#if package not in ['geogebra', 'wotsap', 'netrw', 'haskell-devscripts',
# 'haskell-filestore', 'openide-utils']:
# continue
print >> sys.stderr, "%d %s %s %s" % (i, package, suite, version)
i += 1
if (package, version) not in previous:
prev_package = previous[(package, version)] = {}
try:
dh = db.makeDiffHandler(package, version)
series = dh.series(ghost=True)
if series:
prev_package['series_type'] = series.style
else:
prev_package['series_type'] = "no_series"
try:
nondebian_diff = dh.nondebiandir(ghost=True)
prev_package['nondebian'] = nondebian_diff.diffstat().lines()
except AttributeError:
# This means that the handler is a DebTarHandler
prev_package['nondebian'] = [0, 0, 0]
except PackageWithoutDiffException:
# The package is native
prev_package['series_type'] = "native"
prev_package['nondebian'] = [0, 0, 0]
prev_package['patches'] = [(patch, patch_data.diffstat().lines()) for (patch, patch_data) in series]
prev_package = previous[(package, version)]
packages.append({'package': package, 'suite': suite, 'version': version,
'series_type': prev_package['series_type'],
'nondebian': prev_package['nondebian'],
'patches': prev_package['patches']})
# This is mainly intended for debugging: if you want to interrupt the
# process, you still can obtain the JSON with the packages processed so far.
# Consistency is assured by the fact that append() is atomic in Python
except KeyboardInterrupt:
pass
# TODO We don't need to keep all the packages dictionary in memory; there are
# libraries to access JSON in a stream (DOM-like) fashion, but Python
# bindings don't appear to be available in Debian (libyajl)
# Pretty printing:
#json.dump(packages, sys.stdout, sort_keys=True, indent=4)
# Awful printing:
json.dump(packages, sys.stdout)
if __name__ == '__main__':
main()
|