Пример #1
0
def main(argv):
  dispatcher = subcommand.CommandDispatcher(__name__)
  parser = tools.OptionParserWithLogging(
        version=__version__, verbose=int(os.environ.get('ISOLATE_DEBUG', 0)))
  try:
    return dispatcher.execute(parser, argv)
  except isolated_format.MappingError as e:
    print >> sys.stderr, 'Failed to find an input file: %s' % e
    return 1
  except ExecutionError as e:
    print >> sys.stderr, 'Execution failure: %s' % e
    return 1
Пример #2
0
def main(args=None):
    tools.disable_buffering()
    parser = tools.OptionParserWithLogging(
        usage='%prog <options> [file1] [file2] ...')
    parser.add_option('-o',
                      '--output',
                      help='Output to file instead of stdout')

    options, args = parser.parse_args(args)

    configs = load_isolates(args)
    data = configs.make_isolate_file()
    if options.output:
        with open(options.output, 'wb') as f:
            isolate_format.print_all(configs.file_comment, data, f)
    else:
        isolate_format.print_all(configs.file_comment, data, sys.stdout)
    return 0
Пример #3
0
def main(args):
  tools.disable_buffering()
  parser = tools.OptionParserWithLogging(
      usage='%prog <options>',
      version=__version__,
      log_file=RUN_ISOLATED_LOG_FILE)

  data_group = optparse.OptionGroup(parser, 'Data source')
  data_group.add_option(
      '-s', '--isolated',
      help='Hash of the .isolated to grab from the isolate server')
  data_group.add_option(
      '-H', dest='isolated', help=optparse.SUPPRESS_HELP)
  isolateserver.add_isolate_server_options(data_group)
  parser.add_option_group(data_group)

  isolateserver.add_cache_options(parser)
  parser.set_defaults(cache='cache')

  debug_group = optparse.OptionGroup(parser, 'Debugging')
  debug_group.add_option(
      '--leak-temp-dir',
      action='store_true',
      help='Deliberately leak isolate\'s temp dir for later examination '
          '[default: %default]')
  parser.add_option_group(debug_group)

  auth.add_auth_options(parser)
  options, args = parser.parse_args(args)
  if not options.isolated:
    parser.error('--isolated is required.')
  auth.process_auth_options(parser, options)
  isolateserver.process_isolate_server_options(parser, options, True)

  cache = isolateserver.process_cache_options(options)
  with isolateserver.get_storage(
      options.isolate_server, options.namespace) as storage:
    # Hashing schemes used by |storage| and |cache| MUST match.
    assert storage.hash_algo == cache.hash_algo
    return run_tha_test(
        options.isolated, storage, cache, options.leak_temp_dir, args)
Пример #4
0
def main(args):
  tools.disable_buffering()
  parser = tools.OptionParserWithLogging(
      usage='%prog <options>',
      version=__version__,
      log_file=RUN_ISOLATED_LOG_FILE)

  data_group = optparse.OptionGroup(parser, 'Data source')
  data_group.add_option(
      '-s', '--isolated',
      metavar='FILE',
      help='File/url describing what to map or run')
  data_group.add_option(
      '-H', '--hash',
      help='Hash of the .isolated to grab from the hash table')
  isolateserver.add_isolate_server_options(data_group, True)
  parser.add_option_group(data_group)

  cache_group = optparse.OptionGroup(parser, 'Cache management')
  cache_group.add_option(
      '--cache',
      default='cache',
      metavar='DIR',
      help='Cache directory, default=%default')
  cache_group.add_option(
      '--max-cache-size',
      type='int',
      metavar='NNN',
      default=20*1024*1024*1024,
      help='Trim if the cache gets larger than this value, default=%default')
  cache_group.add_option(
      '--min-free-space',
      type='int',
      metavar='NNN',
      default=2*1024*1024*1024,
      help='Trim if disk free space becomes lower than this value, '
           'default=%default')
  cache_group.add_option(
      '--max-items',
      type='int',
      metavar='NNN',
      default=100000,
      help='Trim if more than this number of items are in the cache '
           'default=%default')
  parser.add_option_group(cache_group)

  auth.add_auth_options(parser)
  options, args = parser.parse_args(args)
  auth.process_auth_options(parser, options)
  isolateserver.process_isolate_server_options(data_group, options)

  if bool(options.isolated) == bool(options.hash):
    logging.debug('One and only one of --isolated or --hash is required.')
    parser.error('One and only one of --isolated or --hash is required.')

  options.cache = os.path.abspath(options.cache)
  policies = CachePolicies(
      options.max_cache_size, options.min_free_space, options.max_items)

  try:
    # |options.cache| path may not exist until DiskCache() instance is created.
    cache = DiskCache(
        options.cache, policies, isolateserver.get_hash_algo(options.namespace))
    remote = options.isolate_server or options.indir
    with isolateserver.get_storage(remote, options.namespace) as storage:
      # Hashing schemes used by |storage| and |cache| MUST match.
      assert storage.hash_algo == cache.hash_algo
      return run_tha_test(
          options.isolated or options.hash, storage, cache, args)
  except Exception as e:
    # Make sure any exception is logged.
    tools.report_error(e)
    logging.exception(e)
    return 1
Пример #5
0
def main():
    tools.disable_buffering()
    parser = tools.OptionParserWithLogging(usage='%prog <options>',
                                           version=__version__,
                                           log_file=RUN_ISOLATED_LOG_FILE)

    group = optparse.OptionGroup(parser, 'Data source')
    group.add_option('-s',
                     '--isolated',
                     metavar='FILE',
                     help='File/url describing what to map or run')
    group.add_option('-H',
                     '--hash',
                     help='Hash of the .isolated to grab from the hash table')
    group.add_option('-I',
                     '--isolate-server',
                     metavar='URL',
                     default='',
                     help='Isolate server to use')
    group.add_option(
        '-n',
        '--namespace',
        default='default-gzip',
        help='namespace to use when using isolateserver, default: %default')
    parser.add_option_group(group)

    group = optparse.OptionGroup(parser, 'Cache management')
    group.add_option('--cache',
                     default='cache',
                     metavar='DIR',
                     help='Cache directory, default=%default')
    group.add_option(
        '--max-cache-size',
        type='int',
        metavar='NNN',
        default=20 * 1024 * 1024 * 1024,
        help='Trim if the cache gets larger than this value, default=%default')
    group.add_option(
        '--min-free-space',
        type='int',
        metavar='NNN',
        default=2 * 1024 * 1024 * 1024,
        help='Trim if disk free space becomes lower than this value, '
        'default=%default')
    group.add_option(
        '--max-items',
        type='int',
        metavar='NNN',
        default=100000,
        help='Trim if more than this number of items are in the cache '
        'default=%default')
    parser.add_option_group(group)

    options, args = parser.parse_args()

    if bool(options.isolated) == bool(options.hash):
        logging.debug('One and only one of --isolated or --hash is required.')
        parser.error('One and only one of --isolated or --hash is required.')
    if args:
        logging.debug('Unsupported args %s' % ' '.join(args))
        parser.error('Unsupported args %s' % ' '.join(args))
    if not options.isolate_server:
        parser.error('--isolate-server is required.')

    options.cache = os.path.abspath(options.cache)
    policies = CachePolicies(options.max_cache_size, options.min_free_space,
                             options.max_items)
    storage = isolateserver.get_storage(options.isolate_server,
                                        options.namespace)
    algo = isolateserver.get_hash_algo(options.namespace)

    try:
        # |options.cache| may not exist until DiskCache() instance is created.
        cache = DiskCache(options.cache, policies, algo)
        outdir = make_temp_dir('run_tha_test', options.cache)
        return run_tha_test(options.isolated or options.hash, storage, cache,
                            algo, outdir)
    except Exception as e:
        # Make sure any exception is logged.
        logging.exception(e)
        return 1