| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Does one of the following depending on the --mode argument: | 6 """Does one of the following depending on the --mode argument: |
| 7 check Verifies all the inputs exist, touches the file specified with | 7 check Verifies all the inputs exist, touches the file specified with |
| 8 --result and exits. | 8 --result and exits. |
| 9 hashtable Puts a manifest file and hard links each of the inputs into the | 9 hashtable Puts a manifest file and hard links each of the inputs into the |
| 10 output directory. | 10 output directory. |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 False) | 411 False) |
| 412 | 412 |
| 413 | 413 |
| 414 def get_valid_modes(): | 414 def get_valid_modes(): |
| 415 """Returns the modes that can be used.""" | 415 """Returns the modes that can be used.""" |
| 416 return sorted( | 416 return sorted( |
| 417 i[4:] for i in dir(sys.modules[__name__]) if i.startswith('MODE')) | 417 i[4:] for i in dir(sys.modules[__name__]) if i.startswith('MODE')) |
| 418 | 418 |
| 419 | 419 |
| 420 def main(): | 420 def main(): |
| 421 default_variables = ['OS=%s' % trace_inputs.get_flavor()] | 421 default_variables = [('OS', trace_inputs.get_flavor())] |
| 422 if sys.platform in ('win32', 'cygwin'): | 422 if sys.platform in ('win32', 'cygwin'): |
| 423 default_variables.append('EXECUTABLE_SUFFIX=.exe') | 423 default_variables.append(('EXECUTABLE_SUFFIX', '.exe')) |
| 424 else: | 424 else: |
| 425 default_variables.append('EXECUTABLE_SUFFIX=') | 425 default_variables.append(('EXECUTABLE_SUFFIX', '')) |
| 426 valid_modes = get_valid_modes() | 426 valid_modes = get_valid_modes() |
| 427 parser = optparse.OptionParser( | 427 parser = optparse.OptionParser( |
| 428 usage='%prog [options] [.isolate file]', | 428 usage='%prog [options] [.isolate file]', |
| 429 description=sys.modules[__name__].__doc__) | 429 description=sys.modules[__name__].__doc__) |
| 430 parser.format_description = lambda *_: parser.description | 430 parser.format_description = lambda *_: parser.description |
| 431 parser.add_option( | 431 parser.add_option( |
| 432 '-v', '--verbose', | 432 '-v', '--verbose', |
| 433 action='count', | 433 action='count', |
| 434 default=int(os.environ.get('ISOLATE_DEBUG', 0)), | 434 default=int(os.environ.get('ISOLATE_DEBUG', 0)), |
| 435 help='Use multiple times') | 435 help='Use multiple times') |
| 436 parser.add_option( | 436 parser.add_option( |
| 437 '-m', '--mode', | 437 '-m', '--mode', |
| 438 choices=valid_modes, | 438 choices=valid_modes, |
| 439 help='Determines the action to be taken: %s' % ', '.join(valid_modes)) | 439 help='Determines the action to be taken: %s' % ', '.join(valid_modes)) |
| 440 parser.add_option( | 440 parser.add_option( |
| 441 '-r', '--result', | 441 '-r', '--result', |
| 442 metavar='FILE', | 442 metavar='FILE', |
| 443 help='Result file to store the json manifest') | 443 help='Result file to store the json manifest') |
| 444 parser.add_option( | 444 parser.add_option( |
| 445 '-V', '--variable', | 445 '-V', '--variable', |
| 446 nargs=2, |
| 446 action='append', | 447 action='append', |
| 447 default=default_variables, | 448 default=default_variables, |
| 448 dest='variables', | 449 dest='variables', |
| 449 metavar='FOO=BAR', | 450 metavar='FOO BAR', |
| 450 help='Variables to process in the .isolate file, default: %default') | 451 help='Variables to process in the .isolate file, default: %default') |
| 451 parser.add_option( | 452 parser.add_option( |
| 452 '-o', '--outdir', metavar='DIR', | 453 '-o', '--outdir', metavar='DIR', |
| 453 help='Directory used to recreate the tree or store the hash table. ' | 454 help='Directory used to recreate the tree or store the hash table. ' |
| 454 'If the environment variable ISOLATE_HASH_TABLE_DIR exists, it will ' | 455 'If the environment variable ISOLATE_HASH_TABLE_DIR exists, it will ' |
| 455 'be used. Otherwise, for run and remap, uses a /tmp subdirectory. ' | 456 'be used. Otherwise, for run and remap, uses a /tmp subdirectory. ' |
| 456 'For the other modes, defaults to the directory containing --result') | 457 'For the other modes, defaults to the directory containing --result') |
| 457 | 458 |
| 458 options, args = parser.parse_args() | 459 options, args = parser.parse_args() |
| 459 level = [logging.ERROR, logging.INFO, logging.DEBUG][min(2, options.verbose)] | 460 level = [logging.ERROR, logging.INFO, logging.DEBUG][min(2, options.verbose)] |
| 460 logging.basicConfig( | 461 logging.basicConfig( |
| 461 level=level, | 462 level=level, |
| 462 format='%(levelname)5s %(module)15s(%(lineno)3d): %(message)s') | 463 format='%(levelname)5s %(module)15s(%(lineno)3d): %(message)s') |
| 463 | 464 |
| 464 if not options.mode: | 465 if not options.mode: |
| 465 parser.error('--mode is required') | 466 parser.error('--mode is required') |
| 466 if len(args) != 1: | 467 if len(args) != 1: |
| 467 parser.error('Use only one argument which should be a .isolate file') | 468 parser.error('Use only one argument which should be a .isolate file') |
| 468 | 469 |
| 469 input_file = os.path.abspath(args[0]) | 470 input_file = os.path.abspath(args[0]) |
| 470 isolate_dir = os.path.dirname(input_file) | 471 isolate_dir = os.path.dirname(input_file) |
| 471 | 472 |
| 472 # Extract the variables. | 473 # Extract the variables. |
| 473 variables = dict(i.split('=', 1) for i in options.variables) | 474 variables = dict(options.variables) |
| 474 # Process path variables as a special case. First normalize it, verifies it | 475 # Process path variables as a special case. First normalize it, verifies it |
| 475 # exists, convert it to an absolute path, then set it as relative to | 476 # exists, convert it to an absolute path, then set it as relative to |
| 476 # isolate_dir. | 477 # isolate_dir. |
| 477 for i in ('PRODUCT_DIR',): | 478 for i in ('PRODUCT_DIR',): |
| 478 if i not in variables: | 479 if i not in variables: |
| 479 continue | 480 continue |
| 480 variable = os.path.normpath(variables[i]) | 481 variable = os.path.normpath(variables[i]) |
| 481 if not os.path.isdir(variable): | 482 if not os.path.isdir(variable): |
| 482 parser.error('%s=%s is not a directory' % (i, variable)) | 483 parser.error('%s=%s is not a directory' % (i, variable)) |
| 483 variable = os.path.abspath(variable) | 484 variable = os.path.abspath(variable) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 command, | 525 command, |
| 525 relative_dir, | 526 relative_dir, |
| 526 options.result) | 527 options.result) |
| 527 except run_test_from_archive.MappingError, e: | 528 except run_test_from_archive.MappingError, e: |
| 528 print >> sys.stderr, str(e) | 529 print >> sys.stderr, str(e) |
| 529 return 1 | 530 return 1 |
| 530 | 531 |
| 531 | 532 |
| 532 if __name__ == '__main__': | 533 if __name__ == '__main__': |
| 533 sys.exit(main()) | 534 sys.exit(main()) |
| OLD | NEW |