Add -A/--append parameter to append generated changelog lines to existing file instead of overwriting it

This commit is contained in:
Benjamin Renard 2022-12-12 11:16:27 +01:00
parent 0c3ddea197
commit e71611f17a

16
gitdch
View file

@ -69,6 +69,18 @@ parser.add_argument(
help='Generated Debian changelog output path (default: stdout)', help='Generated Debian changelog output path (default: stdout)',
) )
parser.add_argument(
'-A',
'--append',
action='store_true',
dest='append',
help=(
'Append mode: if the output changelog file already exists, append '
'generated changelog lines at the begining of the file (optional, '
'default: overwriting the file)'
)
)
parser.add_argument( parser.add_argument(
'-n', '-n',
'--package-name', '--package-name',
@ -266,6 +278,10 @@ for version in versions:
if options.output: if options.output:
log.info('Write generated Debian changelog in file %s', options.output) log.info('Write generated Debian changelog in file %s', options.output)
if options.append and os.path.exists(options.output):
with open(options.output, 'r', encoding='utf8') as fd:
changelog_lines += [""]
changelog_lines += fd.readlines()
with open(options.output, 'w', encoding='utf8') as fd: with open(options.output, 'w', encoding='utf8') as fd:
fd.writelines(changelog_lines) fd.writelines(changelog_lines)
else: else: