diff --git a/osc/commandline.py b/osc/commandline.py index 2dfb7acc..307a9f47 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -1835,23 +1835,31 @@ class Osc(cmdln.Cmdln): help='show email addresses instead of user names') @cmdln.option('-v', '--verbose', action='store_true', help='show more information') + @cmdln.option('-a', '--add', metavar='user', + help='add a new maintainer') + @cmdln.option('-d', '--delete', metavar='user', + help='delete a maintainer from a project or package') def do_maintainer(self, subcmd, opts, *args): """${cmd_name}: Show maintainers of a project/package To be used like this: - osc maintainer PRJ + osc maintainer PRJ or - osc maintainer PRJ PKG + osc maintainer PRJ PKG ${cmd_usage} ${cmd_option_list} """ + pac = None if len(args) == 1: m = show_project_meta(conf.config['apiurl'], args[0]) + prj = args[0] elif len(args) == 2: m = show_package_meta(conf.config['apiurl'], args[0], args[1]) + prj = args[0] + pac = args[1] else: sys.exit('wrong argument count') @@ -1877,6 +1885,10 @@ class Osc(cmdln.Cmdln): userdata.append(itm) for row in build_table(3, userdata, ['realname', 'userid', 'email\n']): print row + elif opts.add: + addMaintainer(conf.config['apiurl'], prj, pac, opts.add) + elif opts.delete: + delMaintainer(conf.config['apiurl'], prj, pac, opts.delete) else: print ', '.join(maintainers) diff --git a/osc/core.py b/osc/core.py index a1a9ce49..0a046889 100755 --- a/osc/core.py +++ b/osc/core.py @@ -2129,3 +2129,61 @@ def delete_server_files(apiurl, prj, pac, files): # see bug #280034 print >>sys.stderr, 'error while deleting file \'%s\'' % file sys.exit(1) + +def addMaintainer(apiurl, prj, pac, user): + """ add a new maintainer to a package or project """ + path = quote_plus(prj), + kind = 'prj' + if pac: + path = path + (quote_plus(pac),) + kind = 'pkg' + data = meta_exists(metatype=kind, + path_args=path, + template_args=None, + create_new=False) + + if data and get_user_meta(apiurl, user) != None: + tree = ET.fromstring(''.join(data)) + found = False + for person in tree.getiterator('person'): + if person.get('userid') == user: + found = True + print "user already exists" + break + if not found: + # the xml has a fixed structure + tree.insert(2, ET.Element('person', role='maintainer', userid=user)) + print 'user \'%s\' added to \'%s\'' % (user, pac or prj) + edit_meta(metatype=kind, + path_args=path, + data=ET.tostring(tree)) + else: + print "osc: an error occured" + +def delMaintainer(apiurl, prj, pac, user): + """ delete a maintainer from a package or project """ + path = quote_plus(prj), + kind = 'prj' + if pac: + path = path + (quote_plus(pac), ) + kind = 'pkg' + data = meta_exists(metatype=kind, + path_args=path, + template_args=None, + create_new=False) + if data: + tree = ET.fromstring(''.join(data)) + found = False + for person in tree.getiterator('person'): + if person.get('userid') == user: + tree.remove(person) + found = True + print "user \'%s\' removed" % user + if found: + edit_meta(metatype=kind, + path_args=path, + data=ET.tostring(tree)) + else: + print "user \'%s\' not found in \'%s\'" % (user, pac or prj) + else: + print "an error occured"