blob: 9496d678d3bba11ec13af02981fb4eeb1c3145db [file] [log] [blame]
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import fnmatch
from recipe_engine import recipe_api
CATAPULT_URL = 'https://chromeperf.appspot.com'
class CatapultApi(recipe_api.RecipeApi):
"""CatapultApi provides support for the Catapult infra tool."""
FILE_PATTERN = '*.catapult_json'
def __init__(self, *args, **kwargs):
super(CatapultApi, self).__init__(*args, **kwargs)
self._catapult = None
def __call__(self, subcommand, *flags, **kwargs):
"""Return a catapult command step.
Args:
subcommand (str): The Catapult CLI command to run; e.g. 'make_histogram'
or 'update'
name (str): The name to use for this step.
"""
self._ensure()
cmd = [self._catapult, subcommand]
cmd.extend(flags)
name = kwargs.pop('name', 'catapult ' + subcommand)
with self.m.context(infra_steps=True):
return self.m.step(name, cmd, **kwargs)
def _ensure(self):
if self._catapult:
return
with self.m.step.nest('ensure catapult'):
with self.m.context(infra_steps=True):
cipd_dir = self.m.path['start_dir'].join('cipd', 'catapult')
pkgs = self.m.cipd.EnsureFile()
pkgs.add_package('fuchsia/infra/catapult/${platform}', 'latest')
self.m.cipd.ensure(cipd_dir, pkgs)
self._catapult = cipd_dir.join('catapult')
def upload(self, input_file, timeout=None, **kwargs):
"""
Uploads performance JSON data to a dashboard.
Args:
input_file (Path): Full path to the input file to upload.
timeout (string): Optional request timeout duration string. e.g. 12s or
1m.
kwargs: Keyword argments passed to the returned step.
Returns:
A step to execute the upload subcommand.
"""
args = ['upload', '-url', CATAPULT_URL]
if timeout:
args += ['-timeout', timeout]
args.append(input_file)
return self(*args, **kwargs)
# TODO(olivernewman): Delete this method once the fuchsia_perf recipe is
# removed, and just rely on glob searches for catapult files.
def is_catapult_file(self, path):
return fnmatch.fnmatch(path, self.FILE_PATTERN)