add adi command to create an ad interim staging prj for all non-ring packages

This commit is contained in:
Stephan Kulow 2015-07-16 15:09:26 +02:00
parent 50aeb49eb8
commit 5de87f84e4
4 changed files with 72 additions and 9 deletions

View File

@ -35,6 +35,7 @@ from osclib.obslock import OBSLock
from osclib.select_command import SelectCommand
from osclib.stagingapi import StagingAPI
from osclib.unselect_command import UnselectCommand
from osclib.adi_command import AdiCommand
OSC_STAGING_VERSION = '0.0.1'
@ -121,7 +122,7 @@ def do_staging(self, subcmd, opts, *args):
min_args = 2
elif cmd == 'unselect':
min_args, max_args = 1, None
elif cmd in ('list', 'cleanup_rings'):
elif cmd in ('adi', 'list', 'cleanup_rings'):
min_args, max_args = 0, 0
else:
raise oscerr.WrongArgs('Unknown command: %s' % cmd)
@ -162,9 +163,11 @@ def do_staging(self, subcmd, opts, *args):
if opts.add:
api.mark_additional_packages(tprj, [opts.add])
else:
SelectCommand(api).perform(tprj, args[2:], opts.move,
SelectCommand(api, tprj).perform(args[2:], opts.move,
opts.from_, opts.no_freeze)
elif cmd == 'cleanup_rings':
CleanupRings(api).perform()
elif cmd == 'list':
ListCommand(api).perform()
elif cmd == 'adi':
AdiCommand(api).perform()

49
osclib/adi_command.py Normal file
View File

@ -0,0 +1,49 @@
from osc import oscerr
from osclib.select_command import SelectCommand
class AdiCommand:
def __init__(self, api):
self.api = api
def perform(self):
"""
Perform the list command
"""
# Print out the left overs
requests = self.api.get_open_requests()
non_ring_packages = []
non_ring_requests = []
for request in requests:
# Consolidate all data from request
request_id = int(request.get('id'))
action = request.findall('action')
if not action:
msg = 'Request {} has no action'.format(request_id)
raise oscerr.WrongArgs(msg)
# we care only about first action
action = action[0]
# Where are we targeting the package
target_package = action.find('target').get('package')
if not self.api.ring_packages.get(target_package):
non_ring_packages.append(target_package)
non_ring_requests.append(request_id)
if len(non_ring_packages):
print "Not in a ring:", ' '.join(sorted(non_ring_packages))
name = self.api.create_adi_project(None)
sc = SelectCommand(self.api, name)
for request in non_ring_requests:
if not self.api.rq_to_prj(request, name):
return False
# Notify everybody about the changes
self.api.update_status_comments(name, 'select')

View File

@ -14,9 +14,10 @@ MOVE = 'move'
class SelectCommand(object):
def __init__(self, api):
def __init__(self, api, target_project):
self.api = api
self.affected_projects = set()
self.target_project = target_project
def _package(self, request):
"""
@ -118,7 +119,6 @@ class SelectCommand(object):
print('Freeze the prj first')
return False
# FreezeCommand(self.api).perform(target_project)
self.target_project = target_project
for request in RequestFinder.find_sr(requests, self.api):
if not self.select_request(request, move, from_):

View File

@ -245,13 +245,16 @@ class StagingAPI(object):
projects.append(val.get('name'))
return projects
def is_adi_project(self, p):
return ':adi:' in p
def get_adi_projects(self):
"""
Get all current running ADI projects
:return list of known ADI projects
"""
projects = [p for p in self.get_staging_project() if ':adi:' in p]
projects = [p for p in self.get_staging_projects() if self.is_adi_project(p) ]
return projects
def do_change_review_state(self, request_id, newstate, message=None,
@ -744,7 +747,7 @@ class StagingAPI(object):
# The force_enable_build will avoid the
# map_ring_package_to_subproject
if not force_enable_build:
if self.crings and not self.ring_packages.get(tar_pkg):
if self.crings and not self.ring_packages.get(tar_pkg) and not self.is_adi_project(project):
disable_build = True
else:
project = self.map_ring_package_to_subject(project, tar_pkg)
@ -1092,9 +1095,13 @@ class StagingAPI(object):
def _candidate_adi_project(self):
"""Decide a candidate name for an ADI project."""
adi_projects = sorted(self.get_adi_projects())
adi_index = 1
for i, project in enumerate(adi_projects):
if not project.endswith(i):
return self.adi_prj_from_number(i)
adi_index = i + 1
if not project.endswith(str(adi_index)):
return self.adi_prj_from_number(adi_index)
adi_index = i + 2
return self.adi_prj_from_number(adi_index)
def create_adi_project(self, name):
"""Create an ADI project."""
@ -1122,5 +1129,9 @@ class StagingAPI(object):
<arch>x86_64</arch>
</repository>
</project>""".format(name, self.project)
url = ""
url = make_meta_url('prj', name, self.apiurl)
http_PUT(url, data=meta)
# put twice because on first put, the API adds useless maintainer
http_PUT(url, data=meta)
return name