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

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

Issue 29674558: Issue 6286 - Remove common scripts duplicating (Closed)
Patch Set: Created Jan. 19, 2018, 8:03 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 import os
2 import sys
3 import subprocess
4
5
6 def main(argv):
7 cwd = os.getcwd()
8 subprocess_env = os.environ.copy()
9 subprocess_args = []
10 for arg in argv:
11 # if it's env var
12 if arg[: 5] == '--env':
13 equal_pos = arg.index('=')
14 key = arg[5:equal_pos]
15 value = arg[equal_pos + 1:len(arg)]
16 print('Set env variable {}={}'.format(key, value))
17 subprocess_env[key] = value
18 else:
19 # if it's cwd
20 if arg[: 5] == '--cwd':
21 cwd = arg[5:]
22 print('Set cwd={}'.format(cwd))
23 else:
24 # cmd arguments
25 subprocess_args += [arg]
26
27 process = subprocess.Popen(subprocess_args, env=subprocess_env,
28 cwd=cwd, stdout=sys.stdout, stderr=sys.stderr)
29 process.communicate()
30 return process.returncode
31
32
33 if '__main__' == __name__:
34 try:
35 sys.exit(main(sys.argv[1:]))
36 except KeyboardInterrupt:
37 sys.stderr.write('interrupted\n')
38 sys.exit(1)
OLDNEW

Powered by Google App Engine
This is Rietveld