From 5e39c9e94f62d924ec94f8887baa088f05930b07 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 22 Jan 2020 14:55:37 +0100 Subject: [PATCH] Actually remove files Minor rework of how files are removed. Actually do remove the files (earlier I accidentally committed a debug version with removal commented out). --- scripts/assemble_changelog.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index be83fd18c..1de57bbbb 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -172,10 +172,9 @@ class ChangeLog: for line in self.trailer: out.write(line) -def finish_output(files_to_remove, changelog, output_file): +def finish_output(changelog, output_file): """Write the changelog to the output file. - Remove the specified input files. """ if os.path.exists(output_file) and not os.path.isfile(output_file): # The output is a non-regular file (e.g. pipe). Write to it directly. @@ -185,12 +184,13 @@ def finish_output(files_to_remove, changelog, output_file): # then move it into place atomically. output_temp = output_file + '.tmp' changelog.write(output_temp) - for filename in files_to_remove: - sys.stderr.write('Removing ' + filename + '\n') - #os.remove(filename) if output_temp != output_file: os.rename(output_temp, output_file) +def remove_merged_entries(files_to_remove): + for filename in files_to_remove: + os.remove(filename) + def merge_entries(options): """Merge changelog entries into the changelog file. @@ -208,8 +208,9 @@ def merge_entries(options): for filename in files_to_merge: with open(filename, 'rb') as input_file: changelog.add_file(input_file) - files_to_remove = [] if options.keep_entries else files_to_merge - finish_output(files_to_remove, changelog, options.output) + finish_output(changelog, options.output) + if not options.keep_entries: + remove_merged_entries(files_to_merge) def set_defaults(options): """Add default values for missing options."""