osc-staging: implement remote config.

This commit is contained in:
Jimmy Berry 2017-04-28 22:12:32 -05:00
parent d3649f7903
commit d4a2af58c8
2 changed files with 20 additions and 1 deletions

View File

@ -338,7 +338,7 @@ def do_staging(self, subcmd, opts, *args):
opts.project = self._full_project_name(opts.project) opts.project = self._full_project_name(opts.project)
opts.apiurl = self.get_api_url() opts.apiurl = self.get_api_url()
opts.verbose = False opts.verbose = False
Config(opts.project) config = Config(opts.project)
colorama.init(autoreset=True, colorama.init(autoreset=True,
strip=(opts.no_color or not bool(int(conf.config.get('staging.color', 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: with lock:
api = StagingAPI(opts.apiurl, opts.project) api = StagingAPI(opts.apiurl, opts.project)
config.apply_remote(api)
# call the respective command and parse args by need # call the respective command and parse args by need
if cmd == 'check': if cmd == 'check':

View File

@ -15,6 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
import io
import os import os
import operator import operator
import re import re
@ -96,6 +97,7 @@ class Config(object):
conf_file = os.environ.get('OSC_CONFIG', '~/.oscrc') conf_file = os.environ.get('OSC_CONFIG', '~/.oscrc')
self.conf_file = os.path.expanduser(conf_file) self.conf_file = os.path.expanduser(conf_file)
self.remote_values = None
# Populate the configuration dictionary # Populate the configuration dictionary
self.populate_conf() self.populate_conf()
@ -120,6 +122,9 @@ class Config(object):
defaults[k] = v defaults[k] = v
break break
if self.remote_values:
defaults.update(self.remote_values)
# Update the configuration, only when it is necessary # Update the configuration, only when it is necessary
conf.config[self.project] = self.read_section(self.project, defaults) conf.config[self.project] = self.read_section(self.project, defaults)
@ -141,3 +146,16 @@ class Config(object):
return dict(cp.items(section)) return dict(cp.items(section))
else: else:
return defaults 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', '')