mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-25 03:32:15 +01:00
added a bit more functionality to do_maintainers. It is possible to add and delete users from a project/package
This commit is contained in:
parent
bd9ae2fd05
commit
69b7e3bfc7
@ -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 <options>
|
||||
or
|
||||
osc maintainer PRJ PKG
|
||||
osc maintainer PRJ PKG <options>
|
||||
|
||||
${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)
|
||||
|
||||
|
58
osc/core.py
58
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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user