Skip to content

Commit

Permalink
Move vc env exporting code into core.vc_export_env
Browse files Browse the repository at this point in the history
This allows for reuse. In the future, these variables should also
be exported when executing source services.
  • Loading branch information
marcus-h committed Jan 29, 2019
1 parent c534d7e commit fefd7c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
32 changes: 1 addition & 31 deletions osc/commandline.py
Expand Up @@ -8850,37 +8850,6 @@ def do_vc(self, subcmd, opts, *args):
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)
Expand All @@ -8899,6 +8868,7 @@ def do_vc(self, subcmd, opts, *args):

cmd_list.extend(args)

vc_export_env(apiurl)
vc = Popen(cmd_list)
vc.wait()
sys.exit(vc.returncode)
Expand Down
33 changes: 33 additions & 0 deletions osc/core.py
Expand Up @@ -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

0 comments on commit fefd7c1

Please sign in to comment.