1 # Copyright 2012 The Swarming Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 that
3 # can be found in the LICENSE file.
13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
14 sys.path.append(os.path.join(ROOT_DIR, '..', 'third_party'))
19 CHROMIUM_SWARMING_OSES = {
35 def parse_args(use_isolate_server, use_swarming):
36 """Process arguments for the example scripts."""
40 parser = optparse.OptionParser(description=sys.modules['__main__'].__doc__)
41 if use_isolate_server:
43 '-I', '--isolate-server',
44 metavar='URL', default=os.environ.get('ISOLATE_SERVER', ''),
45 help='Isolate server to use')
49 metavar='URL', default=os.environ.get('SWARMING_SERVER', ''),
50 help='Swarming server to use')
52 '-o', '--os', default=sys.platform,
53 help='Swarming slave OS to request. Should be one of the valid '
54 'sys.platform values like darwin, linux2 or win32 default: '
56 parser.add_option('-v', '--verbose', action='count', default=0)
57 options, args = parser.parse_args()
60 parser.error('Unsupported argument %s' % args)
61 if use_isolate_server and not options.isolate_server:
62 parser.error('--isolate-server is required.')
64 if not options.swarming:
65 parser.error('--swarming is required.')
66 options.isolate_os = ISOLATE_OSES[options.os]
67 options.swarming_os = CHROMIUM_SWARMING_OSES[options.os]
73 def unique_task_name():
74 """Makes sure this gets run as an unique task run."""
75 return '%s-%s-hello_world' % (
77 datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
81 """Prints a formatted note."""
83 colorama.Fore.YELLOW + colorama.Style.BRIGHT + '\n-> ' + text +
87 def run(cmd, verbose):
88 """Prints the command it runs then run it."""
90 cmd.extend(['--verbose'] * verbose)
93 (colorama.Fore.GREEN, ' '.join(cmd), colorama.Fore.RESET))
94 cmd = [sys.executable, os.path.join('..', cmd[0])] + cmd[1:]
95 if sys.platform != 'win32':
96 cmd = ['time', '-p'] + cmd
97 subprocess.check_call(cmd)
101 """Prints the command it runs then return stdout."""
104 (colorama.Fore.GREEN, ' '.join(cmd), colorama.Fore.RESET))
105 cmd = [sys.executable, os.path.join('..', cmd[0])] + cmd[1:]
106 return subprocess.check_output(cmd)