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

Side by Side Diff: third_party/libadblockplus/subproc.py

Issue 29670584: Issue 6277 - Subproc.py should wait for subprocess to finish (Closed)
Patch Set: Created Jan. 16, 2018, 12:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/libadblockplus_android/subproc.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os 1 import os
2 import io
3 import sys 2 import sys
4 import subprocess 3 import subprocess
5 4
5
6 def main(argv): 6 def main(argv):
7 cwd = os.getcwd() 7 cwd = os.getcwd()
8 subprocess_env = os.environ.copy() 8 subprocess_env = os.environ.copy()
9 subprocess_args = [] 9 subprocess_args = []
10 for arg in argv: 10 for arg in argv:
11 # if it's env var 11 # if it's env var
12 if arg[: 5] == '--env': 12 if arg[: 5] == '--env':
13 equal_pos = arg.index('=') 13 equal_pos = arg.index('=')
14 key = arg[5 : equal_pos] 14 key = arg[5:equal_pos]
15 value = arg[equal_pos + 1 : len(arg)] 15 value = arg[equal_pos + 1:len(arg)]
16 print('Set env variable %s=%s' % (key, value)) 16 print('Set env variable {}={}'.format(key, value))
17 subprocess_env[key] = value 17 subprocess_env[key] = value
18 else: 18 else:
19 # if it's cwd 19 # if it's cwd
20 if arg[: 5] == '--cwd': 20 if arg[: 5] == '--cwd':
21 cwd = arg[5:] 21 cwd = arg[5:]
22 print('Set cwd=%s' % cwd) 22 print('Set cwd={}'.format(cwd))
23 else: 23 else:
24 # cmd arguments 24 # cmd arguments
25 subprocess_args += [ arg ] 25 subprocess_args += [arg]
26 26
27 #print("Running: %s" % " ".join(subprocess_args)) 27 process = subprocess.Popen(subprocess_args, env=subprocess_env,
28 process = subprocess.Popen(subprocess_args, env=subprocess_env, cwd=cwd, stdou t=sys.stdout, stderr=sys.stderr) 28 cwd=cwd, stdout=sys.stdout, stderr=sys.stderr)
29 return process.returncode 29 process.communicate()
30 return process.returncode
31
30 32
31 if '__main__' == __name__: 33 if '__main__' == __name__:
32 try: 34 try:
33 sys.exit(main(sys.argv[1:])) 35 sys.exit(main(sys.argv[1:]))
34 except KeyboardInterrupt: 36 except KeyboardInterrupt:
35 sys.stderr.write('interrupted\n') 37 sys.stderr.write('interrupted\n')
36 sys.exit(1) 38 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | third_party/libadblockplus_android/subproc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld