#!/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()