Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Unified Diff: cros_extract_deps

Issue 3148022: cros_extract_deps -j writes JSON, sorted by package name. (Closed) Base URL: ssh://gitrw.chromium.org/crosutils.git
Patch Set: Make json default. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cros_extract_deps
diff --git a/cros_extract_deps b/cros_extract_deps
index 87b7bdea9372b678d27693a762f5ef7e77b15e47..03ba92cafa2175241d1cb6ae5566464ff7be430a 100755
--- a/cros_extract_deps
+++ b/cros_extract_deps
@@ -5,8 +5,8 @@
"""Extract dependency tree out of emerge and make it accessible and useful."""
+import json
import optparse
-import pprint
import re
import shutil
import subprocess
@@ -23,6 +23,14 @@ class ParseException(Exception):
return self.reason
+class SetEncoder(json.JSONEncoder):
+ """Custom json encoder class, doesn't hate set types."""
+ def default(self, o):
+ if isinstance(o, set):
+ return list(o)
+ return json.JSONEncoder.default(self, o)
+
+
def GetDepLinesFromPortage(options, packages):
"""Get dependency lines out of emerge.
@@ -179,7 +187,7 @@ def main():
lines = GetDepLinesFromPortage(options, packages)
deps_map = ParseDepLines(lines)
- output = pprint.pformat(deps_map)
+ output = json.dumps(deps_map, sort_keys=True, indent=2, cls=SetEncoder)
if options.output:
output_file = open(options.output, 'w')
output_file.write(output)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698