2017-11-01 18:27:14 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from xml.etree import cElementTree as ET
|
|
|
|
|
2019-05-09 15:49:01 +08:00
|
|
|
try:
|
|
|
|
from urllib.error import HTTPError
|
|
|
|
except ImportError:
|
|
|
|
from urllib2 import HTTPError
|
|
|
|
|
2017-11-01 18:27:14 +08:00
|
|
|
import osc.core
|
|
|
|
import osc.conf
|
|
|
|
|
|
|
|
from osc import cmdln
|
|
|
|
from osc import oscerr
|
|
|
|
|
|
|
|
def _has_binary(self, project, package):
|
|
|
|
query = {'view': 'binarylist', 'package': package, 'multibuild': '1'}
|
|
|
|
pkg_binarylist = ET.parse(osc.core.http_GET(osc.core.makeurl(self.apiurl, ['build', project, '_result'], query=query))).getroot()
|
|
|
|
for binary in pkg_binarylist.findall('./result/binarylist/binary'):
|
|
|
|
return 'Yes'
|
|
|
|
return 'No'
|
|
|
|
|
|
|
|
|
|
|
|
def list_virtually_accepted_request(self, project, opts):
|
2019-05-09 15:49:01 +08:00
|
|
|
state_cond = "state/@name='review'+or+state/@name='revoked'"
|
2017-11-01 18:27:14 +08:00
|
|
|
if opts.all:
|
|
|
|
state_cond += "+or+state/@name='accepted'"
|
|
|
|
query = "match=({})+and+(action/target/@project='{}'+and+action/@type='delete')+and+"\
|
|
|
|
"((review/@state='new'+or+review/@state='accepted')+and+review/@by_group='{}')".format(state_cond, project, opts.delreq_review)
|
|
|
|
url = osc.core.makeurl(self.apiurl, ['search', 'request'], query)
|
|
|
|
f = osc.core.http_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
rqs = []
|
|
|
|
for rq in root.findall('request'):
|
|
|
|
has_binary = 'No'
|
|
|
|
id = rq.attrib['id']
|
|
|
|
rq_state = rq.find('state').get('name')
|
|
|
|
pkg = rq.find('action/target').get('package')
|
2019-05-09 15:49:01 +08:00
|
|
|
try:
|
|
|
|
osc.core.show_package_meta(self.apiurl, project, pkg)
|
|
|
|
except HTTPError as err:
|
|
|
|
if err.code == 404:
|
|
|
|
continue
|
|
|
|
raise err
|
|
|
|
|
2017-11-01 18:27:14 +08:00
|
|
|
if rq_state != 'accepted':
|
|
|
|
has_binary = self._has_binary(project, pkg)
|
|
|
|
for review in rq.findall('review'):
|
|
|
|
if review.get('by_group') and review.attrib['by_group'] == opts.delreq_review:
|
|
|
|
delreq_review_state = review.attrib['state']
|
|
|
|
|
|
|
|
content = {"id": int(id), "package": pkg, "rq_state": rq_state, "delreq_review_state": delreq_review_state, "has_binary": has_binary}
|
|
|
|
rqs.append(content)
|
|
|
|
|
|
|
|
rqs.sort(key=lambda d: d['id'])
|
|
|
|
for rq in rqs:
|
|
|
|
print("{} {} state is {} \n {} Virtually accept review is {} ( binary: {} )".format(str(rq['id']),
|
|
|
|
rq['package'], rq['rq_state'], "-".rjust(len(str(rq['id']))+1, ' '), rq['delreq_review_state'], rq['has_binary']))
|
|
|
|
|
|
|
|
@cmdln.option('--delreq-review', dest='delreq_review', metavar='DELREQREVIEW', default='factory-maintainers',
|
|
|
|
help='the additional reviews')
|
|
|
|
@cmdln.option('--all', action='store_true', default=False, help='shows all requests including accepted request')
|
|
|
|
def do_vdelreq(self, subcmd, opts, *args):
|
|
|
|
"""${cmd_name}: display pending virtual accept delete request
|
|
|
|
|
|
|
|
osc vdelreq [OPT] COMMAND PROJECT
|
|
|
|
Shows pending the virtual accept delete requests and the current state.
|
|
|
|
|
|
|
|
${cmd_option_list}
|
|
|
|
|
|
|
|
"list" will list virtually accepted delete request.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
osc vdelreq [--delreq-review DELREQREVIEW] list PROJECT
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.apiurl = self.get_api_url()
|
|
|
|
|
|
|
|
if len(args) == 0:
|
|
|
|
raise oscerr.WrongArgs('No command given, see "osc help vdelreq"!')
|
|
|
|
if len(args) < 2:
|
|
|
|
raise oscerr.WrongArgs('No project given, see "osc help vdelreq"!')
|
|
|
|
|
|
|
|
cmd = args[0]
|
|
|
|
if cmd in ('list'):
|
|
|
|
self.list_virtually_accepted_request(args[1], opts)
|
|
|
|
else:
|
|
|
|
raise oscerr.WrongArgs('Unknown command: %s' % cmd)
|
|
|
|
|