def _handle_artifact(path, response): if path.endswith(".json"): return response.json() if path.endswith(".yml"): return yaml.load_stream(response.text) response.raw.read = functools.partial(response.raw.read, decode_content=True) return response.raw
def load_data(filename): with open(filename) as f: if filename.endswith('.yml'): return yaml.load_stream(f) elif filename.endswith('.json'): return json.load(f) else: raise Exception("unknown filename {}".format(filename))
def load_parameters_file(filename, strict=True, overrides=None, trust_domain=None): """ Load parameters from a path, url, decision task-id or project. Examples: task-id=fdtgsD5DQUmAQZEaGMvQ4Q project=mozilla-central """ import requests from taskgraph.util.taskcluster import get_artifact_url, find_task_id from taskgraph.util import yaml if overrides is None: overrides = {} if not filename: return Parameters(strict=strict, **overrides) try: # reading parameters from a local parameters.yml file f = open(filename) except IOError: # fetching parameters.yml using task task-id, project or supplied url task_id = None if filename.startswith("task-id="): task_id = filename.split("=")[1] elif filename.startswith("project="): if trust_domain is None: raise ValueError( "Can't specify parameters by project " "if trust domain isn't supplied.", ) index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format( trust_domain=trust_domain, project=filename.split("=")[1], ) task_id = find_task_id(index) if task_id: filename = get_artifact_url(task_id, 'public/parameters.yml') logger.info("Loading parameters from {}".format(filename)) resp = requests.get(filename, stream=True) resp.raise_for_status() f = resp.raw if filename.endswith('.yml'): kwargs = yaml.load_stream(f) elif filename.endswith('.json'): kwargs = json.load(f) else: raise TypeError( "Parameters file `{}` is not JSON or YAML".format(filename)) kwargs.update(overrides) return Parameters(strict=strict, **kwargs)
def load_parameters_file(spec, strict=True, overrides=None, trust_domain=None): """ Load parameters from a path, url, decision task-id or project. Examples: task-id=fdtgsD5DQUmAQZEaGMvQ4Q project=mozilla-central """ from taskgraph.util.taskcluster import get_artifact_url, find_task_id from taskgraph.util import yaml if overrides is None: overrides = {} overrides["spec"] = spec if not spec: return Parameters(strict=strict, **overrides) try: # reading parameters from a local parameters.yml file f = open(spec) except OSError: # fetching parameters.yml using task task-id, project or supplied url task_id = None if spec.startswith("task-id="): task_id = spec.split("=")[1] elif spec.startswith("project="): if trust_domain is None: raise ValueError( "Can't specify parameters by project " "if trust domain isn't supplied.", ) index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format( trust_domain=trust_domain, project=spec.split("=")[1], ) task_id = find_task_id(index) if task_id: spec = get_artifact_url(task_id, "public/parameters.yml") f = urlopen(spec) if spec.endswith(".yml"): kwargs = yaml.load_stream(f) elif spec.endswith(".json"): kwargs = json.load(f) else: raise TypeError(f"Parameters file `{spec}` is not JSON or YAML") kwargs.update(overrides) return Parameters(strict=strict, **kwargs)