Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: third_party/libadblockplus_common/subproc.py

Issue 29674555: Issue 6273 - Apply eyeo python code style (Closed)
Left Patch Set: Created Jan. 19, 2018, 7:28 a.m.
Right Patch Set: Removed sys.exit() where return code is always 0 Created Jan. 29, 2018, 12:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « third_party/libadblockplus_common/delete_dir.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 from __future__ import print_function
2
1 import os 3 import os
2 import sys 4 import sys
3 import subprocess 5 import subprocess
4 6
5 7
6 def main(argv): 8 def main(argv):
7 cwd = os.getcwd() 9 cwd = os.getcwd()
8 subprocess_env = os.environ.copy() 10 subprocess_env = os.environ.copy()
9 subprocess_args = [] 11 subprocess_args = []
10 for arg in argv: 12 for arg in argv:
11 # if it's env var 13 # if it's env var
12 if arg[: 5] == '--env': 14 if arg[:5] == '--env':
13 equal_pos = arg.index('=') 15 equal_pos = arg.index('=')
14 key = arg[5:equal_pos] 16 key = arg[5:equal_pos]
15 value = arg[equal_pos + 1:len(arg)] 17 value = arg[equal_pos + 1:len(arg)]
16 print('Set env variable {}={}'.format(key, value)) 18 print('Set env variable {}={}'.format(key, value))
17 subprocess_env[key] = value 19 subprocess_env[key] = value
18 else: 20 else:
19 # if it's cwd 21 # if it's cwd
20 if arg[: 5] == '--cwd': 22 if arg[:5] == '--cwd':
21 cwd = arg[5:] 23 cwd = arg[5:]
22 print('Set cwd={}'.format(cwd)) 24 print('Set cwd={}'.format(cwd))
23 else: 25 else:
24 # cmd arguments 26 # cmd arguments
25 subprocess_args += [arg] 27 subprocess_args += [arg]
26 28
27 process = subprocess.Popen(subprocess_args, env=subprocess_env, 29 process = subprocess.Popen(subprocess_args, env=subprocess_env,
28 cwd=cwd, stdout=sys.stdout, stderr=sys.stderr) 30 cwd=cwd, stdout=sys.stdout, stderr=sys.stderr)
29 process.communicate() 31 process.communicate()
30 return process.returncode 32 return process.returncode
31 33
32 34
33 if '__main__' == __name__: 35 if __name__ == '__main__':
34 try: 36 try:
35 sys.exit(main(sys.argv[1:])) 37 sys.exit(main(sys.argv[1:]))
36 except KeyboardInterrupt: 38 except KeyboardInterrupt:
37 sys.stderr.write('interrupted\n') 39 sys.exit('interrupted')
38 sys.exit(1)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld