From b5d47ebd8c476473d149f1e5052d85a63be39dc1 Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Tue, 11 Feb 2014 11:56:44 +0100 Subject: [PATCH] - do_maintainer: fixed support for groups Ideally, the whole method will be refactored one day... --- osc/commandline.py | 14 ++++++++++++-- osc/core.py | 30 +++++++++++++++++------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 57565d43..43da97b5 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -7054,6 +7054,16 @@ Please submit there instead, or use --nodevelproject to force direct submission. ${cmd_usage} ${cmd_option_list} """ + def get_maintainer_data(apiurl, maintainer, verbose=False): + tags = ('email',) + if maintainer.startswith('group:'): + group = maintainer.replace('group:', '') + if verbose: + return [maintainer] + get_group_data(apiurl, group, 'title', *tags) + return get_group_data(apiurl, group, 'email') + if verbose: + tags = ('login', 'realname', 'email') + return get_user_data(apiurl, maintainer, *tags) binary = None prj = None @@ -7276,7 +7286,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. if opts.email: emails = [] for maintainer in maintainers.get(role, []): - user = get_user_data(apiurl, maintainer, 'email') + user = get_maintainer_data(apiurl, maintainer, verbose=False) if len(user): emails.append(''.join(user)) print(indent, end=' ') @@ -7284,7 +7294,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. elif opts.verbose: userdata = [] for maintainer in maintainers.get(role, []): - user = get_user_data(apiurl, maintainer, 'login', 'realname', 'email') + user = get_maintainer_data(apiurl, maintainer, verbose=True) userdata.append(user[0]) if user[1] != '-': userdata.append("%s <%s>"%(user[1], user[2])) diff --git a/osc/core.py b/osc/core.py index df74ebc5..d66658a9 100644 --- a/osc/core.py +++ b/osc/core.py @@ -4013,26 +4013,30 @@ def get_user_meta(apiurl, user): return None -def get_user_data(apiurl, user, *tags): - """get specified tags from the user meta""" - meta = get_user_meta(apiurl, user) +def _get_xml_data(meta, *tags): data = [] if meta != None: root = ET.fromstring(meta) for tag in tags: - try: - if root.find(tag).text != None: - data.append(root.find(tag).text) - else: - # tag is empty - data.append('-') - except AttributeError: - # this part is reached if the tags tuple contains an invalid tag - print('The xml file for user \'%s\' seems to be broken' % user) - return [] + elm = root.find(tag) + if elm is None or elm.text is None: + data.append('-') + else: + data.append(elm.text) return data +def get_user_data(apiurl, user, *tags): + """get specified tags from the user meta""" + meta = get_user_meta(apiurl, user) + return _get_xml_data(meta, *tags) + + +def get_group_data(apiurl, group, *tags): + meta = get_group(apiurl, group) + return _get_xml_data(meta, *tags) + + def download(url, filename, progress_obj = None, mtime = None): import tempfile, shutil global BUFSIZE