This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch jonathan/mirror-client
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 32b110ea055613d3048599ccd9da80032c6ba838
Author: Jonathan Maw <[email protected]>
AuthorDate: Wed May 16 14:15:47 2018 +0100

    Set default mirror via command-line or user config
    
    In user config (buildstream.conf), it is set with the "default-mirror"
    field.
    
    On the command-line, it is set with "--default-mirror"
---
 buildstream/_context.py          | 6 ++++++
 buildstream/_frontend/app.py     | 3 ++-
 buildstream/_frontend/cli.py     | 2 ++
 buildstream/_project.py          | 5 +++--
 tests/completions/completions.py | 1 +
 5 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/buildstream/_context.py b/buildstream/_context.py
index bf7f495..5410a71 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -101,6 +101,9 @@ class Context():
         # What to do when a build fails in non interactive mode
         self.sched_error_action = 'continue'
 
+        # The default mirror to fetch from
+        self.default_mirror = None
+
         # Whether elements must be rebuilt when their dependencies have changed
         self._strict_build_plan = None
 
@@ -152,6 +155,7 @@ class Context():
         _yaml.node_validate(defaults, [
             'sourcedir', 'builddir', 'artifactdir', 'logdir',
             'scheduler', 'artifacts', 'logging', 'projects',
+            'default-mirror',
         ])
 
         for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir']:
@@ -196,6 +200,8 @@ class Context():
         # Load per-projects overrides
         self._project_overrides = _yaml.node_get(defaults, Mapping, 
'projects', default_value={})
 
+        self.default_mirror = _yaml.node_get(defaults, str, "default-mirror", 
default_value=None)
+
         # Shallow validation of overrides, parts of buildstream which rely
         # on the overrides are expected to validate elsewhere.
         for _, overrides in _yaml.node_items(self._project_overrides):
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index fa07a9a..2ab9106 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -204,7 +204,8 @@ class App():
         # Load the Project
         #
         try:
-            self.project = Project(directory, self.context, 
cli_options=self._main_options['option'])
+            self.project = Project(directory, self.context, 
cli_options=self._main_options['option'],
+                                   
default_mirror=self._main_options.get('default_mirror'))
         except LoadError as e:
 
             # Let's automatically start a `bst init` session in this case
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index c321fa9..b2308f9 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -159,6 +159,8 @@ def print_version(ctx, param, value):
               help="Elements must be rebuilt when their dependencies have 
changed")
 @click.option('--option', '-o', type=click.Tuple([str, str]), multiple=True, 
metavar='OPTION VALUE',
               help="Specify a project option")
[email protected]('--default-mirror', default=None,
+              help="The mirror to fetch from first, before attempting other 
mirrors")
 @click.pass_context
 def cli(context, **kwargs):
     """Build and manipulate BuildStream projects
diff --git a/buildstream/_project.py b/buildstream/_project.py
index 9fce29e..90a73d5 100644
--- a/buildstream/_project.py
+++ b/buildstream/_project.py
@@ -65,7 +65,7 @@ class HostMount():
 #
 class Project():
 
-    def __init__(self, directory, context, *, junction=None, cli_options=None):
+    def __init__(self, directory, context, *, junction=None, cli_options=None, 
default_mirror=None):
 
         # The project name
         self.name = None
@@ -91,7 +91,8 @@ class Project():
         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.
+
+        self.default_mirror = default_mirror or context.default_mirror  # The 
name of the preferred mirror.
 
         #
         # Private Members
diff --git a/tests/completions/completions.py b/tests/completions/completions.py
index cc98cb9..ec6ae9a 100644
--- a/tests/completions/completions.py
+++ b/tests/completions/completions.py
@@ -26,6 +26,7 @@ MAIN_OPTIONS = [
     "--colors ",
     "--config ",
     "--debug ",
+    "--default-mirror ",
     "--directory ",
     "--error-lines ",
     "--fetchers ",

Reply via email to