2014-02-28 11:45:06 +01:00
|
|
|
from osc.core import change_request_state
|
2014-05-20 12:26:29 +02:00
|
|
|
from osc.core import get_request
|
2014-06-01 19:51:18 +02:00
|
|
|
from osc.core import http_GET
|
2014-05-20 12:26:29 +02:00
|
|
|
|
|
|
|
from osclib.comments import CommentAPI
|
2014-02-28 11:45:06 +01:00
|
|
|
|
2014-06-01 19:51:18 +02:00
|
|
|
from xml.etree import cElementTree as ET
|
2014-02-19 11:48:16 +01:00
|
|
|
|
2014-03-06 18:22:19 +01:00
|
|
|
class AcceptCommand(object):
|
2014-02-19 11:48:16 +01:00
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
2014-05-20 12:26:29 +02:00
|
|
|
self.comment = CommentAPI(self.api.apiurl)
|
2014-02-19 11:48:16 +01:00
|
|
|
|
2014-06-01 19:51:18 +02:00
|
|
|
def find_new_requests(self, project):
|
|
|
|
requests = []
|
|
|
|
|
|
|
|
query = "match=state/@name='new'+and+(action/target/@project='{}'+and+action/@type='submit')".format(project)
|
|
|
|
url = self.api.makeurl(['search', 'request'], query)
|
|
|
|
|
|
|
|
f = http_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
|
|
|
|
ids=[]
|
|
|
|
for rq in root.findall('request'):
|
|
|
|
ids.append(int(rq.get('id')))
|
|
|
|
return ids
|
|
|
|
|
2014-03-05 15:49:48 +01:00
|
|
|
def perform(self, project):
|
2014-02-26 14:51:01 +01:00
|
|
|
"""
|
|
|
|
Accept the staging LETTER for review and submit to factory
|
|
|
|
Then disable the build to disabled
|
|
|
|
:param project: staging project we are working with
|
|
|
|
"""
|
2014-06-01 19:51:18 +02:00
|
|
|
|
2014-02-19 11:48:16 +01:00
|
|
|
status = self.api.check_project_status(project)
|
|
|
|
|
|
|
|
if not status:
|
2014-02-26 14:51:01 +01:00
|
|
|
print('The project "{0}" is not yet acceptable.'.format(project))
|
2014-02-19 11:48:16 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
meta = self.api.get_prj_pseudometa(project)
|
|
|
|
requests = []
|
|
|
|
for req in meta['requests']:
|
|
|
|
self.api.rm_from_prj(project, request_id=req['id'], msg='ready to accept')
|
2014-05-20 12:26:29 +02:00
|
|
|
msg = 'Accepting staging review for {0}'.format(req['package'])
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
# Write a comment in the project.
|
|
|
|
user = get_request(self.api.apiurl, str(req['id'])).get_creator()
|
2014-05-20 15:08:21 +02:00
|
|
|
self.comment.add_comment(project_name=project, comment='[at]%s: %s' % (user, msg))
|
2014-05-20 12:26:29 +02:00
|
|
|
|
2014-02-19 11:48:16 +01:00
|
|
|
requests.append(req['id'])
|
|
|
|
|
|
|
|
for req in requests:
|
2014-03-05 15:49:48 +01:00
|
|
|
change_request_state(self.api.apiurl, str(req), 'accepted', message='Accept to factory')
|
2014-02-19 11:48:16 +01:00
|
|
|
|
2014-05-20 12:26:29 +02:00
|
|
|
# XXX CAUTION - AFAIK the 'accept' command is expected to clean the messages here.
|
|
|
|
self.comment.delete_from(project_name=project)
|
|
|
|
|
2014-02-19 11:48:16 +01:00
|
|
|
self.api.build_switch_prj(project, 'disable')
|
2014-05-27 18:32:51 +02:00
|
|
|
if self.api.project_exists(project + ":DVD"):
|
|
|
|
self.api.build_switch_prj(project + ":DVD", 'disable')
|
|
|
|
|
2014-06-01 19:51:18 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
def accept_other_new(self):
|
|
|
|
for req in self.find_new_requests('openSUSE:Factory'):
|
|
|
|
change_request_state(self.api.apiurl, str(req), 'accepted', message='Accept to factory')
|
|
|
|
|
|
|
|
return True
|