From c226327ae5250ee6eb8b4fa8cf2c854918f11353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Tue, 11 Jan 2011 20:02:48 +0100 Subject: [PATCH] add option to request the additon of a group to a project or package and rename add_role to add_user to make the difference obvious. --- NEWS | 1 + osc/commandline.py | 35 ++++++++++++++++++++++++++++++++--- osc/core.py | 9 +++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 012bfa31..1630fdc9 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ - add blt and rblt commands, aka "buildlogtail" and "remotebuildlogtail" to show just the end of a build log (for getting the fail reason faster). CHANGE: the --start parameter is now called --offset + - add "createrequest -a add_group" option to create a group request - add "createrequest -a add_me" shortcut 0.130 diff --git a/osc/commandline.py b/osc/commandline.py index 5ccdbed2..423fd3e8 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -1264,7 +1264,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. return actionxml - def _add_role(self, args, opts): + def _add_user(self, args, opts): if len(args) > 4: raise oscerr.WrongArgs('Too many arguments.') if len(args) < 3: @@ -1288,6 +1288,30 @@ Please submit there instead, or use --nodevelproject to force direct submission. return actionxml + def _add_group(self, args, opts): + if len(args) > 4: + raise oscerr.WrongArgs('Too many arguments.') + if len(args) < 3: + raise oscerr.WrongArgs('Too few arguments.') + + apiurl = self.get_api_url() + + group = args[0] + role = args[1] + project = args[2] + actionxml = """ """ % \ + (project, group, role) + + if len(args) > 3: + package = args[3] + actionxml = """ """ % \ + (project, package, group, role) + + if get_group(apiurl, group) == None: + raise oscerr.WrongArgs('osc: an error occured.') + + return actionxml + def _set_bugowner(self, args, opts): if len(args) > 3: raise oscerr.WrongArgs('Too many arguments.') @@ -1340,6 +1364,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. -a delete PROJECT [PACKAGE] -a change_devel PROJECT PACKAGE DEVEL_PROJECT [DEVEL_PACKAGE] -a add_me ROLE PROJECT [PACKAGE] + -a add_group GROUP ROLE PROJECT [PACKAGE] -a add_role USER ROLE PROJECT [PACKAGE] -a set_bugowner USER PROJECT [PACKAGE] ] @@ -1387,9 +1412,13 @@ Please submit there instead, or use --nodevelproject to force direct submission. args = opts.actiondata[i] actionsxml += self._add_me(args,opts) i = i+1 + elif ai == 'add_group': + args = opts.actiondata[i] + actionsxml += self._add_group(args,opts) + i = i+1 elif ai == 'add_role': args = opts.actiondata[i] - actionsxml += self._add_role(args,opts) + actionsxml += self._add_user(args,opts) i = i+1 elif ai == 'set_bugowner': args = opts.actiondata[i] @@ -1459,7 +1488,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. arg = [ user, opts.role, project, package ] - actionsxml = self._add_role(arg, None) + actionsxml = self._add_user(arg, None) if not opts.message: opts.message = edit_message() diff --git a/osc/core.py b/osc/core.py index 81329202..e714e13b 100644 --- a/osc/core.py +++ b/osc/core.py @@ -3655,6 +3655,15 @@ def get_request_log(apiurl, reqid): return data +def get_group(apiurl, group): + u = makeurl(apiurl, ['group', quote_plus(group)]) + try: + f = http_GET(u) + return ''.join(f.readlines()) + except urllib2.HTTPError: + print 'user \'%s\' not found' % group + return None + def get_user_meta(apiurl, user): u = makeurl(apiurl, ['person', quote_plus(user)]) try: