Coverage for debputy/version_substitutions.py: 0%
20 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-22 14:29 +0100
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-22 14:29 +0100
1from datetime import datetime
2from typing import Dict
4from debian.changelog import Changelog
7def load_source_variables(changelog_file: str) -> Dict[str, str]:
8 with open(changelog_file) as fd:
9 dch = Changelog(fd, max_blocks=1)
10 first_entry = dch[0]
11 source_version = first_entry.version
12 epoch = source_version.epoch
13 upstream_version = source_version.upstream_version
14 debian_revision = source_version.debian_revision
15 epoch_upstream = upstream_version
16 upstream_debian_revision = upstream_version
17 if epoch is not None and epoch != '':
18 epoch_upstream = f'{epoch}:{upstream_version}'
19 if debian_revision is not None and debian_revision != '':
20 upstream_debian_revision = f'{upstream_version}-{debian_revision}'
22 local_time = datetime.strptime(first_entry.date, "%a, %d %b %Y %H:%M:%S %z")
23 source_date_epoch = int(local_time.timestamp())
24 return {
25 'DEB_SOURCE': first_entry.package,
26 'DEB_VERSION': source_version.full_version,
27 'DEB_VERSION_EPOCH_UPSTREAM': epoch_upstream,
28 'DEB_VERSION_UPSTREAM_REVISION': upstream_debian_revision,
29 'DEB_VERSION_UPSTREAM': upstream_version,
30 'SOURCE_DATE_EPOCH': source_date_epoch,
31 }