| OLD | NEW |
| 1 # Copyright 2012 The Swarming Authors. All rights reserved. | 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 | 2 # Use of this source code is governed under the Apache License, Version 2.0 that |
| 3 # can be found in the LICENSE file. | 3 # can be found in the LICENSE file. |
| 4 | 4 |
| 5 import datetime | 5 import datetime |
| 6 import getpass | 6 import getpass |
| 7 import hashlib |
| 7 import optparse | 8 import optparse |
| 8 import os | 9 import os |
| 9 import subprocess | 10 import subprocess |
| 10 import sys | 11 import sys |
| 11 | 12 |
| 12 | 13 |
| 13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 14 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 14 sys.path.append(os.path.join(ROOT_DIR, '..', 'third_party')) | 15 sys.path.append(os.path.join(ROOT_DIR, '..', 'third_party')) |
| 15 | 16 |
| 16 import colorama | 17 import colorama |
| 17 | 18 |
| 18 | 19 |
| 19 CHROMIUM_SWARMING_OSES = { | 20 CHROMIUM_SWARMING_OSES = { |
| 20 'darwin': 'Mac', | 21 'darwin': 'Mac', |
| 21 'cygwin': 'Windows', | 22 'cygwin': 'Windows', |
| 22 'linux2': 'Linux', | 23 'linux2': 'Ubuntu', |
| 23 'win32': 'Windows', | 24 'win32': 'Windows', |
| 24 } | 25 } |
| 25 | 26 |
| 26 | 27 |
| 27 def parse_args(use_isolate_server, use_swarming): | 28 def parse_args(use_isolate_server, use_swarming): |
| 28 """Process arguments for the example scripts.""" | 29 """Process arguments for the example scripts.""" |
| 29 os.chdir(ROOT_DIR) | 30 os.chdir(ROOT_DIR) |
| 30 colorama.init() | 31 colorama.init() |
| 31 | 32 |
| 32 parser = optparse.OptionParser(description=sys.modules['__main__'].__doc__) | 33 parser = optparse.OptionParser(description=sys.modules['__main__'].__doc__) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 subprocess.check_call(cmd) | 93 subprocess.check_call(cmd) |
| 93 | 94 |
| 94 | 95 |
| 95 def capture(cmd): | 96 def capture(cmd): |
| 96 """Prints the command it runs then return stdout.""" | 97 """Prints the command it runs then return stdout.""" |
| 97 print( | 98 print( |
| 98 'Running: %s%s%s' % | 99 'Running: %s%s%s' % |
| 99 (colorama.Fore.GREEN, ' '.join(cmd), colorama.Fore.RESET)) | 100 (colorama.Fore.GREEN, ' '.join(cmd), colorama.Fore.RESET)) |
| 100 cmd = [sys.executable, os.path.join('..', cmd[0])] + cmd[1:] | 101 cmd = [sys.executable, os.path.join('..', cmd[0])] + cmd[1:] |
| 101 return subprocess.check_output(cmd) | 102 return subprocess.check_output(cmd) |
| 103 |
| 104 |
| 105 def isolate(tempdir, isolate_server, swarming_os, verbose): |
| 106 """Archives the payload.""" |
| 107 # All the files are put in a temporary directory. This is optional and |
| 108 # simply done so the current directory doesn't have the following files |
| 109 # created: |
| 110 # - hello_world.isolated |
| 111 # - hello_world.isolated.state |
| 112 isolated = os.path.join(tempdir, 'hello_world.isolated') |
| 113 note('Archiving to %s' % isolate_server) |
| 114 run( |
| 115 [ |
| 116 'isolate.py', |
| 117 'archive', |
| 118 '--isolate', os.path.join('payload', 'hello_world.isolate'), |
| 119 '--isolated', isolated, |
| 120 '--isolate-server', isolate_server, |
| 121 '--config-variable', 'OS', swarming_os, |
| 122 ], verbose) |
| 123 with open(isolated, 'rb') as f: |
| 124 hashval = hashlib.sha1(f.read()).hexdigest() |
| 125 return isolated, hashval |
| OLD | NEW |