| # 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. |
| |
| 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 __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. |
| """ |
| 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) |
| |
| @property |
| def _catapult(self): |
| return self.m.cipd.ensure_tool("fuchsia/infra/catapult/${platform}", "latest") |
| |
| 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 arguments 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) |