OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import json |
| 6 import os |
| 7 import pipes |
| 8 import subprocess |
| 9 import sys |
| 10 |
| 11 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 12 from pylib import buildbot_report |
| 13 from pylib import constants |
| 14 |
| 15 |
| 16 TESTING = 'BUILDBOT_TESTING' in os.environ |
| 17 |
| 18 |
| 19 def SpawnCmd(command): |
| 20 """Spawn a process without waiting for termination.""" |
| 21 print '>', ' '.join(map(pipes.quote, command)) |
| 22 sys.stdout.flush() |
| 23 if TESTING: |
| 24 class MockPopen(object): |
| 25 @staticmethod |
| 26 def wait(): |
| 27 return 0 |
| 28 return MockPopen() |
| 29 |
| 30 return subprocess.Popen(command, cwd=constants.CHROME_DIR) |
| 31 |
| 32 |
| 33 def RunCmd(command, flunk_on_failure=True, halt_on_failure=False, |
| 34 retcode_callback=None): |
| 35 """Run a command relative to the chrome source root.""" |
| 36 code = SpawnCmd(command).wait() |
| 37 print '<', ' '.join(map(pipes.quote, command)) |
| 38 if retcode_callback: |
| 39 retcode_callback(code) |
| 40 return code |
| 41 if code != 0: |
| 42 print 'ERROR: process exited with code %d' % code |
| 43 if flunk_on_failure: |
| 44 buildbot_report.PrintError() |
| 45 else: |
| 46 buildbot_report.PrintWarning() |
| 47 # Allow steps to have both halting (i.e. 1) and non-halting exit codes. |
| 48 if code != 0 and code != 88 and halt_on_failure: |
| 49 raise OSError() |
| 50 return code |
| 51 |
| 52 |
| 53 def OptParserError(parser, msg): |
| 54 """We avoid parser.error because it calls sys.exit.""" |
| 55 parser.print_help() |
| 56 print >> sys.stderr, '\nERROR:', msg |
| 57 return 1 |
| 58 |
| 59 |
| 60 def ConvertJson(option, _, value, parser): |
| 61 setattr(parser.values, option.dest, json.loads(value)) |
OLD | NEW |