当前位置: 首页>>代码示例>>Python>>正文


Python on_error.report函数代码示例

本文整理汇总了Python中utils.on_error.report函数的典型用法代码示例。如果您正苦于以下问题:Python report函数的具体用法?Python report怎么用?Python report使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了report函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: swarming_trigger

def swarming_trigger(swarming, raw_request, xsrf_token):
  """Triggers a request on the Swarming server and returns the json data.

  It's the low-level function.

  Returns:
    {
      'request': {
        'created_ts': u'2010-01-02 03:04:05',
        'name': ..
      },
      'task_id': '12300',
    }
  """
  logging.info('Triggering: %s', raw_request['name'])

  headers = {'X-XSRF-Token': xsrf_token}
  result = net.url_read_json(
      swarming + '/swarming/api/v1/client/request',
      data=raw_request,
      headers=headers)
  if not result:
    on_error.report('Failed to trigger task %s' % raw_request['name'])
    return None
  return result
开发者ID:misscache,项目名称:luci-py,代码行数:25,代码来源:swarming.py

示例2: trigger_by_manifest

def trigger_by_manifest(swarming, manifest):
  """Given a task manifest, triggers it for execution on swarming.

  Args:
    swarming: URL of a swarming service.
    manifest: instance of Manifest.

  Returns:
    tuple(Task id, priority) on success. tuple(None, None) on failure.
  """
  logging.info('Triggering: %s', manifest.task_name)
  manifest_text = manifest.to_json()
  result = net.url_read(swarming + '/test', data={'request': manifest_text})
  if not result:
    on_error.report('Failed to trigger task %s' % manifest.task_name)
    return None, None
  try:
    data = json.loads(result)
  except (ValueError, TypeError):
    msg = '\n'.join((
        'Failed to trigger task %s' % manifest.task_name,
        'Manifest: %s' % manifest_text,
        'Bad response: %s' % result))
    on_error.report(msg)
    return None, None
  if not data:
    return None, None
  return data['test_keys'][0]['test_key'], data['priority']
开发者ID:bpsinc-native,项目名称:src_tools_swarming_client,代码行数:28,代码来源:swarming.py

示例3: CMDcollect

def CMDcollect(parser, args):
  """Retrieves results of a Swarming task.

  The result can be in multiple part if the execution was sharded. It can
  potentially have retries.
  """
  add_collect_options(parser)
  add_sharding_options(parser)
  (options, args) = parser.parse_args(args)
  if not args:
    parser.error('Must specify one task name.')
  elif len(args) > 1:
    parser.error('Must specify only one task name.')

  auth.ensure_logged_in(options.swarming)
  try:
    return collect(
        options.swarming,
        args[0],
        options.shards,
        options.timeout,
        options.decorate,
        options.print_status_updates,
        options.task_summary_json,
        options.task_output_dir)
  except Failure:
    on_error.report(None)
    return 1
开发者ID:bpsinc-native,项目名称:src_tools_swarming_client,代码行数:28,代码来源:swarming.py

示例4: CMDtrigger

def CMDtrigger(parser, args):
  """Triggers a Swarming task.

  Accepts either the hash (sha1) of a .isolated file already uploaded or the
  path to an .isolated file to archive, packages it if needed and sends a
  Swarming manifest file to the Swarming server.

  If an .isolated file is specified instead of an hash, it is first archived.

  Passes all extra arguments provided after '--' as additional command line
  arguments for an isolated command specified in *.isolate file.
  """
  add_trigger_options(parser)
  add_sharding_options(parser)
  args, isolated_cmd_args = extract_isolated_command_extra_args(args)
  parser.add_option(
      '--dump-json',
      metavar='FILE',
      help='Dump details about the triggered task(s) to this file as json')
  options, args = parser.parse_args(args)
  process_trigger_options(parser, options, args)

  auth.ensure_logged_in(options.swarming)
  if file_path.is_url(options.isolate_server):
    auth.ensure_logged_in(options.isolate_server)
  try:
    tasks, task_name = trigger(
        swarming=options.swarming,
        isolate_server=options.isolate_server or options.indir,
        namespace=options.namespace,
        file_hash_or_isolated=args[0],
        task_name=options.task_name,
        extra_args=isolated_cmd_args,
        shards=options.shards,
        dimensions=options.dimensions,
        env=dict(options.env),
        deadline=options.deadline,
        verbose=options.verbose,
        profile=options.profile,
        priority=options.priority)
    if tasks:
      if task_name != options.task_name:
        print('Triggered task: %s' % task_name)
      if options.dump_json:
        data = {
          'base_task_name': task_name,
          'tasks': tasks,
        }
        tools.write_json(options.dump_json, data, True)
    return int(not tasks)
  except Failure:
    on_error.report(None)
    return 1
开发者ID:bpsinc-native,项目名称:src_tools_swarming_client,代码行数:53,代码来源:swarming.py

示例5: CMDcollect

def CMDcollect(parser, args):
  """Retrieves results of one or multiple Swarming task by its ID.

  The result can be in multiple part if the execution was sharded. It can
  potentially have retries.
  """
  add_collect_options(parser)
  parser.add_option(
      '-j', '--json',
      help='Load the task ids from .json as saved by trigger --dump-json')
  options, args = parser.parse_args(args)
  if not args and not options.json:
    parser.error('Must specify at least one task id or --json.')
  if args and options.json:
    parser.error('Only use one of task id or --json.')

  if options.json:
    options.json = unicode(os.path.abspath(options.json))
    try:
      with fs.open(options.json, 'rb') as f:
        data = json.load(f)
    except (IOError, ValueError):
      parser.error('Failed to open %s' % options.json)
    try:
      tasks = sorted(
          data['tasks'].itervalues(), key=lambda x: x['shard_index'])
      args = [t['task_id'] for t in tasks]
    except (KeyError, TypeError):
      parser.error('Failed to process %s' % options.json)
    if options.timeout is None:
      options.timeout = (
          data['request']['properties']['execution_timeout_secs'] +
          data['request']['expiration_secs'] + 10.)
  else:
    valid = frozenset('0123456789abcdef')
    if any(not valid.issuperset(task_id) for task_id in args):
      parser.error('Task ids are 0-9a-f.')

  try:
    return collect(
        options.swarming,
        args,
        options.timeout,
        options.decorate,
        options.print_status_updates,
        options.task_summary_json,
        options.task_output_dir,
        options.perf)
  except Failure:
    on_error.report(None)
    return 1
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:51,代码来源:swarming.py

示例6: CMDtrigger

def CMDtrigger(parser, args):
  """Triggers a Swarming task.

  Accepts either the hash (sha1) of a .isolated file already uploaded or the
  path to an .isolated file to archive.

  If an .isolated file is specified instead of an hash, it is first archived.

  Passes all extra arguments provided after '--' as additional command line
  arguments for an isolated command specified in *.isolate file.
  """
  add_trigger_options(parser)
  add_sharding_options(parser)
  parser.add_option(
      '--dump-json',
      metavar='FILE',
      help='Dump details about the triggered task(s) to this file as json')
  options, args = parser.parse_args(args)
  task_request = process_trigger_options(parser, options, args)
  try:
    tasks = trigger_task_shards(
        options.swarming, task_request, options.shards)
    if tasks:
      print('Triggered task: %s' % options.task_name)
      tasks_sorted = sorted(
          tasks.itervalues(), key=lambda x: x['shard_index'])
      if options.dump_json:
        data = {
          'base_task_name': options.task_name,
          'tasks': tasks,
          'request': task_request_to_raw_request(task_request),
        }
        tools.write_json(unicode(options.dump_json), data, True)
        print('To collect results, use:')
        print('  swarming.py collect -S %s --json %s' %
            (options.swarming, options.dump_json))
      else:
        print('To collect results, use:')
        print('  swarming.py collect -S %s %s' %
            (options.swarming, ' '.join(t['task_id'] for t in tasks_sorted)))
      print('Or visit:')
      for t in tasks_sorted:
        print('  ' + t['view_url'])
    return int(not tasks)
  except Failure:
    on_error.report(None)
    return 1
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:47,代码来源:swarming.py

示例7: isolated_to_hash

def isolated_to_hash(isolate_server, namespace, arg, algo, verbose):
  """Archives a .isolated file if needed.

  Returns the file hash to trigger and a bool specifying if it was a file (True)
  or a hash (False).
  """
  if arg.endswith('.isolated'):
    file_hash = archive(isolate_server, namespace, arg, algo, verbose)
    if not file_hash:
      on_error.report('Archival failure %s' % arg)
      return None, True
    return file_hash, True
  elif isolateserver.is_valid_hash(arg, algo):
    return arg, False
  else:
    on_error.report('Invalid hash %s' % arg)
    return None, False
开发者ID:bpsinc-native,项目名称:src_tools_swarming_client,代码行数:17,代码来源:swarming.py

示例8: isolated_to_hash

def isolated_to_hash(arg, algo):
    """Archives a .isolated file if needed.

  Returns the file hash to trigger and a bool specifying if it was a file (True)
  or a hash (False).
  """
    if arg.endswith(".isolated"):
        file_hash = isolated_format.hash_file(arg, algo)
        if not file_hash:
            on_error.report("Archival failure %s" % arg)
            return None, True
        return file_hash, True
    elif isolated_format.is_valid_hash(arg, algo):
        return arg, False
    else:
        on_error.report("Invalid hash %s" % arg)
        return None, False
开发者ID:Teamxrtc,项目名称:webrtc-streaming-node,代码行数:17,代码来源:swarming.py

示例9: swarming_trigger

def swarming_trigger(swarming, raw_request):
    """Triggers a request on the Swarming server and returns the json data.

  It's the low-level function.

  Returns:
    {
      'request': {
        'created_ts': u'2010-01-02 03:04:05',
        'name': ..
      },
      'task_id': '12300',
    }
  """
    logging.info("Triggering: %s", raw_request["name"])

    result = net.url_read_json(swarming + "/_ah/api/swarming/v1/tasks/new", data=raw_request)
    if not result:
        on_error.report("Failed to trigger task %s" % raw_request["name"])
        return None
    return result
开发者ID:Teamxrtc,项目名称:webrtc-streaming-node,代码行数:21,代码来源:swarming.py

示例10: CMDcollect

def CMDcollect(parser, args):
    """Retrieves results of one or multiple Swarming task by its ID.

  The result can be in multiple part if the execution was sharded. It can
  potentially have retries.
  """
    add_collect_options(parser)
    parser.add_option("-j", "--json", help="Load the task ids from .json as saved by trigger --dump-json")
    options, args = parser.parse_args(args)
    if not args and not options.json:
        parser.error("Must specify at least one task id or --json.")
    if args and options.json:
        parser.error("Only use one of task id or --json.")

    if options.json:
        try:
            with open(options.json) as f:
                tasks = sorted(json.load(f)["tasks"].itervalues(), key=lambda x: x["shard_index"])
                args = [t["task_id"] for t in tasks]
        except (KeyError, IOError, TypeError, ValueError):
            parser.error("Failed to parse %s" % options.json)
    else:
        valid = frozenset("0123456789abcdef")
        if any(not valid.issuperset(task_id) for task_id in args):
            parser.error("Task ids are 0-9a-f.")

    try:
        return collect(
            options.swarming,
            None,
            args,
            options.timeout,
            options.decorate,
            options.print_status_updates,
            options.task_summary_json,
            options.task_output_dir,
        )
    except Failure:
        on_error.report(None)
        return 1
开发者ID:Teamxrtc,项目名称:webrtc-streaming-node,代码行数:40,代码来源:swarming.py

示例11: CMDtrigger

def CMDtrigger(parser, args):
    """Triggers a Swarming task.

  Accepts either the hash (sha1) of a .isolated file already uploaded or the
  path to an .isolated file to archive.

  If an .isolated file is specified instead of an hash, it is first archived.

  Passes all extra arguments provided after '--' as additional command line
  arguments for an isolated command specified in *.isolate file.
  """
    add_trigger_options(parser)
    add_sharding_options(parser)
    parser.add_option(
        "--dump-json", metavar="FILE", help="Dump details about the triggered task(s) to this file as json"
    )
    options, args = parser.parse_args(args)
    task_request = process_trigger_options(parser, options, args)
    try:
        tasks = trigger_task_shards(options.swarming, task_request, options.shards)
        if tasks:
            print ("Triggered task: %s" % options.task_name)
            tasks_sorted = sorted(tasks.itervalues(), key=lambda x: x["shard_index"])
            if options.dump_json:
                data = {"base_task_name": options.task_name, "tasks": tasks}
                tools.write_json(options.dump_json, data, True)
                print ("To collect results, use:")
                print ("  swarming.py collect -S %s --json %s" % (options.swarming, options.dump_json))
            else:
                print ("To collect results, use:")
                print (
                    "  swarming.py collect -S %s %s" % (options.swarming, " ".join(t["task_id"] for t in tasks_sorted))
                )
            print ("Or visit:")
            for t in tasks_sorted:
                print ("  " + t["view_url"])
        return int(not tasks)
    except Failure:
        on_error.report(None)
        return 1
开发者ID:Teamxrtc,项目名称:webrtc-streaming-node,代码行数:40,代码来源:swarming.py

示例12: CMDrun

def CMDrun(parser, args):
    """Triggers a task and wait for the results.

  Basically, does everything to run a command remotely.
  """
    add_trigger_options(parser)
    add_collect_options(parser)
    add_sharding_options(parser)
    options, args = parser.parse_args(args)
    task_request = process_trigger_options(parser, options, args)
    try:
        tasks = trigger_task_shards(options.swarming, task_request, options.shards)
    except Failure as e:
        on_error.report("Failed to trigger %s(%s): %s" % (options.task_name, args[0], e.args[0]))
        return 1
    if not tasks:
        on_error.report("Failed to trigger the task.")
        return 1
    print ("Triggered task: %s" % options.task_name)
    task_ids = [t["task_id"] for t in sorted(tasks.itervalues(), key=lambda x: x["shard_index"])]
    try:
        return collect(
            options.swarming,
            options.task_name,
            task_ids,
            options.timeout,
            options.decorate,
            options.print_status_updates,
            options.task_summary_json,
            options.task_output_dir,
        )
    except Failure:
        on_error.report(None)
        return 1
开发者ID:Teamxrtc,项目名称:webrtc-streaming-node,代码行数:34,代码来源:swarming.py

示例13: swarming_trigger

def swarming_trigger(swarming, raw_request):
  """Triggers a request on the Swarming server and returns the json data.

  It's the low-level function.

  Returns:
    {
      'request': {
        'created_ts': u'2010-01-02 03:04:05',
        'name': ..
      },
      'task_id': '12300',
    }
  """
  logging.info('Triggering: %s', raw_request['name'])

  result = net.url_read_json(
      swarming + '/_ah/api/swarming/v1/tasks/new', data=raw_request)
  if not result:
    on_error.report('Failed to trigger task %s' % raw_request['name'])
    return None
  if result.get('error'):
    # The reply is an error.
    msg = 'Failed to trigger task %s' % raw_request['name']
    if result['error'].get('errors'):
      for err in result['error']['errors']:
        if err.get('message'):
          msg += '\nMessage: %s' % err['message']
        if err.get('debugInfo'):
          msg += '\nDebug info:\n%s' % err['debugInfo']
    elif result['error'].get('message'):
      msg += '\nMessage: %s' % result['error']['message']

    on_error.report(msg)
    return None
  return result
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:36,代码来源:swarming.py

示例14: CMDrun

def CMDrun(parser, args):
  """Triggers a task and wait for the results.

  Basically, does everything to run a command remotely.
  """
  add_trigger_options(parser)
  add_collect_options(parser)
  add_sharding_options(parser)
  args, isolated_cmd_args = extract_isolated_command_extra_args(args)
  options, args = parser.parse_args(args)
  process_trigger_options(parser, options, args)

  auth.ensure_logged_in(options.swarming)
  if file_path.is_url(options.isolate_server):
    auth.ensure_logged_in(options.isolate_server)
  try:
    tasks, task_name = trigger(
        swarming=options.swarming,
        isolate_server=options.isolate_server or options.indir,
        namespace=options.namespace,
        file_hash_or_isolated=args[0],
        task_name=options.task_name,
        extra_args=isolated_cmd_args,
        shards=options.shards,
        dimensions=options.dimensions,
        env=dict(options.env),
        deadline=options.deadline,
        verbose=options.verbose,
        profile=options.profile,
        priority=options.priority)
  except Failure as e:
    on_error.report(
        'Failed to trigger %s(%s): %s' %
        (options.task_name, args[0], e.args[0]))
    return 1
  if not tasks:
    on_error.report('Failed to trigger the task.')
    return 1
  if task_name != options.task_name:
    print('Triggered task: %s' % task_name)
  try:
    # TODO(maruel): Use task_ids, it's much more efficient!
    return collect(
        options.swarming,
        task_name,
        options.shards,
        options.timeout,
        options.decorate,
        options.print_status_updates,
        options.task_summary_json,
        options.task_output_dir)
  except Failure:
    on_error.report(None)
    return 1
开发者ID:bpsinc-native,项目名称:src_tools_swarming_client,代码行数:54,代码来源:swarming.py

示例15: run_shell_out

def run_shell_out(url, mode):
  # Enable 'report_on_exception_exit' even though main file is *_test.py.
  on_error._is_in_test = lambda: False

  # Hack it out so registering works.
  on_error._ENABLED_DOMAINS = (socket.getfqdn(),)

  # Don't try to authenticate into localhost.
  on_error.net.OAuthAuthenticator = lambda *_: None

  if not on_error.report_on_exception_exit(url):
    print 'Failure to register the handler'
    return 1

  # Hack out certificate verification because we are using a self-signed
  # certificate here. In practice, the SSL certificate is signed to guard
  # against MITM attacks.
  on_error._SERVER.engine.session.verify = False

  if mode == 'crash':
    # Sadly, net is a bit overly verbose, which breaks
    # test_shell_out_crash_server_down.
    logging.error = lambda *_, **_kwargs: None
    logging.warning = lambda *_, **_kwargs: None
    raise ValueError('Oops')

  if mode == 'report':
    # Generate a manual report without an exception frame. Also set the version
    # value.
    setattr(sys.modules['__main__'], '__version__', '123')
    on_error.report('Oh dang')

  if mode == 'exception':
    # Report from inside an exception frame.
    try:
      raise TypeError('You are not my type')
    except TypeError:
      on_error.report('Really')

  if mode == 'exception_no_msg':
    # Report from inside an exception frame.
    try:
      raise TypeError('You are not my type #2')
    except TypeError:
      on_error.report(None)
  return 0
开发者ID:Crawping,项目名称:chromium_extract,代码行数:46,代码来源:on_error_test.py


注:本文中的utils.on_error.report函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。