deskflow/CI/deb_changelog.py
Kyle Bloom 5711a5346f
Add changelogs to deb's (#7167)
* Add changelogs to deb's

* Update changelog

* Fix code smell
2022-05-12 09:27:59 +01:00

38 lines
1.6 KiB
Python

from argparse import ArgumentParser
from datetime import datetime, timezone
IGNORE_SEGMENTS = ['Github Actions:']
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('name', type=str, help='Name of the package')
parser.add_argument('version', type=str, help='Version of the package')
parser.add_argument('-d', '--distribution', type=str, default='unstable', help='Distribution the package is built for')
parser.add_argument('-u', '--urgency', type=str, default='low', help='Urgency of the package')
args = parser.parse_args()
build_time = datetime.now(timezone.utc).strftime('%a, %d %b %Y %H:%M:%S %z') # day-of-week, dd month yyyy hh:mm:ss +zzzz
with open('ChangeLog', 'r') as in_file, open('debian/changelog', 'w+') as out_file:
out_file.write(f'{args.name} ({args.version}) {args.distribution}; urgency={args.urgency}\n')
in_section = False
ignore_segment = False
while line := in_file.readline():
if line.startswith('v'):
if line.startswith(f'v{args.version}'):
in_section = True
elif in_section:
break
elif not in_section:
continue
elif line.strip().replace('=', '') == '':
ignore_segment = False
elif line.strip() in IGNORE_SEGMENTS:
ignore_segment = True
elif line.strip().endswith(':'):
out_file.write(f'\n * {line.strip()[:-1]}')
else:
if in_section and not ignore_segment:
while line.startswith(('#', '|', '-')):
line = ' '.join(line.split()[1:])
out_file.write(f'\n - {line}')
out_file.write(f'\n\n -- Symless <engineering@symless.com> {build_time}')