1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-28 02:36:15 +01:00

Refactor the do_vc code a bit

No functional changes.
This commit is contained in:
Marcus Huewe 2018-08-17 22:43:50 +02:00
parent 820c3adc71
commit 86e5757832

View File

@ -8787,40 +8787,36 @@ Please submit there instead, or use --nodevelproject to force direct submission.
else:
apiurl = self.get_api_url()
# set user's full name and email if the realname and mailaddr env variables are not set
# 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 = []
vc_id_missing = { 'realname': False, 'email': False }
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 'VC_REALNAME' in os.environ:
pass
elif 'realname' in conf.config['api_host_options'][apiurl]:
os.environ['VC_REALNAME'] = conf.config['api_host_options'][apiurl]['realname']
else:
vc_id_missing['realname'] = True
if 'VC_MAILADDR' in os.environ or 'mailaddr' in os.environ:
pass
elif 'email' in conf.config['api_host_options'][apiurl]:
os.environ['VC_MAILADDR'] = conf.config['api_host_options'][apiurl]['email']
os.environ['mailaddr'] = conf.config['api_host_options'][apiurl]['email']
else:
vc_id_missing['email'] = True
if True in list(vc_id_missing.values()):
if missing_tags:
user = conf.get_apiurl_usr(apiurl)
data = get_user_data(apiurl, user, 'realname', 'email')
if data:
if vc_id_missing['realname'] and (data[0] != "-"):
os.environ['VC_REALNAME'] = data[0]
else:
print('Try env VC_REALNAME=...', file=sys.stderr)
if vc_id_missing['email'] and (data[1] != "-"):
os.environ['VC_MAILADDR'] = data[1]
os.environ['mailaddr'] = data[1]
else:
print('Try env VC_MAILADDR=...', file=sys.stderr)
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: