Move pending_requests and get_request.

This commit is contained in:
Alberto Planas 2014-06-04 14:12:37 +02:00
parent 6ff892fdf2
commit 209dc8f961
2 changed files with 33 additions and 18 deletions

View File

@ -522,9 +522,10 @@ def _check_repo_group(self, id_, reqs, opts):
fetched[p.request] = True fetched[p.request] = True
packs.append(p) packs.append(p)
for req, f in fetched.items(): for request_id, f in fetched.items():
if not f: if not f:
packs.extend(self._check_repo_fetch_request(req, opts)) request = self.checkrepo.get_request(request_id)
packs.extend(self._check_repo_one_request(request, opts))
for p in packs: for p in packs:
if fetched[p.request]: if fetched[p.request]:
continue continue
@ -654,12 +655,6 @@ def _check_repo_group(self, id_, reqs, opts):
shutil.rmtree(destdir) shutil.rmtree(destdir)
def _check_repo_fetch_request(self, id_, opts):
url = makeurl(opts.apiurl, ['request', str(id_)])
root = ET.parse(http_GET(url)).getroot()
return self._check_repo_one_request(root, opts)
@cmdln.alias('check', 'cr') @cmdln.alias('check', 'cr')
@cmdln.option('-s', '--skip', action='store_true', help='skip review') @cmdln.option('-s', '--skip', action='store_true', help='skip review')
def do_check_repo(self, subcmd, opts, *args): def do_check_repo(self, subcmd, opts, *args):
@ -696,18 +691,14 @@ def do_check_repo(self, subcmd, opts, *args):
packs = [] packs = []
if not ids: if not ids:
# xpath query, using the -m, -r, -s options # Return a list, we flat here with .extend()
where = "@by_user='factory-repo-checker'+and+@state='new'" for request in self.checkrepo.pending_requests():
url = makeurl(opts.apiurl, ['search', 'request'], packs.extend(self._check_repo_one_request(request, opts))
"match=state/@name='review'+and+review[%s]" % where)
f = http_GET(url)
root = ET.parse(f).getroot()
for rq in root.findall('request'):
packs.extend(self._check_repo_one_request(rq, opts))
else: else:
# we have a list, use them. # we have a list, use them.
for id_ in ids: for request_id in ids:
packs.extend(self._check_repo_fetch_request(id_, opts)) request = self.checkrepo.get_request(request_id)
packs.extend(self._check_repo_one_request(request, opts))
# Order the packs before grouping # Order the packs before grouping
packs = sorted(packs, key=lambda p: p.request, reverse=True) packs = sorted(packs, key=lambda p: p.request, reverse=True)

View File

@ -17,6 +17,7 @@
import urllib2 import urllib2
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
from osc.core import http_GET
from osc.core import http_POST from osc.core import http_POST
from osc.core import makeurl from osc.core import makeurl
@ -73,3 +74,26 @@ class CheckRepo(object):
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
print('ERROR in URL %s [%s]' % (url, e)) print('ERROR in URL %s [%s]' % (url, e))
return code return code
def get_request(self, request_id):
"""Get a request XML onject."""
request = None
try:
url = makeurl(self.apiurl, ('request', str(request_id)))
request = ET.parse(http_GET(url)).getroot()
except urllib2.HTTPError, e:
print('ERROR in URL %s [%s]' % (url, e))
return request
def pending_requests(self):
"""Search pending requests to review."""
requests = []
where = "@by_user='factory-repo-checker'+and+@state='new'"
try:
url = makeurl(self.apiurl, ('search', 'request'),
"match=state/@name='review'+and+review[%s]" % where)
root = ET.parse(http_GET(url)).getroot()
requests = root.findall('request')
except urllib2.HTTPError, e:
print('ERROR in URL %s [%s]' % (url, e))
return requests