OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 # Output environment setup by src/build/android/envsetup.sh to json file. | |
7 | |
8 import json | |
9 import optparse | |
10 import os | |
11 import subprocess | |
12 import sys | |
13 | |
14 | |
15 def main(): | |
16 parser = optparse.OptionParser() | |
17 parser.add_option('-f', '--output-json', | |
18 help='Output json file to create with environment.') | |
19 parser.add_option( | |
20 '-d', '--dump-mode', action='store_true', | |
21 help='Dump the environment to stdout or file and exit immediately.') | |
22 | |
23 options, args = parser.parse_args() | |
iannucci
2013/09/14 00:08:36
maybe just do
if options.output_json is None:
p
| |
24 if options.dump_mode: | |
25 if options.output_json: | |
26 with open(options.output_json, 'w') as f: | |
27 json.dump(dict(os.environ), f) | |
28 else: | |
29 print json.dumps(dict(os.environ)) | |
30 return | |
iannucci
2013/09/14 00:08:36
let's do an else: instead of the early return
| |
31 | |
32 if not options.output_json: | |
33 parser.error('Requires --output-json or --dump-mode argument.') | |
34 | |
35 envsetup_cmd = ' '.join(args) | |
36 full_cmd = [ | |
37 'bash', '-c', | |
38 '. %s; ./%s -d -f %s' % (envsetup_cmd, __file__, options.output_json)] | |
39 ret = subprocess.call(full_cmd) | |
40 if ret: | |
41 sys.exit('Error running %s and dumping env', envsetup_cmd) | |
42 | |
43 | |
44 if __name__ == '__main__': | |
45 sys.exit(main()) | |
OLD | NEW |