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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extract dependency tree out of emerge and make it accessible and useful.""" 6 """Extract dependency tree out of emerge and make it accessible and useful."""
7 7
8 import json
8 import optparse 9 import optparse
9 import pprint
10 import re 10 import re
11 import shutil 11 import shutil
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 import tempfile 14 import tempfile
15 import time 15 import time
16 16
17 class ParseException(Exception): 17 class ParseException(Exception):
18 def __init__(self, reason): 18 def __init__(self, reason):
19 Exception.__init__(self) 19 Exception.__init__(self)
20 self.reason = reason 20 self.reason = reason
21 21
22 def __str__(self): 22 def __str__(self):
23 return self.reason 23 return self.reason
24 24
25 25
26 class SetEncoder(json.JSONEncoder):
27 """Custom json encoder class, doesn't hate set types."""
28 def default(self, o):
29 if isinstance(o, set):
30 return list(o)
31 return json.JSONEncoder.default(self, o)
32
33
26 def GetDepLinesFromPortage(options, packages): 34 def GetDepLinesFromPortage(options, packages):
27 """Get dependency lines out of emerge. 35 """Get dependency lines out of emerge.
28 36
29 This calls emerge -p --debug and extracts the 'digraph' lines which detail 37 This calls emerge -p --debug and extracts the 'digraph' lines which detail
30 the dependencies." 38 the dependencies."
31 """ 39 """
32 # Use a temporary directory for $ROOT, so that emerge will consider all 40 # Use a temporary directory for $ROOT, so that emerge will consider all
33 # packages regardless of current build status. 41 # packages regardless of current build status.
34 temp_dir = tempfile.mkdtemp() 42 temp_dir = tempfile.mkdtemp()
35 43
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 help='Also extract build-time dependencies.') 180 help='Also extract build-time dependencies.')
173 parser.add_option('-o', '--output', default=None, 181 parser.add_option('-o', '--output', default=None,
174 help='Output file.') 182 help='Output file.')
175 (options, packages) = parser.parse_args() 183 (options, packages) = parser.parse_args()
176 if not packages: 184 if not packages:
177 parser.print_usage() 185 parser.print_usage()
178 sys.exit(1) 186 sys.exit(1)
179 187
180 lines = GetDepLinesFromPortage(options, packages) 188 lines = GetDepLinesFromPortage(options, packages)
181 deps_map = ParseDepLines(lines) 189 deps_map = ParseDepLines(lines)
182 output = pprint.pformat(deps_map) 190 output = json.dumps(deps_map, sort_keys=True, indent=2, cls=SetEncoder)
183 if options.output: 191 if options.output:
184 output_file = open(options.output, 'w') 192 output_file = open(options.output, 'w')
185 output_file.write(output) 193 output_file.write(output)
186 output_file.close() 194 output_file.close()
187 else: 195 else:
188 print output 196 print output
189 197
190 198
191 if __name__ == '__main__': 199 if __name__ == '__main__':
192 main() 200 main()
OLDNEW
« 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