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 # This script can either source a file and dump the enironment changes done by | |
7 # it, or just simply dump the current environment as JSON into a file. | |
8 | |
9 import json | |
10 import optparse | |
11 import os | |
12 import subprocess | |
13 import sys | |
14 | |
15 | |
16 def main(): | |
17 parser = optparse.OptionParser() | |
18 parser.add_option('-f', '--output-json', | |
19 help='File to dump the environment as JSON into.') | |
20 parser.add_option( | |
21 '-d', '--dump-mode', action='store_true', | |
22 help='Dump the environment to the file and exit immediately.') | |
23 | |
24 options, args = parser.parse_args() | |
25 if not options.output_json: | |
26 parser.error('Requires --output-json option.') | |
27 | |
28 if options.dump_mode or not args: | |
29 with open(options.output_json, 'w') as f: | |
iannucci
2013/09/14 00:23:31
Actually, I would do
if options.dump_mode:
if a
| |
30 json.dump(dict(os.environ), f) | |
31 else: | |
32 envsetup_cmd = ' '.join(args) | |
33 full_cmd = [ | |
34 'bash', '-c', | |
35 '. %s; ./%s -d -f %s' % (envsetup_cmd, __file__, options.output_json)] | |
36 ret = subprocess.call(full_cmd) | |
37 if ret: | |
38 sys.exit('Error running %s and dumping env', envsetup_cmd) | |
39 | |
40 | |
41 if __name__ == '__main__': | |
42 sys.exit(main()) | |
OLD | NEW |