check adi stagings and allow arguments to adi

This commit is contained in:
Stephan Kulow 2015-07-19 09:32:32 +02:00
parent 595e78ebbc
commit 78eec38b4f
3 changed files with 59 additions and 13 deletions

View File

@ -122,7 +122,9 @@ def do_staging(self, subcmd, opts, *args):
min_args = 2
elif cmd == 'unselect':
min_args, max_args = 1, None
elif cmd in ('adi', 'list', 'cleanup_rings'):
elif cmd == 'adi':
min_args, max_args = None, None
elif cmd in ('list', 'cleanup_rings'):
min_args, max_args = 0, 0
else:
raise oscerr.WrongArgs('Unknown command: %s' % cmd)
@ -170,4 +172,4 @@ def do_staging(self, subcmd, opts, *args):
elif cmd == 'list':
ListCommand(api).perform()
elif cmd == 'adi':
AdiCommand(api).perform()
AdiCommand(api).perform(args[1:])

View File

@ -1,25 +1,55 @@
import json
from osc import oscerr
from osc.core import delete_project
from osclib.select_command import SelectCommand
from osclib.request_finder import RequestFinder
class AdiCommand:
def __init__(self, api):
self.api = api
def perform(self):
"""
Perform the list command
"""
def check_adi_project(self, project):
query_project = 'adi:' + project.split(':adi:')[1]
query = {'format': 'json'}
url = self.api.makeurl(('project', 'staging_projects', self.api.project,
query_project), query=query)
info = json.load(self.api.retried_GET(url))
if len(info['building_repositories']):
print project, "still building"
return
if len(info['broken_packages']):
print "https://build.opensuse.org/project/show/{}".format(project), "has broken packages"
return
for review in info['missing_reviews']:
print project, "has at least one missing review by", review['by'], "in", review['request']
return
if len(info['untracked_requests']) or len(info['obsolete_requests']):
print project, "has inconsistent requests"
return
print project, "is ready"
for req in info['selected_requests']:
print req['id']
self.api.rm_from_prj(project, request_id=req['id'], msg='ready to accept')
delete_project(self.api.apiurl, project)
# Print out the left overs
requests = self.api.get_open_requests()
def check_adi_projects(self):
for p in self.api.get_adi_projects():
self.check_adi_project(p)
def create_new_adi(self, wanted_requests):
all_requests = self.api.get_open_requests()
non_ring_packages = []
non_ring_requests = []
for request in requests:
for request in all_requests:
# Consolidate all data from request
request_id = int(request.get('id'))
if len(wanted_requests) and request_id not in wanted_requests:
continue
action = request.findall('action')
if not action:
msg = 'Request {} has no action'.format(request_id)
@ -47,3 +77,18 @@ class AdiCommand:
# Notify everybody about the changes
self.api.update_status_comments(name, 'select')
def perform(self, packages):
"""
Perform the list command
"""
if len(packages):
requests = set()
for request, request_project in RequestFinder.find_sr(packages,
self.api).items():
requests.add(request)
self.create_new_adi(requests)
else:
self.create_new_adi(())
#self.check_adi_projects()

View File

@ -259,7 +259,7 @@ class StagingAPI(object):
"""
projects = [p for p in self.get_staging_projects() if self.is_adi_project(p) ]
return projects
return sorted(projects, key=lambda project: self.extract_adi_number(project))
def do_change_review_state(self, request_id, newstate, message=None,
by_group=None, by_user=None, by_project=None):
@ -1098,8 +1098,7 @@ class StagingAPI(object):
def _candidate_adi_project(self):
"""Decide a candidate name for an ADI project."""
adi_projects = sorted(self.get_adi_projects(),
key=lambda project: self.extract_adi_number(project))
adi_projects = self.get_adi_projects()
adi_index = 1
for i, project in enumerate(adi_projects):
adi_index = i + 1