Skip to content

Commit

Permalink
Improved changes logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
StrahinjaJacimovic committed Sep 30, 2024
1 parent 07602c2 commit 293c21c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions scripts/log_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def extract_date(filename):
utility.filter_multiple_empty_rows(os.path.join(os.getcwd(),'changelog.md'))

## Update CHANGELOG files with specific date releases
array_of_links = ['Support added for following hardware:\n']
for each_version in all_versions:
## Get file content first
with open(os.path.join(changelog_root, each_version, 'changelog.md'), 'r') as sub_changelog_file:
Expand All @@ -56,17 +55,29 @@ def extract_date(filename):
current_files = os.listdir(os.path.join(changelog_root, each_version))
if len(current_files) > 1:
print('Updated changelog file at: %s' % os.path.join(changelog_root, each_version))
empty_hw = False
array_of_links = ['Support added for following hardware:\n']
if 'new_hw' in current_files:
if 'Support added for following hardware:' not in open(os.path.join(changelog_root, each_version, 'changelog.md'), 'r').read():
array_of_links = [
'>> If any new hardware was added to current version, it will be listed here.\n',
'Support added for following hardware:\n']
empty_hw = True
## Sort the files based on date (newest go to top of the file)
all_sub_files = sorted(os.listdir(os.path.join(changelog_root, each_version, 'new_hw')), key=extract_date)
for each_sub_file in all_sub_files:
## Create new links
array_of_links.append(f'+ **[{each_sub_file.split('.')[0]}](./new_hw/{each_sub_file})**')

## Then write the new sub changelog.md content
with open(os.path.join(changelog_root, each_version, 'changelog.md'), 'w') as sub_changelog_file:
sub_changelog_file.writelines(''.join(sub_changelog).replace('Support added for following hardware:', '\n'.join(array_of_links)))
sub_changelog_file.close()
if empty_hw:
with open(os.path.join(changelog_root, each_version, 'changelog.md'), 'w') as sub_changelog_file:
sub_changelog_file.writelines(''.join(sub_changelog).replace('>> If any new hardware was added to current version, it will be listed here.', '\n'.join(array_of_links)))
sub_changelog_file.close()
else:
with open(os.path.join(changelog_root, each_version, 'changelog.md'), 'w') as sub_changelog_file:
sub_changelog_file.writelines(''.join(sub_changelog).replace('Support added for following hardware:', '\n'.join(array_of_links)))
sub_changelog_file.close()

## And remove any occurrences of more than 1 sequential empty row
utility.filter_multiple_empty_rows(os.path.join(changelog_root, each_version, 'changelog.md'))

0 comments on commit 293c21c

Please sign in to comment.