From 86f82325d8696741a60d51cd3c4a9e219aac0fb7 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Thu, 8 Aug 2024 10:34:37 +0200 Subject: [PATCH] Stop importing/exporting scmsync packages/projects Also, allow other-than Factory projects --- git-importer.py | 5 ++++- lib/importer.py | 24 +++++++++++++++++++++++- lib/obs.py | 10 +++++----- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/git-importer.py b/git-importer.py index 7327e1c..f05f9e9 100755 --- a/git-importer.py +++ b/git-importer.py @@ -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__": diff --git a/lib/importer.py b/lib/importer.py index 6ec511f..e72ffab 100644 --- a/lib/importer.py +++ b/lib/importer.py @@ -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 + diff --git a/lib/obs.py b/lib/obs.py index 147b051..d36c56b 100644 --- a/lib/obs.py +++ b/lib/obs.py @@ -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