1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +01:00

- do_request(): added "--involved-projects" option to show all requests for project/packages where USER is involved

- code restructuring:
  * added new get_user_projpkgs_request_list() method
  * added new get_user_projpkgs() method
This commit is contained in:
Marcus Huewe 2010-03-13 21:06:18 +01:00
parent 4dfaad4795
commit 88474d392d
2 changed files with 79 additions and 47 deletions

View File

@ -1043,6 +1043,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
help='interactive review of request')
@cmdln.option('--exclude-target-project', action='append',
help='exclude target project from request list')
@cmdln.option('--involved-projects', action='store_true',
help='show all requests for project/packages where USER is involved in')
@cmdln.alias("rq")
@cmdln.alias("review")
def do_request(self, subcmd, opts, *args):
@ -1181,8 +1183,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if (self.options.debug):
print 'list: option --bugowner ignored: not impl.'
results = get_request_list(apiurl, project, package, who,
state_list, opts.type, opts.exclude_target_project or [])
if opts.involved_projects:
who = who or conf.get_apiurl_usr(apiurl)
results = get_user_projpkgs_request_list(apiurl, who, req_state=state_list,
req_type=opts.type, exclude_projects=opts.exclude_target_project or [])
else:
results = get_request_list(apiurl, project, package, who,
state_list, opts.type, opts.exclude_target_project or [])
results.sort(reverse=True)
import time
days = opts.days or conf.config['request_list_days']
@ -3912,35 +3919,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if opts.all:
role_filter = ''
xpath = 'person/@userid = \'%s\'' % user
excl_prj = ''
excl_pkg = ''
for i in exclude_projects:
excl_prj = xpath_join(excl_prj, 'not(@name = \'%s\')' % i, op='and')
excl_pkg = xpath_join(excl_pkg, 'not(@project = \'%s\')' % i, op='and')
role_filter_xpath = xpath
if role_filter:
xpath = xpath_join(xpath, 'person/@role = \'%s\'' % role_filter, inner=True, op='and')
xpath_pkg = xpath_join(xpath, excl_pkg, op='and')
xpath_prj = xpath_join(xpath, excl_prj, op='and')
if what.has_key('package'):
what['package'] = xpath_pkg
if what.has_key('project'):
what['project'] = xpath_prj
try:
res = search(conf.config['apiurl'], **what)
except urllib2.HTTPError, e:
if e.code != 400 or not role_filter:
raise e
# backward compatibility: local role filtering
what = dict([[kind, role_filter_xpath] for kind in what.keys()])
if what.has_key('package'):
what['package'] = xpath_join(role_filter_xpath, excl_pkg, op='and')
if what.has_key('project'):
what['project'] = xpath_join(role_filter_xpath, excl_prj, op='and')
res = search(conf.config['apiurl'], **what)
filter_role(res, user, role_filter)
res = get_user_projpkgs(conf.config['apiurl'], user, role_filter,
exclude_projects, what.has_key('project'), what.has_key('package'))
request_todo = {}
roles = {}
if len(what.keys()) == 2:
@ -3952,26 +3932,12 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if not i.get('project') in request_todo.keys():
request_todo.setdefault(i.get('project'), []).append(i.get('name'))
else:
request_todo = dict([[i.get('name'), []] for i in res['project'].findall('project')])
for i in res['project'].findall('project'):
roles[i.get('name')] = [p.get('role') for p in i.findall('person') if p.get('userid') == user]
if list_requests:
xpath = ''
for prj, pacs in request_todo.iteritems():
if not len(pacs):
xpath = xpath_join(xpath, 'action/target/@project=\'%s\'' % prj, inner=True)
else:
xp = ''
for p in pacs:
xp = xpath_join(xp, 'action/target/@package=\'%s\'' % p, inner=True)
xp = xpath_join(xp, 'action/target/@project=\'%s\'' % prj, op='and')
xpath = xpath_join(xpath, xp, inner=True)
xpath = xpath_join(xpath, 'state/@name = \'new\'', op='and')
res = search(conf.config['apiurl'], request=xpath)
for root in res['request'].findall('request'):
r = Request()
r.read(root)
requests = get_user_projpkgs_request_list(conf.config['apiurl'], user, projpkgs=request_todo)
for r in requests:
print r.list_view()
else:
for i in sorted(roles.keys()):

View File

@ -2628,6 +2628,39 @@ def get_request_list(apiurl, project='', package='', req_who='', req_state=('new
requests.append(r)
return requests
def get_user_projpkgs_request_list(apiurl, user, req_state=('new',), req_type=None, exclude_projects=[], projpkgs={}):
"""Return all new requests for all projects/packages where is user is involved"""
if not projpkgs:
res = get_user_projpkgs(apiurl, user, exclude_projects=exclude_projects)
for i in res['project'].findall('project'):
projpkgs[i.get('name')] = []
for i in res['package'].findall('package'):
if not i.get('project') in projpkgs.keys():
projpkgs.setdefault(i.get('project'), []).append(i.get('name'))
xpath = ''
for prj, pacs in projpkgs.iteritems():
if not len(pacs):
xpath = xpath_join(xpath, 'action/target/@project=\'%s\'' % prj, inner=True)
else:
xp = ''
for p in pacs:
xp = xpath_join(xp, 'action/target/@package=\'%s\'' % p, inner=True)
xp = xpath_join(xp, 'action/target/@project=\'%s\'' % prj, op='and')
xpath = xpath_join(xpath, xp, inner=True)
if req_type:
xpath = xpath_join(xpath, 'action/@type=\'%s\'' % req_type, op='and')
if not 'all' in req_state:
xp = ''
for state in req_state:
xp = xpath_join(xp, 'state/@name=\'%s\'' % state)
xpath = xpath_join(xpath, '(%s)' % xp, op='and')
res = search(apiurl, request=xpath)
result = []
for root in res['request'].findall('request'):
r = Request()
r.read(root)
result.append(r)
return result
def get_request_log(apiurl, reqid):
r = get_request(conf.config['apiurl'], reqid)
@ -4635,6 +4668,39 @@ def request_interactive_review(apiurl, request):
if tmpfile is not None:
tmpfile.close()
def get_user_projpkgs(apiurl, user, role=None, exclude_projects=[], proj=True, pkg=True):
"""Return all project/packages where user is involved."""
xpath = 'person/@userid = \'%s\'' % user
excl_prj = ''
excl_pkg = ''
for i in exclude_projects:
excl_prj = xpath_join(excl_prj, 'not(@name = \'%s\')' % i, op='and')
excl_pkg = xpath_join(excl_pkg, 'not(@project = \'%s\')' % i, op='and')
role_filter_xpath = xpath
if role:
xpath = xpath_join(xpath, 'person/@role = \'%s\'' % role, inner=True, op='and')
xpath_pkg = xpath_join(xpath, excl_pkg, op='and')
xpath_prj = xpath_join(xpath, excl_prj, op='and')
what = {}
if pkg:
what['package'] = xpath_pkg
if proj:
what['project'] = xpath_prj
try:
res = search(apiurl, **what)
except urllib2.HTTPError, e:
if e.code != 400 or not role_filter:
raise e
# backward compatibility: local role filtering
what = dict([[kind, role_filter_xpath] for kind in what.keys()])
if what.has_key('package'):
what['package'] = xpath_join(role_filter_xpath, excl_pkg, op='and')
if what.has_key('project'):
what['project'] = xpath_join(role_filter_xpath, excl_prj, op='and')
res = search(apiurl, **what)
filter_role(res, user, role)
return res
# backward compatibility: local role filtering
def filter_role(meta, user, role):
"""