Index: build/env_dump.py |
diff --git a/build/env_dump.py b/build/env_dump.py |
index d6a18c83224cf1d142c1b50b3135b6c056e9fdc4..1534b377bd63c80b9763d29c167a6162bafd0403 100755 |
--- a/build/env_dump.py |
+++ b/build/env_dump.py |
@@ -20,7 +20,7 @@ def main(): |
help='File to dump the environment as JSON into.') |
parser.add_option( |
'-d', '--dump-mode', action='store_true', |
- help='Dump the environment to the file and exit immediately.') |
+ help='Dump the environment to sys.stdout and exit immediately.') |
iannucci
2013/09/18 00:55:37
just 'stdout' in help string :)
|
options, args = parser.parse_args() |
if not options.output_json: |
@@ -29,8 +29,7 @@ def main(): |
if options.dump_mode: |
iannucci
2013/09/18 00:55:37
we should make it an error to pass options.output_
|
if args: |
parser.error("Cannot specify args with --dump-mode") |
- with open(options.output_json, 'w') as f: |
- json.dump(dict(os.environ), f) |
+ json.dump(dict(os.environ), sys.stdout) |
else: |
envsetup_cmd = ' '.join(map(pipes.quote, args)) |
full_cmd = [ |
@@ -38,9 +37,19 @@ def main(): |
'. %s; %s -d -f %s' % (envsetup_cmd, os.path.abspath(__file__), |
iannucci
2013/09/18 00:55:37
I don't think we need to pass -f any more, since i
|
options.output_json) |
] |
- ret = subprocess.call(full_cmd) |
- if ret: |
- sys.exit('Error running %s and dumping env' % envsetup_cmd) |
+ try: |
+ output = subprocess.check_output(full_cmd) |
+ except Exception as e: |
+ sys.exit('Error running % and dumping environment.' % envsetup_cmd) |
iannucci
2013/09/18 00:55:37
missing %s
|
+ |
+ env_diff = {} |
+ new_env = json.loads(output) |
+ for k, val in new_env.items(): |
+ if k == '_' or (k in os.environ and os.environ[k] == val): |
+ continue |
+ env_diff[k] = val |
+ with open(options.output_json, 'w') as f: |
+ json.dump(env_diff, f) |
if __name__ == '__main__': |