osclib/staging-api: lazy-load all config values to allow for placement in remote config.

This commit is contained in:
Jimmy Berry 2018-03-07 15:39:55 -06:00
parent d30db7eb1d
commit e3168d6c34

View File

@ -67,16 +67,7 @@ class StagingAPI(object):
self.project = project
# Store some prefix / data used in the code.
self.cstaging = conf.config[project]['staging']
self.cstaging_group = conf.config[project]['staging-group']
self.cstaging_archs = conf.config[project]['staging-archs'].split()
self.cstaging_dvd_archs = conf.config[project]['staging-dvd-archs'].split()
self._cstaging_nocleanup = None
self.crings = conf.config[project]['rings']
self.cnonfree = conf.config[project]['nonfree']
self.crebuild = conf.config[project]['rebuild']
self.cproduct = conf.config[project]['product']
self.copenqa = conf.config[project]['openqa']
self.user = conf.get_apiurl_usr(apiurl)
self.delreq_review = conf.config[project]['delreq-review']
self.main_repo = conf.config[project]['main-repo']
@ -99,6 +90,24 @@ class StagingAPI(object):
Cache.init()
def __getattr__(self, attr):
"""Lazy-load all config values to allow for placement in remote config."""
if attr.startswith('c'):
# Drop 'c' prefix and change to config key format.
key = attr[1:].replace('_', '-')
# This will intentionally cause error if key does not exists.
value = conf.config[self.project][key]
if key.endswith('archs'):
value = value.split()
# This code will only be called for the first access.
setattr(self, attr, value)
return value
# Raise AttributeError like normal.
return self.__getattribute__(attr)
@property
def cstaging_nocleanup(self):
"""Lazy-load value to allow for placement in remote config."""