diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-04-09 15:48:50 +0100 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-07-27 12:24:56 +0000 |
commit | 8b46e874070911b2923c4750fcc8fa855b034c7f (patch) | |
tree | 8fdd260c3ffe5caa13a4058b6c644057da2670d7 /buildstream | |
parent | 6ea97b17c8947f69ca713f20c5bb5bf957fdf371 (diff) | |
download | buildstream-8b46e874070911b2923c4750fcc8fa855b034c7f.tar.gz |
project: Parse and store mirrors
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_project.py | 51 | ||||
-rw-r--r-- | buildstream/_versions.py | 2 |
2 files changed, 50 insertions, 3 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py index 54ec9ee34..fee721bbb 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -19,7 +19,7 @@ import os import multiprocessing # for cpu_count() -from collections import Mapping +from collections import Mapping, OrderedDict from pluginbase import PluginBase from . import utils from . import _cachekey @@ -94,6 +94,8 @@ class Project(): self.base_env_nocache = None # The base nocache mask (list) for the environment self.element_overrides = {} # Element specific configurations self.source_overrides = {} # Source specific configurations + self.mirrors = OrderedDict() # contains dicts of alias-mappings to URIs. + self.default_mirror = None # The name of the preferred mirror. # # Private Members @@ -202,6 +204,36 @@ class Project(): self._assert_plugin_format(source, version) return source + # get_alias_uri() + # + # Returns the URI for a given alias, if it exists + # + # Args: + # alias (str): The alias. + # + # Returns: + # str: The URI for the given alias; or None: if there is no URI for + # that alias. + def get_alias_uri(self, alias): + return self._aliases.get(alias) + + # get_alias_uris() + # + # Returns a list of every URI to replace an alias with + def get_alias_uris(self, alias): + if not alias or alias not in self._aliases: + return [None] + + mirror_list = [] + for key, alias_mapping in self.mirrors.items(): + if alias in alias_mapping: + if key == self.default_mirror: + mirror_list = alias_mapping[alias] + mirror_list + else: + mirror_list += alias_mapping[alias] + mirror_list.append(self._aliases[alias]) + return mirror_list + # _load(): # # Loads the project configuration file in the project directory. @@ -249,7 +281,7 @@ class Project(): 'aliases', 'name', 'artifacts', 'options', 'fail-on-overlap', 'shell', - 'ref-storage', 'sandbox' + 'ref-storage', 'sandbox', 'mirrors', ]) # The project name, element path and option declarations @@ -414,6 +446,21 @@ class Project(): self._shell_host_files.append(mount) + mirrors = _yaml.node_get(config, list, 'mirrors', default_value=[]) + for mirror in mirrors: + allowed_mirror_fields = [ + 'name', 'aliases' + ] + _yaml.node_validate(mirror, allowed_mirror_fields) + mirror_name = _yaml.node_get(mirror, str, 'name') + alias_mappings = {} + for alias_mapping, uris in _yaml.node_items(mirror['aliases']): + assert isinstance(uris, list) + alias_mappings[alias_mapping] = list(uris) + self.mirrors[mirror_name] = alias_mappings + if not self.default_mirror: + self.default_mirror = mirror_name + # _assert_plugin_format() # # Helper to raise a PluginError if the loaded plugin is of a lesser version then diff --git a/buildstream/_versions.py b/buildstream/_versions.py index 19699e125..4531d9a72 100644 --- a/buildstream/_versions.py +++ b/buildstream/_versions.py @@ -23,7 +23,7 @@ # This version is bumped whenever enhancements are made # to the `project.conf` format or the core element format. # -BST_FORMAT_VERSION = 10 +BST_FORMAT_VERSION = 11 # The base BuildStream artifact version |