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.
This commit is contained in:
Louis Abel 2023-06-29 00:58:14 -07:00
parent 60e197c9e1
commit 843380bd98
Signed by: label
GPG Key ID: 3331F061D1D9990E
5 changed files with 41 additions and 26 deletions

View File

@ -116,6 +116,17 @@ class Import:
if os.path.exists('/usr/sbin/restorecon'): if os.path.exists('/usr/sbin/restorecon'):
processor.run_proc_foreground_shell(f'/usr/sbin/restorecon {dest_path}') 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): class SrpmImport(Import):
""" """
Import class for importing rpms to a git service Import class for importing rpms to a git service
@ -170,9 +181,12 @@ class SrpmImport(Import):
return None return None
def pkg_import(self): def pkg_import(self, skip_lookaside: bool = False):
""" """
Actually perform the import 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) check_repo = gitutil.lsremote(self.git_url)
git_repo_path = f'/var/tmp/{self.rpm_name}' 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) sources = self.get_dict_of_lookaside_files(git_repo_path)
self.generate_metadata(git_repo_path, self.rpm_name, sources) self.generate_metadata(git_repo_path, self.rpm_name, sources)
self.generate_filesum(git_repo_path, self.rpm_name, self.srpm_hash) self.generate_filesum(git_repo_path, self.rpm_name, self.srpm_hash)
if skip_lookaside:
self.skip_import_lookaside(git_repo_path, sources)
else:
self.import_lookaside(git_repo_path, self.rpm_name, branch, sources) self.import_lookaside(git_repo_path, self.rpm_name, branch, sources)
gitutil.add_all(repo) gitutil.add_all(repo)
verify = repo.is_dirty() verify = repo.is_dirty()

View File

@ -1,5 +0,0 @@
# -*-:python; coding:utf-8; -*-
# author: Louis Abel <label@rockylinux.org>
"""
Useful models. These may not be used and may be put elsewhere.
"""

View File

@ -1,5 +0,0 @@
# -*-:python; coding:utf-8; -*-
# author: Louis Abel <label@rockylinux.org>
"""
The peridotpb part of everything I suppose.
"""

View File

@ -8,13 +8,13 @@ from pv2.util import error as err
# General utilities # General utilities
__all__ = [ __all__ = [
'ordered',
'conv_multibyte', 'conv_multibyte',
'to_unicode',
'convert_from_unix_time', 'convert_from_unix_time',
'trim_non_empty_string',
'gen_bool_option', 'gen_bool_option',
'generate_password_hash' 'generate_password_hash',
'ordered',
'to_unicode',
'trim_non_empty_string'
] ]
def to_unicode(string: str) -> str: def to_unicode(string: str) -> str:

View File

@ -19,18 +19,18 @@ except ImportError:
rpm = None rpm = None
__all__ = [ __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_header',
'get_rpm_metadata_from_hdr', 'get_rpm_metadata_from_hdr',
'compare_rpms', 'is_debug_package',
'is_rpm', 'is_rpm',
'get_files_from_package',
'get_exclu_from_package',
'get_rpm_hdr_size',
'split_rpm_by_header', 'split_rpm_by_header',
'get_all_rpm_header_keys', 'verify_rpm_signature'
'verify_rpm_signature',
'add_rpm_key'
] ]
# NOTES TO THOSE RUNNING PYLINT OR ANOTHER TOOL # 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. Note: Splitting a source package will result in an erroneous "arch" field.
""" """
# pylint: disable=no-member # 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] name = hdr[rpm.RPMTAG_NAME]
version = hdr[rpm.RPMTAG_VERSION] version = hdr[rpm.RPMTAG_VERSION]
release = hdr[rpm.RPMTAG_RELEASE] release = hdr[rpm.RPMTAG_RELEASE]
epoch = hdr[rpm.RPMTAG_EPOCH] epoch = hdr[rpm.RPMTAG_EPOCH]
arch = hdr[rpm.RPMTAG_ARCH] arch = pkg_arch
if not epoch: if not epoch:
epoch = '' epoch = ''