| OLD | NEW |
| (Empty) | |
| 1 import json |
| 2 import os |
| 3 import subprocess |
| 4 import sys |
| 5 |
| 6 def execute(cmd): |
| 7 """Runs a subprocess redirecting its stdout and stderr to the log. |
| 8 |
| 9 Args: |
| 10 cmd: list with command line arguments. |
| 11 |
| 12 Returns: |
| 13 Process exit code. |
| 14 """ |
| 15 print('Running ' + ' '.join(cmd)) |
| 16 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 17 line = '' |
| 18 while True: |
| 19 buf = proc.stdout.read(1) |
| 20 if not buf: |
| 21 if line: |
| 22 print(line.strip()) |
| 23 break |
| 24 if buf == '\n': |
| 25 print(line.strip()) |
| 26 line = '' |
| 27 else: |
| 28 line += buf |
| 29 code = proc.wait() |
| 30 if code: |
| 31 print('Failed with exit code: %d', code) |
| 32 return code |
| 33 |
| 34 |
| 35 def main(): |
| 36 data = json.load(sys.stdin) |
| 37 pkg_list = data['list'] |
| 38 root = data['root'] |
| 39 |
| 40 exit_code = 0 |
| 41 # return if this client version is already installed. |
| 42 |
| 43 exit_code = execute(["./cipd", "ensure", "--root=%s" % root, "--list=%s" % pkg
_list]) |
| 44 return exit_code |
| 45 |
| 46 if __name__ == '__main__': |
| 47 sys.exit(main()) |
| OLD | NEW |