2 # Copyright 2012 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 that
4 # can be found in the LICENSE file.
6 """Runs hello_world.py, through hello_world.isolate, remotely on a Swarming
9 It compiles and archives via 'isolate.py archive', then discard the local files.
10 After, it triggers and finally collects the results.
20 # Pylint can't find common.py that's in the same directory as this file.
21 # pylint: disable=F0401
26 options = common.parse_args(use_isolate_server=True, use_swarming=True)
28 tempdir = tempfile.mkdtemp(prefix='hello_world')
30 # All the files are put in a temporary directory. This is optional and
31 # simply done so the current directory doesn't have the following files
33 # - hello_world.isolated
34 # - hello_world.isolated.state
35 isolated = os.path.join(tempdir, 'hello_world.isolated')
36 common.note('Archiving to %s' % options.isolate_server)
41 '--isolate', os.path.join('payload', 'hello_world.isolate'),
42 '--isolated', isolated,
43 '--isolate-server', options.isolate_server,
44 '--config-variable', 'OS', options.swarming_os,
46 with open(isolated, 'rb') as f:
47 hashval = hashlib.sha1(f.read()).hexdigest()
49 shutil.rmtree(tempdir)
51 # At this point, the temporary directory is not needed anymore.
54 common.note('Running on %s' % options.swarming)
58 '--swarming', options.swarming,
59 '--isolate-server', options.isolate_server,
60 '--dimension', 'os', options.swarming_os,
61 '--task-name', options.task_name,
64 if options.priority is not None:
65 cmd.extend(('--priority', str(options.priority)))
66 common.run(cmd, options.verbose)
68 common.note('Getting results from %s' % options.swarming)
73 '--swarming', options.swarming,
77 except subprocess.CalledProcessError as e:
78 print e.returncode or 1
81 if __name__ == '__main__':