Reuse function of accept to check local links

This commit is contained in:
Stephan Kulow 2019-11-24 20:02:58 +01:00
parent 886dc106eb
commit 2bfc87088d
2 changed files with 17 additions and 3 deletions

View File

@ -66,7 +66,7 @@ def _full_project_name(self, project):
def lock_needed(cmd, opts): def lock_needed(cmd, opts):
return not( return not(
cmd in ('check', 'check_duplicate_binaries', 'frozenage', 'rebuild', 'unlock') or cmd in ('check', 'check_duplicate_binaries', 'check_local_links', 'frozenage', 'rebuild', 'unlock') or
(cmd == 'list' and not opts.supersede) (cmd == 'list' and not opts.supersede)
) )
@ -137,6 +137,8 @@ def do_staging(self, subcmd, opts, *args):
"check" will check if all packages are links without changes "check" will check if all packages are links without changes
"check_local_links" lists local links that don't match multispec package
"check_duplicate_binaries" list binaries provided by multiple packages "check_duplicate_binaries" list binaries provided by multiple packages
"cleanup_rings" will try to cleanup rings content and print "cleanup_rings" will try to cleanup rings content and print
@ -297,6 +299,7 @@ def do_staging(self, subcmd, opts, *args):
osc staging adi [--move] [--by-develproject] [--split] [REQUEST...] osc staging adi [--move] [--by-develproject] [--split] [REQUEST...]
osc staging check [STAGING...] osc staging check [STAGING...]
osc staging check_duplicate_binaries osc staging check_duplicate_binaries
osc staging check_local_links
osc staging cleanup_rings osc staging cleanup_rings
osc staging freeze [--no-bootstrap] STAGING... osc staging freeze [--no-bootstrap] STAGING...
osc staging frozenage [STAGING...] osc staging frozenage [STAGING...]
@ -346,6 +349,7 @@ def do_staging(self, subcmd, opts, *args):
min_args, max_args = 1, None min_args, max_args = 1, None
elif cmd in ( elif cmd in (
'check_duplicate_binaries', 'check_duplicate_binaries',
'check_local_links',
'cleanup_rings', 'cleanup_rings',
'list', 'list',
'lock', 'lock',
@ -405,6 +409,8 @@ def do_staging(self, subcmd, opts, *args):
print() print()
elif cmd == 'check_duplicate_binaries': elif cmd == 'check_duplicate_binaries':
CheckDuplicateBinariesCommand(api).perform(opts.save) CheckDuplicateBinariesCommand(api).perform(opts.save)
elif cmd == 'check_local_links':
AcceptCommand(api).check_local_links()
elif cmd == 'freeze': elif cmd == 'freeze':
for prj in args[1:]: for prj in args[1:]:
prj = api.prj_from_short(prj) prj = api.prj_from_short(prj)

View File

@ -8,7 +8,7 @@ from xml.etree import cElementTree as ET
from osc.core import change_request_state, show_package_meta, wipebinaries from osc.core import change_request_state, show_package_meta, wipebinaries
from osc.core import http_GET, http_PUT, http_DELETE, http_POST from osc.core import http_GET, http_PUT, http_DELETE, http_POST
from osc.core import delete_package, search from osc.core import delete_package, search, meta_get_packagelist
from osc.core import Request from osc.core import Request
from osc.util.helper import decode_it from osc.util.helper import decode_it
from osclib.core import attribute_value_save from osclib.core import attribute_value_save
@ -146,7 +146,11 @@ class AcceptCommand(object):
return return
def fix_linking_packages(self, package): def check_local_links(self):
for package in meta_get_packagelist(self.api.apiurl, self.api.project):
self.fix_linking_packages(package, True)
def fix_linking_packages(self, package, dry=False):
project = self.api.project project = self.api.project
file_list = self.api.get_filelist_for_package(package, project) file_list = self.api.get_filelist_for_package(package, project)
# ignore # ignore
@ -164,6 +168,8 @@ class AcceptCommand(object):
# Deleting all the packages that no longer have a .spec file # Deleting all the packages that no longer have a .spec file
for link in local_links - needed_links: for link in local_links - needed_links:
print(f"Deleting package {project}/{link}") print(f"Deleting package {project}/{link}")
if dry:
continue
try: try:
delete_package(self.api.apiurl, project, link, msg=f"No longer linking to {package}") delete_package(self.api.apiurl, project, link, msg=f"No longer linking to {package}")
except HTTPError as err: except HTTPError as err:
@ -182,6 +188,8 @@ class AcceptCommand(object):
# There is more than one .spec file in the package; link package containers as needed # There is more than one .spec file in the package; link package containers as needed
meta = ET.fromstring(source_file_load(self.api.apiurl, project, package, '_meta')) meta = ET.fromstring(source_file_load(self.api.apiurl, project, package, '_meta'))
print(f"Creating new link {link}->{package}") print(f"Creating new link {link}->{package}")
if dry:
continue
meta.attrib['name'] = link meta.attrib['name'] = link
bcnt = meta.find('bcntsynctag') bcnt = meta.find('bcntsynctag')