From 3901e2ef92eba8571d12c0531833e79bee406970 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 2 Oct 2023 16:40:57 +0100 Subject: [PATCH 1/2] Check for incorrect changelog extensions Signed-off-by: Dave Rodgman --- scripts/assemble_changelog.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index f3aca7070..44fe011f3 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -60,6 +60,11 @@ class LostContent(Exception): message = ('Lost content from {}: "{}"'.format(filename, line)) super().__init__(message) +class FilePathError(Exception): + def __init__(self, filenames): + message = ('Changelog filenames do not end with .txt: {}'.format(", ".join(filenames))) + super().__init__(message) + # The category names we use in the changelog. # If you edit this, update ChangeLog.d/README.md. STANDARD_CATEGORIES = ( @@ -448,14 +453,23 @@ def list_files_to_merge(options): files_to_merge.sort(key=EntryFileSortKey) return files_to_merge +def check_extensions(options): + files = glob.glob(os.path.join(options.dir, '*')) + files = {x for x in files if not x.endswith(".txt")} + files.discard("ChangeLog.d/00README.md") + if files: + raise FilePathError(files) + def merge_entries(options): """Merge changelog entries into the changelog file. Read the changelog file from options.input. + Check that all entries have a .txt extension Read entries to merge from the directory options.dir. Write the new changelog to options.output. Remove the merged entries if options.keep_entries is false. """ + check_extensions(options) with open(options.input, 'r', encoding='utf-8') as input_file: changelog = ChangeLog(input_file, TextChangelogFormat) files_to_merge = list_files_to_merge(options) From 65d8ec1444542a905e8209e0438646d80bb28473 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 2 Oct 2023 17:19:51 +0100 Subject: [PATCH 2/2] Move check into list_files_to_merge Signed-off-by: Dave Rodgman --- scripts/assemble_changelog.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 44fe011f3..e8081012a 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -448,18 +448,24 @@ def list_files_to_merge(options): """List the entry files to merge, oldest first. "Oldest" is defined by `EntryFileSortKey`. + + Also check for required .txt extension """ - files_to_merge = glob.glob(os.path.join(options.dir, '*.txt')) + files_to_merge = glob.glob(os.path.join(options.dir, '*')) + + # Ignore 00README.md + readme = os.path.join(options.dir, "00README.md") + if readme in files_to_merge: + files_to_merge.remove(readme) + + # Identify files without the required .txt extension + bad_files = [x for x in files_to_merge if not x.endswith(".txt")] + if bad_files: + raise FilePathError(bad_files) + files_to_merge.sort(key=EntryFileSortKey) return files_to_merge -def check_extensions(options): - files = glob.glob(os.path.join(options.dir, '*')) - files = {x for x in files if not x.endswith(".txt")} - files.discard("ChangeLog.d/00README.md") - if files: - raise FilePathError(files) - def merge_entries(options): """Merge changelog entries into the changelog file. @@ -469,7 +475,6 @@ def merge_entries(options): Write the new changelog to options.output. Remove the merged entries if options.keep_entries is false. """ - check_extensions(options) with open(options.input, 'r', encoding='utf-8') as input_file: changelog = ChangeLog(input_file, TextChangelogFormat) files_to_merge = list_files_to_merge(options)