def delete_linked(self): for package in self.requests['delete']: for link in self.api.linked_packages(package): if link['project'] in self.api.rings or link['project'] == self.api.project: print(f"delete {link['project']}/{link['package']}") delete_package(self.api.apiurl, link['project'], link['package'], msg="remove link while accepting delete of {}".format(package))
def create_new_links(self, project, pkgname, oldspeclist): filelist = self.api.get_filelist_for_package(pkgname=pkgname, project=project, extension='spec') removedspecs = set(oldspeclist) - set(filelist) for spec in removedspecs: # Deleting all the packages that no longer have a .spec file url = self.api.makeurl(['source', project, spec[:-5]]) print("Deleting package %s from project %s" % (spec[:-5], project)) try: http_DELETE(url) except HTTPError as err: if err.code == 404: # the package link was not yet created, which was likely a mistake from earlier pass else: # If the package was there bug could not be delete, raise the error raise # Remove package from Rings in case 2nd specfile was removed if self.api.ring_packages.get(spec[:-5]): delete_package(self.api.apiurl, self.api.ring_packages.get(spec[:-5]), spec[:-5], force=True, msg="Cleanup package in Rings") if len(filelist) > 1: # There is more than one .spec file in the package; link package containers as needed origmeta = source_file_load(self.api.apiurl, project, pkgname, '_meta') for specfile in filelist: package = specfile[: -5] # stripping .spec off the filename gives the packagename if package == pkgname: # This is the original package and does not need to be linked to itself continue # Check if the target package already exists, if it does not, we get a HTTP error 404 to catch if not self.api.item_exists(project, package): print("Creating new package %s linked to %s" % (package, pkgname)) # new package does not exist. Let's link it with new metadata newmeta = re.sub(r'(<package.*name=.){}'.format(pkgname), r'\1{}'.format(package), origmeta) newmeta = re.sub(r'<devel.*>', r'<devel package="{}"/>'.format(pkgname), newmeta) newmeta = re.sub(r'<bcntsynctag>.*</bcntsynctag>', r'', newmeta) newmeta = re.sub( r'</package>', r'<bcntsynctag>{}</bcntsynctag></package>'.format( pkgname), newmeta) source_file_save(self.api.apiurl, project, package, '_meta', newmeta) link = "<link package=\"{}\" cicount=\"copy\" />".format( pkgname) source_file_save(self.api.apiurl, project, package, '_link', link) return True
def rm_from_prj(self, project, package=None, request_id=None, msg=None, review='accepted'): """ Delete request from the project :param project: project to remove from :param request_id: request we want to remove :param msg: message for the log :param review: review state for the review, defautl accepted """ if not request_id: request_id = self.get_request_id_for_package(project, package) if not package: package = self.get_package_for_request_id(project, request_id) if not package or not request_id: return self._remove_package_from_prj_pseudometa(project, package) subprj = self.map_ring_package_to_subject(project, package) delete_package(self.apiurl, subprj, package, force=True, msg=msg) for sub_prj, sub_pkg in self.get_sub_packages(package): sub_prj = self.map_ring_package_to_subject(project, sub_pkg) if sub_prj != subprj: # if different to the main package's prj delete_package(self.apiurl, sub_prj, sub_pkg, force=True, msg=msg) self.set_review(request_id, project, state=review, msg=msg)
def virtually_accept_delete(self, request_id, package): self.api.add_review( request_id, by_group=self.api.cdelreq_review, msg='Request accepted. Cleanup in progress - DO NOT REVOKE!') filelist = self.api.get_filelist_for_package(pkgname=package, project=self.api.project, expand='1', extension='spec') pkgs = self.api.extract_specfile_short(filelist) # Disable build and wipes the binary to the package and the sub-package for pkg in pkgs: meta = show_package_meta(self.api.apiurl, self.api.project, pkg) meta = ''.join(meta) # Update package meta to disable build self.api.create_package_container(self.api.project, pkg, meta=meta, disable_build=True) wipebinaries(self.api.apiurl, self.api.project, package=pkg, repo=self.api.cmain_repo) # Remove package from Rings if self.api.ring_packages.get(pkg): delete_package(self.api.apiurl, self.api.ring_packages.get(pkg), pkg, force=True, msg="Cleanup package in Rings")
def cleanup(self, project): if not self.api.item_exists(project): return False pkglist = self.api.list_packages(project) clean_list = set(pkglist) - set(self.api.cstaging_nocleanup) for package in clean_list: print "[cleanup] deleted %s/%s" % (project, package) delete_package(self.api.apiurl, project, package, force=True, msg="autocleanup") # wipe Test-DVD binaries and breaks kiwi build if project.startswith('openSUSE:'): for package in pkglist: if package.startswith('Test-DVD-'): # intend to break the kiwi file arch = package.split('-')[-1] fakepkgname = 'I-am-breaks-kiwi-build' oldkiwifile = self.api.load_file_content(project, package, 'PRODUCT-'+arch+'.kiwi') if oldkiwifile is not None: newkiwifile = re.sub(r'<repopackage name="openSUSE-release"/>', '<repopackage name="%s"/>' % fakepkgname, oldkiwifile) self.api.save_file_content(project, package, 'PRODUCT-' + arch + '.kiwi', newkiwifile) # do wipe binary now query = { 'cmd': 'wipe' } query['package'] = package query['repository'] = 'images' url = self.api.makeurl(['build', project], query) try: http_POST(url) except urllib2.HTTPError, err: # failed to wipe isos but we can just continue pass
def fix_linking_packages(self, package, dry=False): project = self.api.project file_list = self.api.get_filelist_for_package(package, project) # ignore linked packages if '_link' in file_list: return needed_links = set() # if there's a multibuild we assume all flavors are built # using multibuild. So any potential previous links have to # be removed ie set of needed_links left empty. if '_multibuild' not in file_list: for file in file_list: if file.endswith('.spec') and file != f'{package}.spec': needed_links.add(file[:-5]) local_links = set() for link in self.api.linked_packages(package): if link['project'] == project: local_links.add(link['package']) # Deleting all the packages that no longer have a .spec file for link in local_links - needed_links: print(f"Deleting package {project}/{link}") if dry: continue try: delete_package(self.api.apiurl, project, link, msg=f"No longer linking to {package}") except HTTPError as err: if err.code == 404: # the package link was not yet created, which was likely a mistake from earlier pass else: # If the package was there bug could not be delete, raise the error raise # Remove package from Rings in case 2nd specfile was removed if self.api.ring_packages.get(link): delete_package(self.api.apiurl, self.api.ring_packages.get(link), link, force=True, msg="Cleanup package in Rings") for link in needed_links - local_links: # 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')) print(f"Creating new link {link}->{package}") if dry: continue meta.attrib['name'] = link bcnt = meta.find('bcntsynctag') if bcnt is None: bcnt = ET.SubElement(meta, 'bcntsynctag') bcnt.text = package devel = meta.find('devel') if devel is None: devel = ET.SubElement(meta, 'devel') devel.attrib['project'] = project devel.attrib['package'] = package source_file_save(self.api.apiurl, project, link, '_meta', ET.tostring(meta)) xml = f"<link package='{package}' cicount='copy' />" source_file_save(self.api.apiurl, project, link, '_link', xml)
def cleanup(self, project): if not self.api.item_exists(project): return False pkglist = self.api.list_packages(project) clean_list = set(pkglist) - set(self.api.cstaging_nocleanup) for package in clean_list: print "[cleanup] deleted %s/%s" % (project, package) delete_package(self.api.apiurl, project, package, force=True, msg="autocleanup") return True
def deletePackage(self, project, package): """ deletePackage(project, package) Delete the specific package in project """ try: core.delete_package(self.apiurl, project, package) except Exception: return False return True
def cleanup(self, project): if not self.api.item_exists(project): return pkglist = self.api.list_packages(project) clean_list = set(pkglist) - set(self.api.cnocleanup_packages) for package in clean_list: print("[cleanup] deleted %s/%s" % (project, package)) delete_package(self.api.apiurl, project, package, force=True, msg="autocleanup") return
def create_new_links(self, project, pkgname, oldspeclist): filelist = self.api.get_filelist_for_package(pkgname=pkgname, project=project, extension='spec') removedspecs = set(oldspeclist) - set(filelist) for spec in removedspecs: # Deleting all the packages that no longer have a .spec file url = self.api.makeurl(['source', project, spec[:-5]]) print("Deleting package %s from project %s" % (spec[:-5], project)) try: http_DELETE(url) except HTTPError as err: if err.code == 404: # the package link was not yet created, which was likely a mistake from earlier pass else: # If the package was there bug could not be delete, raise the error raise # Remove package from Rings in case 2nd specfile was removed if self.api.ring_packages.get(spec[:-5]): delete_package(self.api.apiurl, self.api.ring_packages.get(spec[:-5]), spec[:-5], force=True, msg="Cleanup package in Rings") if len(filelist) > 1: # There is more than one .spec file in the package; link package containers as needed origmeta = source_file_load(self.api.apiurl, project, pkgname, '_meta') for specfile in filelist: package = specfile[:-5] # stripping .spec off the filename gives the packagename if package == pkgname: # This is the original package and does not need to be linked to itself continue # Check if the target package already exists, if it does not, we get a HTTP error 404 to catch if not self.api.item_exists(project, package): print("Creating new package %s linked to %s" % (package, pkgname)) # new package does not exist. Let's link it with new metadata newmeta = re.sub(r'(<package.*name=.){}'.format(pkgname), r'\1{}'.format(package), origmeta) newmeta = re.sub(r'<devel.*>', r'<devel package="{}"/>'.format(pkgname), newmeta) newmeta = re.sub(r'<bcntsynctag>.*</bcntsynctag>', r'', newmeta) newmeta = re.sub(r'</package>', r'<bcntsynctag>{}</bcntsynctag></package>'.format(pkgname), newmeta) source_file_save(self.api.apiurl, project, package, '_meta', newmeta) link = "<link package=\"{}\" cicount=\"copy\" />".format(pkgname) source_file_save(self.api.apiurl, project, package, '_link', link) return True
def virtually_accept_delete(self, request_id, package): self.api.add_review(request_id, by_group=self.api.cdelreq_review, msg='Request accepted. Cleanup in progress - DO NOT REVOKE!') filelist = self.api.get_filelist_for_package(pkgname=package, project=self.api.project, expand='1', extension='spec') pkgs = self.api.extract_specfile_short(filelist) # Disable build and wipes the binary to the package and the sub-package for pkg in pkgs: meta = decode_it(b''.join(show_package_meta(self.api.apiurl, self.api.project, pkg))) # Update package meta to disable build self.api.create_package_container(self.api.project, pkg, meta=meta, disable_build=True) wipebinaries(self.api.apiurl, self.api.project, package=pkg, repo=self.api.cmain_repo) # Remove package from Rings if self.api.ring_packages.get(pkg): delete_package(self.api.apiurl, self.api.ring_packages.get(pkg), pkg, force=True, msg="Cleanup package in Rings")
def cleanup(self, project): if not self.api.item_exists(project): return False pkglist = self.api.list_packages(project) clean_list = set(pkglist) - set(self.api.cnocleanup_packages) for package in clean_list: print("[cleanup] deleted %s/%s" % (project, package)) delete_package(self.api.apiurl, project, package, force=True, msg="autocleanup") # wipe Test-DVD binaries and breaks kiwi build if project.startswith('openSUSE:'): for package in pkglist: if package.startswith('Test-DVD-'): # intend to break the kiwi file arch = package.split('-')[-1] fakepkgname = 'I-am-breaks-kiwi-build' oldkiwifile = source_file_load(self.api.apiurl, project, package, 'PRODUCT-' + arch + '.kiwi') if oldkiwifile is not None: newkiwifile = re.sub( r'<repopackage name="openSUSE-release"/>', '<repopackage name="%s"/>' % fakepkgname, oldkiwifile) source_file_save(self.api.apiurl, project, package, 'PRODUCT-' + arch + '.kiwi', newkiwifile) # do wipe binary now query = {'cmd': 'wipe'} query['package'] = package query['repository'] = 'images' url = self.api.makeurl(['build', project], query) try: http_POST(url) except HTTPError as err: # failed to wipe isos but we can just continue pass return True