diff --git a/osc-staging.py b/osc-staging.py index ad22e3c5..2b9dbdba 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -338,7 +338,7 @@ def do_staging(self, subcmd, opts, *args): opts.project = self._full_project_name(opts.project) opts.apiurl = self.get_api_url() opts.verbose = False - Config(opts.project) + config = Config(opts.project) colorama.init(autoreset=True, strip=(opts.no_color or not bool(int(conf.config.get('staging.color', True))))) @@ -360,6 +360,7 @@ def do_staging(self, subcmd, opts, *args): with lock: api = StagingAPI(opts.apiurl, opts.project) + config.apply_remote(api) # call the respective command and parse args by need if cmd == 'check': diff --git a/osclib/conf.py b/osclib/conf.py index aaaa9332..8656a243 100644 --- a/osclib/conf.py +++ b/osclib/conf.py @@ -15,6 +15,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from ConfigParser import ConfigParser +import io import os import operator import re @@ -96,6 +97,7 @@ class Config(object): conf_file = os.environ.get('OSC_CONFIG', '~/.oscrc') self.conf_file = os.path.expanduser(conf_file) + self.remote_values = None # Populate the configuration dictionary self.populate_conf() @@ -120,6 +122,9 @@ class Config(object): defaults[k] = v break + if self.remote_values: + defaults.update(self.remote_values) + # Update the configuration, only when it is necessary conf.config[self.project] = self.read_section(self.project, defaults) @@ -141,3 +146,16 @@ class Config(object): return dict(cp.items(section)) else: return defaults + + def apply_remote(self, api): + """Fetch remote config and re-process (defaults, remote, .oscrc).""" + config = api.load_file_content(api.cstaging, 'dashboard', 'config') + if config: + cp = ConfigParser() + config = '[remote]\n' + config + cp.readfp(io.BytesIO(config)) + self.remote_values = dict(cp.items('remote')) + self.populate_conf() + else: + # Write empty config to allow for caching. + api.save_file_content(api.cstaging, 'dashboard', 'config', '')