add autochangelog logic

This commit is contained in:
Louis Abel 2024-03-04 17:06:07 -07:00
parent b982646f3a
commit 3e925ca471
Signed by: label
GPG Key ID: 2A6975660E424560

View File

@ -22,6 +22,13 @@ from pv2.util import uploader as upload
#except ImportError: #except ImportError:
# HAS_GI = False # HAS_GI = False
try:
from rpmautospec.subcommands import process_distgit as rpmautocl
HAS_RPMAUTOSPEC = True
except ImportError:
HAS_RPMAUTOSPEC = False
print('WARNING! rpmautospec was not found on this system and is not loaded.')
__all__ = [ __all__ = [
'Import', 'Import',
'SrpmImport', 'SrpmImport',
@ -688,6 +695,7 @@ class GitImport(Import):
check_dest_repo = gitutil.lsremote(self.dest_git_url) check_dest_repo = gitutil.lsremote(self.dest_git_url)
source_git_repo_path = f'/var/tmp/{self.rpm_name}-source' source_git_repo_path = f'/var/tmp/{self.rpm_name}-source'
source_git_repo_spec = f'{source_git_repo_path}/{self.rpm_name}.spec' source_git_repo_spec = f'{source_git_repo_path}/{self.rpm_name}.spec'
source_git_repo_changelog = f'{source_git_repo_path}/changelog'
dest_git_repo_path = f'/var/tmp/{self.rpm_name}' dest_git_repo_path = f'/var/tmp/{self.rpm_name}'
metadata_file = f'{source_git_repo_path}/.{self.rpm_name}.metadata' metadata_file = f'{source_git_repo_path}/.{self.rpm_name}.metadata'
sources_file = f'{source_git_repo_path}/sources' sources_file = f'{source_git_repo_path}/sources'
@ -802,6 +810,28 @@ class GitImport(Import):
if not os.path.exists(source_git_repo_spec) and len(self.alternate_spec_name) == 0: 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) source_git_repo_spec = self.find_spec_file(source_git_repo_path)
# do rpm autochangelog logic here
if HAS_RPMAUTOSPEC and os.path.exists(source_git_repo_changelog):
# Check that the spec file really has %autochangelog
for line in source_git_repo_spec:
if re.search('^%autochangelog', line):
print('autochangelog found')
AUTOCHANGELOG = True
# It was easier to do this then reimplement logic
if AUTOCHANGELOG:
try:
rpmautocl.process_distgit(
source_git_repo_path,
'/tmp/{self.rpm_name}.spec'
)
except Exception as exc:
raise err.GenericError('There was an error with autospec.') from exc
shutil.copy(f'/tmp/{self.rpm_name}.spec',
f'{source_git_repo_path}/{self.rpm_name}.spec')
os.remove(f'/tmp/{self.rpm_name}.spec')
# attempt to pack up the RPM, get metadata # attempt to pack up the RPM, get metadata
packed_srpm = self.pack_srpm(source_git_repo_path, packed_srpm = self.pack_srpm(source_git_repo_path,
source_git_repo_spec, source_git_repo_spec,