Stop importing/exporting scmsync packages/projects

Also, allow other-than Factory projects
This commit is contained in:
Adam Majer 2024-08-08 10:34:37 +02:00
parent 39ba616226
commit 86f82325d8
3 changed files with 32 additions and 7 deletions

View File

@ -119,7 +119,10 @@ def main():
importer = Importer(URL_OBS, args.project, args.packages)
importer.import_into_db()
for package in args.packages:
export_package(args.project, package, args.repodir, args.cachedir, args.gc)
if not importer.package_with_scmsync(package):
export_package(args.project, package, args.repodir, args.cachedir, args.gc)
else:
logging.debug(f"{args.project}/{package} has scmsync links - skipping export")
if __name__ == "__main__":

View File

@ -26,13 +26,16 @@ class Importer:
# Import multiple Factory packages into the database
self.packages = packages
self.project = project
self.scmsync_cache = dict()
self.packages_with_scmsync = set()
self.db = DB()
self.obs = OBS(api_url)
assert project == "openSUSE:Factory"
assert not self.has_scmsync(project)
self.refreshed_packages = set()
self.gone_packages_set = None
def import_request(self, number):
self.obs.request(number).import_into_db(self.db)
@ -213,6 +216,10 @@ class Importer:
return
logging.debug(f"Refresh {project}/{package}")
self.refreshed_packages.add(key)
if self.has_scmsync(project) or self.has_scmsync(key):
self.packages_with_scmsync.add(package)
logging.debug(f"{project}/{package} already in Git - skipping")
return
self.update_db_package(project, package)
self.fetch_all_linked_packages(project, package)
@ -255,3 +262,18 @@ class Importer:
for line in f.readlines():
self.gone_packages_set.add(line.strip())
return key in self.gone_packages_set
def has_scmsync(self, key):
if key in self.scmsync_cache:
return self.scmsync_cache[key]
root = self.obs._meta(key)
scmsync_exists = False
if root is not None:
scmsync_exists = root.find('scmsync') is not None
self.scmsync_cache[key] = scmsync_exists
return scmsync_exists
def package_with_scmsync(self, package):
return package in self.packages_with_scmsync

View File

@ -73,11 +73,11 @@ class OBS:
logging.debug(f"GET {url}")
return ET.parse(osc.core.http_GET(url)).getroot()
def _meta(self, project, package, **params):
def _meta(self, key, **params):
try:
root = self._xml(f"source/{project}/{package}/_meta", **params)
root = self._xml(f"source/{key}/_meta", **params)
except HTTPError:
logging.error(f"Package [{project}/{package} {params}] has no meta")
logging.error(f"Project/Package [{key} {params}] has no meta")
return None
return root
@ -118,13 +118,13 @@ class OBS:
return root
def exists(self, project, package):
root = self._meta(project, package)
root = self._meta(f"{project}/{package}")
if root is None:
return False
return root.get("project") == project
def devel_project(self, project, package):
root = self._meta(project, package)
root = self._meta(f"{project}/{package}")
devel = root.find("devel")
if devel is None:
return None