2015-07-19 09:32:32 +02:00
|
|
|
import json
|
2019-10-09 13:40:59 +02:00
|
|
|
from urllib.error import HTTPError
|
2015-07-16 15:09:26 +02:00
|
|
|
|
2017-04-21 17:09:17 -05:00
|
|
|
from colorama import Fore
|
|
|
|
|
2015-07-19 09:32:32 +02:00
|
|
|
from osc import oscerr
|
2019-10-09 13:40:59 +02:00
|
|
|
from osc.core import get_request
|
2015-07-19 09:32:32 +02:00
|
|
|
from osc.core import delete_project
|
2015-08-27 18:42:39 +08:00
|
|
|
from osc.core import show_package_meta
|
2017-06-23 21:19:46 +08:00
|
|
|
from osc import conf
|
2016-12-29 16:27:11 -06:00
|
|
|
|
2015-07-16 15:09:26 +02:00
|
|
|
from osclib.select_command import SelectCommand
|
2017-04-26 22:27:18 -05:00
|
|
|
from osclib.supersede_command import SupersedeCommand
|
2015-07-19 09:32:32 +02:00
|
|
|
from osclib.request_finder import RequestFinder
|
2017-01-13 01:16:05 -06:00
|
|
|
from osclib.request_splitter import RequestSplitter
|
2015-08-27 18:42:39 +08:00
|
|
|
from xml.etree import cElementTree as ET
|
2015-07-16 15:09:26 +02:00
|
|
|
|
|
|
|
class AdiCommand:
|
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
2017-06-23 21:19:46 +08:00
|
|
|
self.config = conf.config[self.api.project]
|
2015-07-16 15:09:26 +02:00
|
|
|
|
2015-07-19 09:32:32 +02:00
|
|
|
def check_adi_project(self, project):
|
2017-03-16 14:44:24 -05:00
|
|
|
query_project = self.api.extract_staging_short(project)
|
2019-11-08 11:31:23 +01:00
|
|
|
info = self.api.project_status(project, reload=True)
|
2019-03-07 20:03:06 +01:00
|
|
|
|
2019-11-08 11:31:23 +01:00
|
|
|
if info.find('staged_requests/request') is not None:
|
2019-11-08 14:49:39 +01:00
|
|
|
if info.find('building_repositories/repo') is not None:
|
2019-03-07 20:03:06 +01:00
|
|
|
print(query_project + ' ' + Fore.MAGENTA + 'building')
|
2017-09-26 17:06:25 +08:00
|
|
|
return
|
2019-11-08 11:31:23 +01:00
|
|
|
if info.find('untracked_requests/request') is not None:
|
2019-03-07 20:03:06 +01:00
|
|
|
print(query_project + ' ' + Fore.YELLOW + 'untracked: ' + ', '.join(['{}[{}]'.format(
|
2019-11-19 19:38:54 +08:00
|
|
|
Fore.CYAN + req.get('package') + Fore.RESET, req.get('id')) for req in info.findall('untracked_requests/request')]))
|
2017-09-26 17:06:25 +08:00
|
|
|
return
|
2019-11-08 11:31:23 +01:00
|
|
|
if info.find('obsolete_requests/request') is not None:
|
2019-03-07 20:03:06 +01:00
|
|
|
print(query_project + ' ' + Fore.YELLOW + 'obsolete: ' + ', '.join(['{}[{}]'.format(
|
2019-11-19 19:38:54 +08:00
|
|
|
Fore.CYAN + req.get('package') + Fore.RESET, req.get('id')) for req in info.findall('obsolete_requests/request')]))
|
2017-09-26 17:06:25 +08:00
|
|
|
return
|
2019-11-08 11:31:23 +01:00
|
|
|
if info.find('broken_packages/package') is not None:
|
2019-03-07 20:03:06 +01:00
|
|
|
print(query_project + ' ' + Fore.RED + 'broken: ' + ', '.join([
|
2019-11-08 11:31:23 +01:00
|
|
|
Fore.CYAN + p.get('package') + Fore.RESET for p in info.findall('broken_packages/package')]))
|
2017-09-26 17:06:25 +08:00
|
|
|
return
|
2019-11-08 11:31:23 +01:00
|
|
|
for review in info.findall('missing_reviews/review'):
|
2019-03-07 20:03:06 +01:00
|
|
|
print(query_project + ' ' + Fore.WHITE + 'review: ' + '{} for {}[{}]'.format(
|
2019-11-19 15:33:09 +01:00
|
|
|
Fore.YELLOW + self.api.format_review(review) + Fore.RESET,
|
2019-11-08 11:31:23 +01:00
|
|
|
Fore.CYAN + review.get('package') + Fore.RESET,
|
2019-11-19 15:33:09 +01:00
|
|
|
review.get('request')))
|
2017-09-26 17:06:25 +08:00
|
|
|
return
|
2019-11-08 11:31:23 +01:00
|
|
|
for check in info.findall('missing_checks/check'):
|
|
|
|
print(query_project + ' ' + Fore.MAGENTA + 'missing: {}'.format(check.get('name')))
|
2019-03-07 20:03:06 +01:00
|
|
|
return
|
2019-11-08 11:31:23 +01:00
|
|
|
for check in info.findall('checks/check'):
|
|
|
|
state = check.find('state').text
|
|
|
|
if state != 'success':
|
2019-11-08 14:49:39 +01:00
|
|
|
print(query_project + '{} {} check: {}'.format(Fore.MAGENTA, state, check.get('name')))
|
2019-03-07 20:03:06 +01:00
|
|
|
return
|
2017-10-17 09:10:17 +02:00
|
|
|
|
2019-11-08 11:31:23 +01:00
|
|
|
overall_state = info.get('state')
|
|
|
|
if overall_state != 'acceptable' and overall_state != 'empty':
|
|
|
|
raise oscerr.WrongArgs('Missed some case')
|
|
|
|
|
2017-08-24 12:00:52 +02:00
|
|
|
if self.api.is_user_member_of(self.api.user, self.api.cstaging_group):
|
2019-03-07 20:03:06 +01:00
|
|
|
print(query_project + ' ' + Fore.GREEN + 'ready')
|
2017-03-28 23:02:38 -05:00
|
|
|
packages = []
|
2019-11-08 11:31:23 +01:00
|
|
|
for req in info.findall('staged_requests/request'):
|
|
|
|
msg = 'ready to accept'
|
|
|
|
print(' - {} [{}]'.format(Fore.CYAN + req.get('package') + Fore.RESET, req.get('id')))
|
|
|
|
self.api.rm_from_prj(project, request_id=req.get('id'), msg=msg)
|
|
|
|
self.api.do_change_review_state(req.get('id'), 'accepted', by_group=self.api.cstaging_group, message=msg)
|
|
|
|
packages.append(req.get('package'))
|
2017-03-28 23:02:38 -05:00
|
|
|
self.api.accept_status_comment(project, packages)
|
2017-07-07 16:04:38 +02:00
|
|
|
try:
|
2017-09-20 08:05:17 -05:00
|
|
|
delete_project(self.api.apiurl, project, force=True)
|
2018-04-26 13:28:25 +02:00
|
|
|
except HTTPError as e:
|
2017-10-16 22:47:58 +02:00
|
|
|
print(e)
|
2017-07-07 16:04:38 +02:00
|
|
|
pass
|
2016-12-29 16:27:11 -06:00
|
|
|
else:
|
2019-11-27 11:08:06 +01:00
|
|
|
ready = []
|
2019-11-08 11:31:23 +01:00
|
|
|
for req in info.findall('staged_requests/request'):
|
|
|
|
ready.append('{}[{}]'.format(Fore.CYAN + req.get('package') + Fore.RESET, req.get('id')))
|
|
|
|
if len(ready):
|
|
|
|
print(query_project, Fore.GREEN + 'ready:', ', '.join(ready))
|
2016-12-29 16:27:11 -06:00
|
|
|
|
2015-07-19 09:32:32 +02:00
|
|
|
def check_adi_projects(self):
|
|
|
|
for p in self.api.get_adi_projects():
|
|
|
|
self.check_adi_project(p)
|
2015-07-16 15:09:26 +02:00
|
|
|
|
2016-05-30 19:21:14 +08:00
|
|
|
def create_new_adi(self, wanted_requests, by_dp=False, split=False):
|
2017-06-23 21:19:46 +08:00
|
|
|
source_projects_expand = self.config.get('source_projects_expand', '').split()
|
2019-10-09 13:40:59 +02:00
|
|
|
# if we don't call it, there is no invalidate function added
|
2017-01-13 01:16:05 -06:00
|
|
|
requests = self.api.get_open_requests()
|
2019-10-09 13:40:59 +02:00
|
|
|
if len(wanted_requests):
|
|
|
|
requests = []
|
|
|
|
rf = RequestFinder(self.api)
|
|
|
|
for p in wanted_requests:
|
|
|
|
requests.append(rf.load_request(p))
|
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
splitter = RequestSplitter(self.api, requests, in_ring=False)
|
|
|
|
splitter.filter_add('./action[@type="submit"]')
|
|
|
|
if len(wanted_requests):
|
2017-02-10 10:05:38 -06:00
|
|
|
splitter.filter_add_requests([str(p) for p in wanted_requests])
|
2017-01-13 01:16:05 -06:00
|
|
|
# wanted_requests forces all requests into a single group.
|
|
|
|
else:
|
|
|
|
if split:
|
|
|
|
splitter.group_by('./@id')
|
|
|
|
elif by_dp:
|
2017-01-31 18:36:54 -06:00
|
|
|
splitter.group_by('./action/target/@devel_project')
|
2015-07-28 13:01:30 +02:00
|
|
|
else:
|
2017-01-13 01:16:05 -06:00
|
|
|
splitter.group_by('./action/source/@project')
|
2018-01-30 21:50:05 +08:00
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
splitter.split()
|
2015-07-28 13:01:30 +02:00
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
for group in sorted(splitter.grouped.keys()):
|
2017-04-21 17:09:17 -05:00
|
|
|
print(Fore.YELLOW + (group if group != '' else 'wanted') + Fore.RESET)
|
2015-09-09 15:26:05 +08:00
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
name = None
|
|
|
|
for request in splitter.grouped[group]['requests']:
|
|
|
|
request_id = int(request.get('id'))
|
2018-01-30 21:50:05 +08:00
|
|
|
target = request.find('./action/target')
|
|
|
|
target_package = target.get('package')
|
2017-04-26 10:27:56 -05:00
|
|
|
line = '- {} {}{:<30}{}'.format(request_id, Fore.CYAN, target_package, Fore.RESET)
|
2015-07-16 15:09:26 +02:00
|
|
|
|
2017-04-28 10:18:14 -05:00
|
|
|
message = self.api.ignore_format(request_id)
|
|
|
|
if message:
|
|
|
|
print(line + '\n' + Fore.WHITE + message + Fore.RESET)
|
2015-11-19 20:23:10 +08:00
|
|
|
continue
|
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
# Auto-superseding request in adi command
|
2017-04-26 22:27:18 -05:00
|
|
|
stage_info, code = self.api.update_superseded_request(request)
|
|
|
|
if stage_info:
|
2017-04-26 21:10:52 -05:00
|
|
|
print(line + ' ({})'.format(SupersedeCommand.CODE_MAP[code]))
|
2017-01-10 01:27:40 -06:00
|
|
|
continue
|
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
# Only create staging projec the first time a non superseded
|
|
|
|
# request is processed from a particular group.
|
|
|
|
if name is None:
|
2017-06-23 21:19:46 +08:00
|
|
|
use_frozenlinks = group in source_projects_expand and not split
|
2019-11-21 13:42:19 +01:00
|
|
|
name = self.api.create_adi_project(None, use_frozenlinks, group)
|
2015-07-16 15:09:26 +02:00
|
|
|
|
2017-01-13 01:16:05 -06:00
|
|
|
if not self.api.rq_to_prj(request_id, name):
|
2015-07-28 11:16:52 +02:00
|
|
|
return False
|
2015-07-19 09:32:32 +02:00
|
|
|
|
2017-04-21 17:09:17 -05:00
|
|
|
print(line + Fore.GREEN + ' (staged in {})'.format(name) + Fore.RESET)
|
2017-02-13 17:53:09 +08:00
|
|
|
|
2016-05-30 19:21:14 +08:00
|
|
|
def perform(self, packages, move=False, by_dp=False, split=False):
|
2015-07-19 09:32:32 +02:00
|
|
|
"""
|
|
|
|
Perform the list command
|
|
|
|
"""
|
|
|
|
if len(packages):
|
|
|
|
requests = set()
|
2015-08-25 07:12:08 +02:00
|
|
|
if move:
|
|
|
|
items = RequestFinder.find_staged_sr(packages, self.api).items()
|
2018-04-26 13:28:25 +02:00
|
|
|
print(items)
|
2015-08-25 07:12:08 +02:00
|
|
|
for request, request_project in items:
|
|
|
|
staging_project = request_project['staging']
|
|
|
|
self.api.rm_from_prj(staging_project, request_id=request)
|
|
|
|
self.api.add_review(request, by_group=self.api.cstaging_group, msg='Please recheck')
|
|
|
|
else:
|
|
|
|
items = RequestFinder.find_sr(packages, self.api).items()
|
|
|
|
|
|
|
|
for request, request_project in items:
|
2015-07-19 09:32:32 +02:00
|
|
|
requests.add(request)
|
2016-05-30 19:21:14 +08:00
|
|
|
self.create_new_adi(requests, split=split)
|
2015-07-19 09:32:32 +02:00
|
|
|
else:
|
2017-10-17 09:10:17 +02:00
|
|
|
self.check_adi_projects()
|
2017-08-24 12:00:52 +02:00
|
|
|
if self.api.is_user_member_of(self.api.user, self.api.cstaging_group):
|
2016-05-30 19:40:56 +08:00
|
|
|
self.create_new_adi((), by_dp=by_dp, split=split)
|