mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-10 04:55:48 +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):
|
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}
|
% {'repo': repo, 'arch': arch, 'project': prj, 'package': pac, 'apihost': apihost}
|
||||||
return buildroot
|
return buildroot
|
||||||
|
|
||||||
|
|
||||||
def build_as_user():
|
def build_as_user():
|
||||||
if os.environ.get('OSC_SU_WRAPPER', conf.config['su-wrapper']).split():
|
if conf.config["su-wrapper"]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def su_wrapper(cmd):
|
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:
|
||||||
if sucmd[0] == 'su':
|
if sucmd[0] == 'su':
|
||||||
if sucmd[-1] == '-c':
|
if sucmd[-1] == '-c':
|
||||||
@ -782,18 +782,6 @@ def main(apiurl, store, opts, argv):
|
|||||||
if opts.wipe:
|
if opts.wipe:
|
||||||
buildargs.append("--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
|
pacname = pac
|
||||||
if pacname == '_repository':
|
if pacname == '_repository':
|
||||||
if not opts.local_package:
|
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]
|
pacname = os.path.splitext(os.path.basename(build_descr))[0]
|
||||||
apihost = urlsplit(apiurl)[1]
|
apihost = urlsplit(apiurl)[1]
|
||||||
if not build_root:
|
if not build_root:
|
||||||
build_root = config['build-root']
|
build_root = calculate_build_root(apihost, prj, pacname, repo, arch)
|
||||||
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
|
|
||||||
|
|
||||||
# We configure sccache after pacname, so that in default cases we can have an sccache for each
|
# 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.
|
# 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.')
|
raise oscerr.WrongArgs('Wrong number of arguments.')
|
||||||
|
|
||||||
# TODO: refactor/unify buildroot calculation and move it to core.py
|
# 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]
|
apihost = urlsplit(self.get_api_url())[1]
|
||||||
buildroot = buildroot % {'project': project, 'package': package,
|
buildroot = osc_build.calculate_build_root(apihost, project, package, repo, arch)
|
||||||
'repo': repo, 'arch': arch, 'apihost': apihost}
|
|
||||||
offset = 0
|
offset = 0
|
||||||
if opts.offset:
|
if opts.offset:
|
||||||
offset = int(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``
|
Supported substitutions: ``%(repo)s``, ``%(arch)s``, ``%(project)s``, ``%(package)s`` and ``%(apihost)s``
|
||||||
where ``apihost`` is the hostname extracted from the currently used ``apiurl``.
|
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.
|
Passed as ``--root <VALUE>`` to the build tool.
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
@ -1745,7 +1747,7 @@ def get_config(override_conffile=None,
|
|||||||
Configure osc.
|
Configure osc.
|
||||||
|
|
||||||
The configuration options are loaded with the following priority:
|
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()
|
2. override arguments provided to get_config()
|
||||||
3. oscrc config file
|
3. oscrc config file
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user