0.11.0: add importer script for poetry

This commit is contained in:
Louis Abel 2023-08-21 23:53:31 -07:00
parent d0d7581e61
commit c329303281
Signed by: label
GPG Key ID: 2A6975660E424560
3 changed files with 118 additions and 2 deletions

View File

@ -194,6 +194,22 @@ 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 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 @staticmethod
def skip_import_lookaside(repo_path: str, file_dict: dict): def skip_import_lookaside(repo_path: str, file_dict: dict):
""" """
@ -561,6 +577,7 @@ class GitImport(Import):
source_git_protocol: str = 'https', source_git_protocol: str = 'https',
dest_branch: str = '', dest_branch: str = '',
distprefix: str = 'el', distprefix: str = 'el',
source_git_user: str = 'git',
git_user: str = 'git', git_user: str = 'git',
org: str = 'rpms' org: str = 'rpms'
): ):
@ -573,7 +590,11 @@ class GitImport(Import):
self.__rpm = package self.__rpm = package
self.__release = release self.__release = release
# pylint: disable=line-too-long # 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.__git_url = f'ssh://{git_user}@{git_url_path}/{org}/{package}.git'
self.__dist_prefix = distprefix self.__dist_prefix = distprefix
self.__dist_tag = f'.{distprefix}{release}' self.__dist_tag = f'.{distprefix}{release}'

90
pv2/scripts/import_pkg.py Normal file
View File

@ -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()

View File

@ -1,6 +1,6 @@
[project] [project]
name = "pv2" name = "pv2"
version = "0.10.1" version = "0.11.0"
description = "PV2 backend framework module" description = "PV2 backend framework module"
readme = "README.md" readme = "README.md"
authors = [ authors = [
@ -29,3 +29,8 @@ file = "LICENSE"
[tool.setuptools] [tool.setuptools]
package-dir = { "pv2" = "pv2" } 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"