| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Runs hello_world.py, through hello_world.isolated, locally in a temporary | |
| 7 directory with the files fetched from the remote Content-Addressed Datastore. | |
| 8 """ | |
| 9 | |
| 10 import hashlib | |
| 11 import optparse | |
| 12 import os | |
| 13 import shutil | |
| 14 import subprocess | |
| 15 import sys | |
| 16 import tempfile | |
| 17 | |
| 18 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 19 | |
| 20 | |
| 21 def run(cmd): | |
| 22 print('Running: %s' % ' '.join(cmd)) | |
| 23 cmd = [sys.executable, os.path.join(ROOT_DIR, '..', cmd[0])] + cmd[1:] | |
| 24 if sys.platform != 'win32': | |
| 25 cmd = ['time', '-p'] + cmd | |
| 26 subprocess.check_call(cmd) | |
| 27 | |
| 28 | |
| 29 def main(): | |
| 30 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | |
| 31 parser.add_option( | |
| 32 '-I', '--isolate-server', | |
| 33 metavar='URL', default='', | |
| 34 help='Isolate server to use') | |
| 35 parser.add_option('-v', '--verbose', action='count', default=0) | |
| 36 options, args = parser.parse_args() | |
| 37 if args: | |
| 38 parser.error('Unsupported argument %s' % args) | |
| 39 if not options.isolate_server: | |
| 40 parser.error('--isolate-server is required.') | |
| 41 os.environ['ISOLATE_DEBUG'] = str(options.verbose) | |
| 42 | |
| 43 try: | |
| 44 # All the files are put in a temporary directory. This is optional and | |
| 45 # simply done so the current directory doesn't have the following files | |
| 46 # created: | |
| 47 # - hello_world.isolated | |
| 48 # - hello_world.isolated.state | |
| 49 # - cache/ | |
| 50 tempdir = tempfile.mkdtemp(prefix='hello_world') | |
| 51 cachedir = os.path.join(tempdir, 'cache') | |
| 52 isolateddir = os.path.join(tempdir, 'isolated') | |
| 53 isolated = os.path.join(isolateddir, 'hello_world.isolated') | |
| 54 | |
| 55 os.mkdir(isolateddir) | |
| 56 | |
| 57 print('Archiving') | |
| 58 run( | |
| 59 [ | |
| 60 'isolate.py', | |
| 61 'archive', | |
| 62 '--isolate', os.path.join(ROOT_DIR, 'hello_world.isolate'), | |
| 63 '--isolated', isolated, | |
| 64 '--outdir', options.isolate_server, | |
| 65 ]) | |
| 66 | |
| 67 print('\nRunning') | |
| 68 hashval = hashlib.sha1(open(isolated, 'rb').read()).hexdigest() | |
| 69 run( | |
| 70 [ | |
| 71 'run_isolated.py', | |
| 72 '--cache', cachedir, | |
| 73 '--isolate-server', options.isolate_server, | |
| 74 '--hash', hashval, | |
| 75 '--no-log', | |
| 76 ]) | |
| 77 return 0 | |
| 78 except subprocess.CalledProcessError as e: | |
| 79 return e.returncode | |
| 80 finally: | |
| 81 shutil.rmtree(tempdir) | |
| 82 | |
| 83 | |
| 84 if __name__ == '__main__': | |
| 85 sys.exit(main()) | |
| OLD | NEW |