mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 14:56:14 +01:00
Remove any duplicated code loading configuration from ENV
The current conf.get_config() function already handles loading from ENV. Also, always use osc.build.calculate_build_root() instead of making a custom variable substitution.
This commit is contained in:
parent
91a30963d5
commit
2f1cb0edb1
28
osc/build.py
28
osc/build.py
@ -606,19 +606,19 @@ def calculate_prj_pac(store, opts, descr):
|
||||
|
||||
|
||||
def calculate_build_root(apihost, prj, pac, repo, arch):
|
||||
buildroot = os.environ.get('OSC_BUILD_ROOT', conf.config['build-root']) \
|
||||
buildroot = conf.config["build-root"] \
|
||||
% {'repo': repo, 'arch': arch, 'project': prj, 'package': pac, 'apihost': apihost}
|
||||
return buildroot
|
||||
|
||||
|
||||
def build_as_user():
|
||||
if os.environ.get('OSC_SU_WRAPPER', conf.config['su-wrapper']).split():
|
||||
if conf.config["su-wrapper"]:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def su_wrapper(cmd):
|
||||
sucmd = os.environ.get('OSC_SU_WRAPPER', conf.config['su-wrapper']).split()
|
||||
sucmd = conf.config['su-wrapper'].split()
|
||||
if sucmd:
|
||||
if sucmd[0] == 'su':
|
||||
if sucmd[-1] == '-c':
|
||||
@ -782,18 +782,6 @@ def main(apiurl, store, opts, argv):
|
||||
if opts.wipe:
|
||||
buildargs.append("--wipe")
|
||||
|
||||
orig_build_root = config['build-root']
|
||||
# make it possible to override configuration of the rc file
|
||||
for var in ['OSC_PACKAGECACHEDIR', 'OSC_SU_WRAPPER', 'OSC_BUILD_ROOT']:
|
||||
val = os.getenv(var)
|
||||
if val:
|
||||
if var.startswith('OSC_'):
|
||||
var = var[4:]
|
||||
var = var.lower().replace('_', '-')
|
||||
if var in config:
|
||||
print('Overriding config value for %s=\'%s\' with \'%s\'' % (var, config[var], val))
|
||||
config[var] = val
|
||||
|
||||
pacname = pac
|
||||
if pacname == '_repository':
|
||||
if not opts.local_package:
|
||||
@ -805,15 +793,7 @@ def main(apiurl, store, opts, argv):
|
||||
pacname = os.path.splitext(os.path.basename(build_descr))[0]
|
||||
apihost = urlsplit(apiurl)[1]
|
||||
if not build_root:
|
||||
build_root = config['build-root']
|
||||
if build_root == orig_build_root:
|
||||
# ENV var was not set
|
||||
build_root = config['api_host_options'][apiurl].get('build-root', build_root)
|
||||
try:
|
||||
build_root = build_root % {'repo': repo, 'arch': arch,
|
||||
'project': prj, 'package': pacname, 'apihost': apihost}
|
||||
except KeyError:
|
||||
pass
|
||||
build_root = calculate_build_root(apihost, prj, pacname, repo, arch)
|
||||
|
||||
# We configure sccache after pacname, so that in default cases we can have an sccache for each
|
||||
# package to prevent cross-cache polutions. It helps to make the local-use case a bit nicer.
|
||||
|
@ -6419,10 +6419,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
raise oscerr.WrongArgs('Wrong number of arguments.')
|
||||
|
||||
# TODO: refactor/unify buildroot calculation and move it to core.py
|
||||
buildroot = os.environ.get('OSC_BUILD_ROOT', conf.config['build-root'])
|
||||
apihost = urlsplit(self.get_api_url())[1]
|
||||
buildroot = buildroot % {'project': project, 'package': package,
|
||||
'repo': repo, 'arch': arch, 'apihost': apihost}
|
||||
buildroot = osc_build.calculate_build_root(apihost, project, package, repo, arch)
|
||||
|
||||
offset = 0
|
||||
if opts.offset:
|
||||
offset = int(opts.offset)
|
||||
|
@ -1005,6 +1005,8 @@ class Options(OscOptions):
|
||||
Supported substitutions: ``%(repo)s``, ``%(arch)s``, ``%(project)s``, ``%(package)s`` and ``%(apihost)s``
|
||||
where ``apihost`` is the hostname extracted from the currently used ``apiurl``.
|
||||
|
||||
NOTE: The configuration holds the original unexpanded string. Call ``osc.build.get_build_root()`` with proper arguments to retrieve an actual path.
|
||||
|
||||
Passed as ``--root <VALUE>`` to the build tool.
|
||||
"""
|
||||
),
|
||||
@ -1745,7 +1747,7 @@ def get_config(override_conffile=None,
|
||||
Configure osc.
|
||||
|
||||
The configuration options are loaded with the following priority:
|
||||
1. environment variables: OSC_<uppercase-option>
|
||||
1. environment variables: OSC_<uppercase_option>
|
||||
2. override arguments provided to get_config()
|
||||
3. oscrc config file
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user