From 1f8e5fc3aaa0ba7033a5591e66a90c0a3ede0b0f Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Tue, 11 Jul 2023 11:18:54 -0700 Subject: [PATCH] add find spec file --- examples/import_git.py | 2 +- pv2/importer/operation.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/import_git.py b/examples/import_git.py index df4c500..63314e3 100644 --- a/examples/import_git.py +++ b/examples/import_git.py @@ -15,7 +15,7 @@ parser.add_argument('--dest-branch', type=str, required=False, default='') parser.add_argument('--release', type=str, required=False, default='') parser.add_argument('--distprefix', type=str, required=False, default='el') parser.add_argument('--upstream-lookaside', type=str, required=True) -parser.add_argument('--alternate-spec-name', type=str, required=False, default='', description='e.g. if kernel-rt, use kernel') +parser.add_argument('--alternate-spec-name', type=str, required=False, default='', help='e.g. if kernel-rt, use kernel') results = parser.parse_args() classy = importutil.GitImport( results.srpm, diff --git a/pv2/importer/operation.py b/pv2/importer/operation.py index 53c4969..3bdd62c 100644 --- a/pv2/importer/operation.py +++ b/pv2/importer/operation.py @@ -48,6 +48,25 @@ class Import: elif os.path.isdir(file): shutil.rmtree(file) + @staticmethod + def find_spec_file(local_repo_path): + """ + Identifies the spec file in the repo. In the event there's two spec + files, we will error out. Only one spec file is allowed per + repo/package. + """ + file_list = fileutil.filter_files( + local_repo_path, + lambda file: file.endswith('.spec')) + + if len(file_list) > 1: + raise err.ConfigurationError('This repo has more than one spec file.') + + if len(file_list) == 0: + raise err.ConfigurationError('This repo has no spec files.') + + return file_list[0] + @staticmethod def unpack_srpm(srpm_path, local_repo_path): """ @@ -667,6 +686,9 @@ class GitImport(Import): generic.download_file(the_url, download_file, download_checksum, download_hashtype) + if not os.path.exists(source_git_repo_spec) and len(self.alternate_spec_name) == 0: + source_git_repo_spec = self.find_spec_file(source_git_repo_path) + # attempt to pack up the RPM, get metadata packed_srpm = self.pack_srpm(source_git_repo_path, source_git_repo_spec, _dist_tag) if not packed_srpm: