From c329303281a5681e8a95692aea1d7fc8812b4ee7 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Mon, 21 Aug 2023 23:53:31 -0700 Subject: [PATCH] 0.11.0: add importer script for poetry --- pv2/importer/operation.py | 23 +++++++++- pv2/scripts/import_pkg.py | 90 +++++++++++++++++++++++++++++++++++++++ pyproject.toml | 7 ++- 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 pv2/scripts/import_pkg.py diff --git a/pv2/importer/operation.py b/pv2/importer/operation.py index 936f2f5..2e5ffbd 100644 --- a/pv2/importer/operation.py +++ b/pv2/importer/operation.py @@ -194,6 +194,22 @@ class Import: if os.path.exists('/usr/sbin/restorecon'): processor.run_proc_foreground_shell(f'/usr/sbin/restorecon {dest_path}') + @staticmethod + def import_lookaside_peridot_cli( + repo_path: str, + repo_name: str, + file_dict: dict, + ): + """ + Attempts to find and use the peridot-cli binary to upload to peridot's + lookaside. This assumes the environment is setup correctly with the + necessary variables. + + Note: This is a temporary hack and will be removed in a future update. + """ + for name, _ in file_dict.items(): + source_path = f'{repo_path}/{name}' + @staticmethod def skip_import_lookaside(repo_path: str, file_dict: dict): """ @@ -561,6 +577,7 @@ class GitImport(Import): source_git_protocol: str = 'https', dest_branch: str = '', distprefix: str = 'el', + source_git_user: str = 'git', git_user: str = 'git', org: str = 'rpms' ): @@ -573,7 +590,11 @@ class GitImport(Import): self.__rpm = package self.__release = release # pylint: disable=line-too-long - self.__source_git_url = f'{source_git_protocol}://{source_git_url_path}/{source_git_org_path}/{package}.git' + full_source_git_url_path = source_git_url_path + if source_git_protocol == 'ssh': + full_source_git_url_path = f'{source_git_user}@{source_git_url_path}' + + self.__source_git_url = f'{source_git_protocol}://{full_source_git_url_path}/{source_git_org_path}/{package}.git' self.__git_url = f'ssh://{git_user}@{git_url_path}/{org}/{package}.git' self.__dist_prefix = distprefix self.__dist_tag = f'.{distprefix}{release}' diff --git a/pv2/scripts/import_pkg.py b/pv2/scripts/import_pkg.py new file mode 100644 index 0000000..582d72f --- /dev/null +++ b/pv2/scripts/import_pkg.py @@ -0,0 +1,90 @@ +#!/usr/bin/python3 +# This is called to do imports, whether from an RPM or a git repo (e.g. CentOS +# stream gitlab) + +import argparse +import pv2.importer as importutil + +parser = argparse.ArgumentParser(description="Importer Utility") +subparser = parser.add_subparsers(dest='cmd') +subparser.required = True + +rpm_parser = subparser.add_parser('rpm') +git_parser = subparser.add_parser('git') + +rpm_parser.add_argument('--gituser', type=str, required=False, default='git') +rpm_parser.add_argument('--giturl', type=str, required=True) +rpm_parser.add_argument('--branch', type=str, required=True) +rpm_parser.add_argument('--srpm', type=str, required=True) +rpm_parser.add_argument('--release', type=str, required=False, default='') +rpm_parser.add_argument('--gitorg', type=str, required=False, default='rpms') +rpm_parser.add_argument('--distprefix', type=str, required=False, default='el') +rpm_parser.add_argument('--dest-lookaside', type=str, required=False, default='/var/www/html/sources') +rpm_parser.add_argument('--verify-signature', action='store_true') +rpm_parser.add_argument('--skip-lookaside-upload', + action='store_true', + help='Set this flag to skip uploading to /var/www/html/sources esque lookaside') + +git_parser.add_argument('--name', type=str, required=True) +git_parser.add_argument('--source-gituser', type=str, required=False, default='git') +git_parser.add_argument('--source-giturl', type=str, required=True) +git_parser.add_argument('--source-gitorg', type=str, required=True) +git_parser.add_argument('--gituser', type=str, required=False, default='git') +git_parser.add_argument('--branch', type=str, required=True) +git_parser.add_argument('--giturl', type=str, required=True) +git_parser.add_argument('--gitorg', type=str, required=False, default='rpms') +git_parser.add_argument('--dest-branch', type=str, required=False, default='') +git_parser.add_argument('--release', type=str, required=False, default='') +git_parser.add_argument('--distprefix', type=str, required=False, default='el') +rpm_parser.add_argument('--dest-lookaside', type=str, required=False, default='/var/www/html/sources') +git_parser.add_argument('--upstream-lookaside', + choices=('rocky8', 'rocky', 'centos', 'stream', 'fedora'), + required=True) +git_parser.add_argument('--alternate-spec-name', + type=str, required=False, + default='', + help='ex: if kernel-rt, use kernel. only use if built-in finder is failing') +git_parser.add_argument('--skip-lookaside-upload', + action='store_true', + help='Set this flag to skip uploading to /var/www/html/sources esque lookaside') + +results = parser.parse_args() +command = parser.parse_args().cmd + +def main(): + if command == 'rpm': + classy = importutil.SrpmImport( + git_url_path=results.giturl, + srpm_path=results.srpm, + release=results.release, + branch=results.branch, + distprefix=results.distprefix, + git_user=results.gituser, + org=results.gitorg, + dest_lookaside=results.dest_lookaside, + verify_signature=results.verify_signature, + ) + classy.pkg_import(skip_lookaside=results.skip_lookaside_upload) + elif command == 'git': + classy = importutil.GitImport( + package=results.name, + source_git_user=results.source_gituser, + source_git_url_path=results.source_giturl, + source_git_org_path=results.source_gitorg, + git_user=results.gituser, + git_url_path=results.giturl, + org=results.gitorg, + release=results.release, + branch=results.branch, + dest_branch=results.dest_branch, + upstream_lookaside=results.upstream_lookaside, + distprefix=results.distprefix, + alternate_spec_name=results.alternate_spec_name, + dest_lookaside=results.dest_lookaside, + ) + classy.pkg_import(skip_lookaside=results.skip_lookaside_upload) + else: + print('Unknown command') + +if __name__ == '__main__': + main() diff --git a/pyproject.toml b/pyproject.toml index 263dd7c..48e8710 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pv2" -version = "0.10.1" +version = "0.11.0" description = "PV2 backend framework module" readme = "README.md" authors = [ @@ -29,3 +29,8 @@ file = "LICENSE" [tool.setuptools] package-dir = { "pv2" = "pv2" } + +[tool.poetry.scripts] +import_pkg = "pv2.scripts.import_pkg:run" +#pkg_info = "pv2.scripts.pkg_info:run" +#build_pkg = "pv2.scripts.build_pkg:run"