diff options
author | Giovanni Mascellani <mascellani@poisson.phc.unipi.it> | 2011-07-31 12:01:47 +0200 |
---|---|---|
committer | Sean Finney <seanius@htpc-l.(none)> | 2011-09-17 13:28:46 +0200 |
commit | 36d723df4e46a36acde3cac2b8fda7678eddba8e (patch) | |
tree | 61e6b39ed57e20c89c949e710e9e367c35cc6806 | |
parent | 1e0c2ed9fb35436ba84bea0752d5a51772cfa51c (diff) | |
download | patch-tracker-36d723df4e46a36acde3cac2b8fda7678eddba8e.tar.gz |
Added export_for_udd.py script.
-rwxr-xr-x | export_for_udd.py | 71 | ||||
-rw-r--r-- | patchtracker/Util.py | 9 |
2 files changed, 80 insertions, 0 deletions
diff --git a/export_for_udd.py b/export_for_udd.py new file mode 100755 index 0000000..4220e2f --- /dev/null +++ b/export_for_udd.py @@ -0,0 +1,71 @@ +#!/usr/bin/python + +from patchtracker.DB import PatchTrackerDB, PackageWithoutDiffException +from patchtracker.Util import print_used_memory +import sys +import json + +def enumerate_packages(db): + for packages_per_letter in db.findCollection().pkgs.itervalues(): + for package_name, package_data in packages_per_letter.iteritems(): + for suite, package in package_data.iteritems(): + yield (package_name, suite, package.version) + +def main(): + db = PatchTrackerDB() + packages = [] + try: + i = 0 + for package, suite, version in enumerate_packages(db): + + # 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 + + try: + dh = db.makeDiffHandler(package, version) + series = dh.series(ghost=True) + if series: + series_type = series.style + else: + series_type = "no_series" + try: + nondebian_diff = dh.nondebiandir(ghost=True) + nondebian = nondebian_diff.diffstat().lines() + except AttributeError: + # This means that the handler is a DebTarHandler + nondebian = [0, 0, 0] + except PackageWithoutDiffException: + # The package is native + series_type = "native" + nondebian = [0, 0, 0] + + patches = [(patch, patch_data.diffstat().lines()) for (patch, patch_data) in series] + + packages.append({'package': package, 'suite': suite, 'version': version, + 'series_type': series_type, 'nondebian': nondebian, + 'patches': 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() + diff --git a/patchtracker/Util.py b/patchtracker/Util.py new file mode 100644 index 0000000..31a200c --- /dev/null +++ b/patchtracker/Util.py @@ -0,0 +1,9 @@ + +import resource +import sys + +def print_used_memory(msg): + """Small utility function to find where RAM is used at most.""" + r = resource.getrusage(resource.RUSAGE_SELF) + print >> sys.stderr, "%s; used memory = %d" % (msg, r.ru_maxrss) + |