From fefd7c1dea3cdedbfb64f335f61f7e8badaee1a3 Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Tue, 29 Jan 2019 14:20:12 +0100 Subject: [PATCH] Move vc env exporting code into core.vc_export_env This allows for reuse. In the future, these variables should also be exported when executing source services. --- osc/commandline.py | 32 +------------------------------- osc/core.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index c43aa623..acc2ca9f 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -8850,37 +8850,6 @@ Please submit there instead, or use --nodevelproject to force direct submission. else: apiurl = self.get_api_url() - # try to set the env variables for the user's realname and email - # (the variables are used by the "vc" script) - tag2envs = {'realname': ['VC_REALNAME'], - 'email': ['VC_MAILADDR', 'mailaddr']} - tag2val = {} - missing_tags = [] - - for (tag, envs) in tag2envs.items(): - env_present = [env for env in envs if env in os.environ] - config_present = tag in conf.config['api_host_options'][apiurl] - if not env_present and not config_present: - missing_tags.append(tag) - elif config_present: - tag2val[tag] = conf.config['api_host_options'][apiurl][tag] - - if missing_tags: - user = conf.get_apiurl_usr(apiurl) - data = get_user_data(apiurl, user, *missing_tags) - if data is not None: - for tag in missing_tags: - val = data.pop(0) - if val != '-': - tag2val[tag] = val - else: - msg = 'Try env %s=...' % tag2envs[tag][0] - print(msg, file=sys.stderr) - - for (tag, val) in tag2val.items(): - for env in tag2envs[tag]: - os.environ[env] = val - if meego_style: if opts.message or opts.just_edit: print('Warning: to edit MeeGo style changelog, opts will be ignored.', file=sys.stderr) @@ -8899,6 +8868,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. cmd_list.extend(args) + vc_export_env(apiurl) vc = Popen(cmd_list) vc.wait() sys.exit(vc.returncode) diff --git a/osc/core.py b/osc/core.py index d4f2309a..289bc984 100644 --- a/osc/core.py +++ b/osc/core.py @@ -7786,4 +7786,37 @@ def checkout_deleted_package(apiurl, proj, pkg, dst): f.write(data) print('done.') +def vc_export_env(apiurl, quiet=False): + # try to set the env variables for the user's realname and email + # (the variables are used by the "vc" script) + tag2envs = {'realname': ['VC_REALNAME'], + 'email': ['VC_MAILADDR', 'mailaddr']} + tag2val = {} + missing_tags = [] + + for (tag, envs) in tag2envs.items(): + env_present = [env for env in envs if env in os.environ] + config_present = tag in conf.config['api_host_options'][apiurl] + if not env_present and not config_present: + missing_tags.append(tag) + elif config_present: + tag2val[tag] = conf.config['api_host_options'][apiurl][tag] + + if missing_tags: + user = conf.get_apiurl_usr(apiurl) + data = get_user_data(apiurl, user, *missing_tags) + if data is not None: + for tag in missing_tags: + val = data.pop(0) + if val != '-': + tag2val[tag] = val + elif not quiet: + msg = 'Try env %s=...' % tag2envs[tag][0] + print(msg, file=sys.stderr) + + for (tag, val) in tag2val.items(): + for env in tag2envs[tag]: + os.environ[env] = val + + # vim: sw=4 et