From 843380bd98027158a2ea166bfec480f97c79b0ae Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Thu, 29 Jun 2023 00:58:14 -0700 Subject: [PATCH] importer fixes, remove submodules, cleanup util importer/operation.py: Added a skip_lookaside option to pkg_import(). This will remove the source files outright and not attempt to move them. Removed models and peridotpb. These will be something outside of this core module. util/generic.py: reordered __all__ util/rpmutil.py: ordered __all__ and added metadata logic to NEVRA splitter. --- importer/operation.py | 23 +++++++++++++++++++++-- models/__init__.py | 5 ----- peridotpb/__init__.py | 5 ----- util/generic.py | 8 ++++---- util/rpmutil.py | 26 ++++++++++++++++---------- 5 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 models/__init__.py delete mode 100644 peridotpb/__init__.py diff --git a/importer/operation.py b/importer/operation.py index 28a4086..a28cf49 100644 --- a/importer/operation.py +++ b/importer/operation.py @@ -116,6 +116,17 @@ class Import: if os.path.exists('/usr/sbin/restorecon'): processor.run_proc_foreground_shell(f'/usr/sbin/restorecon {dest_path}') + @staticmethod + def skip_import_lookaside(repo_path: str, file_dict: dict): + """ + Removes all files that are supposed to go to the lookaside. This is for + cases where you may have sources in another location, you just want the + metadata filled out appropriately. + """ + for name, _ in file_dict.items(): + source_path = f'{repo_path}/{name}' + os.remove(source_path) + class SrpmImport(Import): """ Import class for importing rpms to a git service @@ -170,9 +181,12 @@ class SrpmImport(Import): return None - def pkg_import(self): + def pkg_import(self, skip_lookaside: bool = False): """ Actually perform the import + + If skip_lookaside is True, source files will just be deleted rather + than uploaded to lookaside. """ check_repo = gitutil.lsremote(self.git_url) git_repo_path = f'/var/tmp/{self.rpm_name}' @@ -234,7 +248,12 @@ class SrpmImport(Import): sources = self.get_dict_of_lookaside_files(git_repo_path) self.generate_metadata(git_repo_path, self.rpm_name, sources) self.generate_filesum(git_repo_path, self.rpm_name, self.srpm_hash) - self.import_lookaside(git_repo_path, self.rpm_name, branch, sources) + + if skip_lookaside: + self.skip_import_lookaside(git_repo_path, sources) + else: + self.import_lookaside(git_repo_path, self.rpm_name, branch, sources) + gitutil.add_all(repo) verify = repo.is_dirty() diff --git a/models/__init__.py b/models/__init__.py deleted file mode 100644 index a83b60f..0000000 --- a/models/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*-:python; coding:utf-8; -*- -# author: Louis Abel -""" -Useful models. These may not be used and may be put elsewhere. -""" diff --git a/peridotpb/__init__.py b/peridotpb/__init__.py deleted file mode 100644 index fd7e7d6..0000000 --- a/peridotpb/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*-:python; coding:utf-8; -*- -# author: Louis Abel -""" -The peridotpb part of everything I suppose. -""" diff --git a/util/generic.py b/util/generic.py index ecccf16..a65d1d3 100644 --- a/util/generic.py +++ b/util/generic.py @@ -8,13 +8,13 @@ from pv2.util import error as err # General utilities __all__ = [ - 'ordered', 'conv_multibyte', - 'to_unicode', 'convert_from_unix_time', - 'trim_non_empty_string', 'gen_bool_option', - 'generate_password_hash' + 'generate_password_hash', + 'ordered', + 'to_unicode', + 'trim_non_empty_string' ] def to_unicode(string: str) -> str: diff --git a/util/rpmutil.py b/util/rpmutil.py index 5598de7..b9d5555 100644 --- a/util/rpmutil.py +++ b/util/rpmutil.py @@ -19,18 +19,18 @@ except ImportError: rpm = None __all__ = [ - 'is_debug_package', + 'add_rpm_key', + 'compare_rpms', + 'get_all_rpm_header_keys', + 'get_exclu_from_package', + 'get_files_from_package', + 'get_rpm_hdr_size', 'get_rpm_header', 'get_rpm_metadata_from_hdr', - 'compare_rpms', + 'is_debug_package', 'is_rpm', - 'get_files_from_package', - 'get_exclu_from_package', - 'get_rpm_hdr_size', 'split_rpm_by_header', - 'get_all_rpm_header_keys', - 'verify_rpm_signature', - 'add_rpm_key' + 'verify_rpm_signature' ] # NOTES TO THOSE RUNNING PYLINT OR ANOTHER TOOL @@ -336,13 +336,19 @@ def split_rpm_by_header(hdr) -> tuple: Note: Splitting a source package will result in an erroneous "arch" field. """ - # pylint: disable=no-member + source_files = hdr[rpm.RPMTAG_SOURCE] + source_pkg = hdr[rpm.RPMTAG_SOURCERPM] + pkg_arch = generic.to_unicode(hdr[rpm.RPMTAG_ARCH]) + + if len(source_files) != 0 or not source_pkg: + pkg_arch = 'src' + name = hdr[rpm.RPMTAG_NAME] version = hdr[rpm.RPMTAG_VERSION] release = hdr[rpm.RPMTAG_RELEASE] epoch = hdr[rpm.RPMTAG_EPOCH] - arch = hdr[rpm.RPMTAG_ARCH] + arch = pkg_arch if not epoch: epoch = ''