Chromium Code Reviews| 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: | |
| 29 if args: | |
| 30 parser.error("Cannot specify args with --dump-mode") | |
| 31 with open(options.output_json, 'w') as f: | |
| 32 json.dump(dict(os.environ), f) | |
| 33 else: | |
| 34 envsetup_cmd = ' '.join(args) | |
| 
 
Isaac (away)
2013/09/15 08:32:25
' '.join(pipes.quote(a) for a in args) 
would be
 
Isaac (away)
2013/09/15 08:34:02
Or: ' '.join(map(pipes.quote, args))
 
iannucci
2013/09/15 09:16:47
+1, I missed this.
 
 | |
| 35 full_cmd = [ | |
| 36 'bash', '-c', | |
| 37 '. %s; ./%s -d -f %s' % (envsetup_cmd, __file__, options.output_json)] | |
| 
 
Isaac (away)
2013/09/15 08:32:25
maybe the '.' at the beginning of line 37 should b
 
iannucci
2013/09/15 09:16:47
-1 on this. I would argue that the '.' (sourcing t
 
Isaac (away)
2013/09/15 09:28:04
:-D
 
 | |
| 38 ret = subprocess.call(full_cmd) | |
| 39 if ret: | |
| 40 sys.exit('Error running %s and dumping env', envsetup_cmd) | |
| 
 
Isaac (away)
2013/09/15 08:32:25
AFAIK, sys.exit only takes one arg. Running new sc
 
iannucci
2013/09/15 09:16:47
Oh, yeah, sys.exit takes an error code, not a stri
 
Isaac (away)
2013/09/15 09:28:04
It actually can take a string (siva showed me this
 
Siva Chandra
2013/09/15 09:39:14
sys.exit takes a string: http://docs.python.org/2.
 
 | |
| 41 | |
| 42 | |
| 43 if __name__ == '__main__': | |
| 44 sys.exit(main()) | |
| OLD | NEW |