New approach for action #1658 - move does not need a from argument
This commit is contained in:
@@ -6,17 +6,39 @@ from osc.core import makeurl
|
||||
from osc.core import http_GET
|
||||
|
||||
|
||||
FACTORY = 'openSUSE:Factory'
|
||||
STG_PREFIX = 'openSUSE:Factory:Staging:'
|
||||
|
||||
|
||||
class RequestFinder:
|
||||
|
||||
@classmethod
|
||||
def find_request_id(self, request, apiurl):
|
||||
def __init__(self, apiurl):
|
||||
# Store the list of submit request together with the source project
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# {
|
||||
# 212454: {
|
||||
# 'project': 'openSUSE:Factory',
|
||||
# },
|
||||
#
|
||||
# 223870: {
|
||||
# 'project': 'openSUSE:Factory',
|
||||
# 'staging': 'openSUSE:Factory:Staging:A',
|
||||
# }
|
||||
# }
|
||||
#
|
||||
self.apiurl = apiurl
|
||||
self.srs = {}
|
||||
|
||||
def find_request_id(self, request):
|
||||
"""
|
||||
Look up the request by ID to verify if it is correct
|
||||
:param request: ID of the added request
|
||||
:param apiurl: OBS url
|
||||
"""
|
||||
|
||||
url = makeurl(apiurl, ['request', str(request)])
|
||||
url = makeurl(self.apiurl, ['request', str(request)])
|
||||
try:
|
||||
f = http_GET(url)
|
||||
except urllib2.HTTPError:
|
||||
@@ -28,72 +50,100 @@ class RequestFinder:
|
||||
return None
|
||||
|
||||
project = root.find('action').find('target').get('project')
|
||||
if project != 'openSUSE:Factory':
|
||||
raise oscerr.WrongArgs('Request {} is not for openSUSE:Factory, but for {}'.format(request, project))
|
||||
self.srids.add(int(request))
|
||||
if project != FACTORY and not project.startswith(STG_PREFIX):
|
||||
msg = 'Request {} is not for openSUSE:Factory, but for {}'
|
||||
msg = msg.format(request, project)
|
||||
raise oscerr.WrongArgs(msg)
|
||||
self.srs[int(request)] = {'project': project}
|
||||
|
||||
for review in root.findall('review'):
|
||||
if review.get('by_project'):
|
||||
self.srs[int(request)]['staging'] = review.get('by_project')
|
||||
break
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def find_request_package(self, package, apiurl):
|
||||
def find_request_package(self, package):
|
||||
"""
|
||||
Look up the package by its name and return the SR#
|
||||
:param package: name of the package
|
||||
:param apiurl: OBS url
|
||||
"""
|
||||
|
||||
url = makeurl(apiurl, ['request'], 'states=new,review,declined&project=openSUSE:Factory&view=collection&package={}'.format(package))
|
||||
query = 'states=new,review,declined&project=openSUSE:Factory&view=collection&package={}'
|
||||
query = query.format(package)
|
||||
url = makeurl(self.apiurl, ['request'], query)
|
||||
f = http_GET(url)
|
||||
|
||||
root = ET.parse(f).getroot()
|
||||
|
||||
ret = None
|
||||
for x in root.findall('request'):
|
||||
for sr in root.findall('request'):
|
||||
# TODO: check the package matches - OBS is case insensitive
|
||||
self.srids.add(int(x.get('id')))
|
||||
request = int(sr.get('id'))
|
||||
self.srs[request] = {'project': 'openSUSE:Factory'}
|
||||
for review in sr.findall('review'):
|
||||
if review.get('by_project'):
|
||||
self.srs[request]['staging'] = review.get('by_project')
|
||||
break
|
||||
if ret:
|
||||
raise oscerr.WrongArgs('There are multiple requests for package "{}": {}'.format(package, ', '.join(map(str, self.srids))))
|
||||
msg = 'There are multiple requests for package "{}": {}'
|
||||
msg = msg.format(package, ', '.join(map(str, self.srs.keys())))
|
||||
raise oscerr.WrongArgs(msg)
|
||||
ret = True
|
||||
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
def find_request_project(self, source_project, apiurl):
|
||||
|
||||
def find_request_project(self, source_project):
|
||||
"""
|
||||
Look up the source project by its name and return the SR#(s)
|
||||
:param source_project: name of the source project
|
||||
:param apiurl: OBS url
|
||||
"""
|
||||
|
||||
url = makeurl(apiurl, ['request'], 'states=new,review&project=openSUSE:Factory&view=collection')
|
||||
query = 'states=new,review&project=openSUSE:Factory&view=collection'
|
||||
url = makeurl(self.apiurl, ['request'], query)
|
||||
f = http_GET(url)
|
||||
root = ET.parse(f).getroot()
|
||||
|
||||
ret = None
|
||||
for rq in root.findall('request'):
|
||||
for a in rq.findall('action'):
|
||||
s = a.find('source')
|
||||
if s is not None and s.get('project') == source_project:
|
||||
self.srids.add(int(rq.attrib['id']))
|
||||
for sr in root.findall('request'):
|
||||
for act in sr.findall('action'):
|
||||
src = act.find('source')
|
||||
if src is not None and src.get('project') == source_project:
|
||||
request = int(sr.attrib['id'])
|
||||
self.srs[request] = {'project': 'openSUSE:Factory'}
|
||||
for review in sr.findall('review'):
|
||||
if review.get('by_project'):
|
||||
self.srs[request]['staging'] = review.get('by_project')
|
||||
break
|
||||
ret = True
|
||||
|
||||
return ret
|
||||
|
||||
def find(self, pkgs):
|
||||
"""
|
||||
Search for all various mutations and return list of SR#s
|
||||
:param pkgs: mesh of argumets to search for
|
||||
|
||||
This function is only called for its side effect.
|
||||
"""
|
||||
for p in pkgs:
|
||||
if self.find_request_package(p):
|
||||
continue
|
||||
if self.find_request_id(p):
|
||||
continue
|
||||
if self.find_request_project(p):
|
||||
continue
|
||||
raise oscerr.WrongArgs('No SR# found for: {}'.format(p))
|
||||
|
||||
@classmethod
|
||||
def find_sr(self, pkgs, apiurl):
|
||||
def find_sr(cls, pkgs, apiurl):
|
||||
"""
|
||||
Search for all various mutations and return list of SR#s
|
||||
:param pkgs: mesh of argumets to search for
|
||||
:param apiurl: OBS url
|
||||
"""
|
||||
|
||||
self.srids = set()
|
||||
for p in pkgs:
|
||||
if self.find_request_package(p, apiurl):
|
||||
continue
|
||||
if self.find_request_id(p, apiurl):
|
||||
continue
|
||||
if self.find_request_project(p, apiurl):
|
||||
continue
|
||||
raise oscerr.WrongArgs('No SR# found for: {0}'.format(p))
|
||||
|
||||
# this is needed in order to ensure we have one level list not nested one
|
||||
return sorted(list(self.srids))
|
||||
finder = cls(apiurl)
|
||||
finder.find(pkgs)
|
||||
return finder.srs
|
||||
|
Reference in New Issue
Block a user