From 648bc73bc539f95ca86f035a68f739dc7956fe17 Mon Sep 17 00:00:00 2001 From: Nadyr <41974248+Darlantanis@users.noreply.github.com> Date: Sat, 25 Jun 2022 23:06:30 -0400 Subject: [PATCH] powder that makes you say yes --- tools/GenerateChangelog/ss13_genchangelog.py | 260 ++----------------- 1 file changed, 17 insertions(+), 243 deletions(-) diff --git a/tools/GenerateChangelog/ss13_genchangelog.py b/tools/GenerateChangelog/ss13_genchangelog.py index 13fffa253a..5b0b88cef6 100644 --- a/tools/GenerateChangelog/ss13_genchangelog.py +++ b/tools/GenerateChangelog/ss13_genchangelog.py @@ -1,22 +1,16 @@ -<<<<<<< HEAD ''' Usage: $ python ss13_genchangelog.py [--dry-run] html/changelog.html html/changelogs/ - ss13_genchangelog.py - Generate changelog from YAML. - Copyright 2013 Rob "N3X15" Nelson - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,8 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' -'''//CHOMP Edit: I am tired of this thing not working. I am just removing it. - from __future__ import print_function import yaml, os, glob, sys, re, time, argparse from datetime import datetime, date @@ -72,7 +64,7 @@ if os.path.isfile(changelog_cache): with open(changelog_cache) as f: (_, all_changelog_entries) = yaml.load_all(f) failed_cache_read = False - + # Convert old timestamps to newer format. new_entries = {} for _date in all_changelog_entries.keys(): @@ -88,10 +80,10 @@ if os.path.isfile(changelog_cache): except Exception as e: print("Failed to read cache:") print(e, file=sys.stderr) - -if args.dryRun: + +if args.dryRun: changelog_cache = os.path.join(args.ymlDir, '.dry_changelog.yml') - + if failed_cache_read and os.path.isfile(args.targetFile): from bs4 import BeautifulSoup from bs4.element import NavigableString @@ -107,7 +99,7 @@ if failed_cache_read and os.path.isfile(args.targetFile): if author.endswith('updated:'): author = author[:-8] author = author.strip() - + # Find \n' if len(changes_added) > 0: entry_htm += author_htm if write_entry: changelog.write(entry_htm) - + with open(os.path.join(targetDir, 'templates', 'footer.html'), 'r') as h: for line in h: changelog.write(line) - + with open(changelog_cache, 'w') as f: cache_head = 'DO NOT EDIT THIS FILE BY HAND! AUTOMATICALLY GENERATED BY ss13_genchangelog.py.' @@ -216,221 +208,3 @@ if len(del_after): if errors: sys.exit(1) -''' -======= -''' -Usage: - $ python ss13_genchangelog.py [--dry-run] html/changelog.html html/changelogs/ - -ss13_genchangelog.py - Generate changelog from YAML. - -Copyright 2013 Rob "N3X15" Nelson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -''' - -from __future__ import print_function -import yaml, os, glob, sys, re, time, argparse -from datetime import datetime, date -from time import time - -today = date.today() - -dateformat = "%d %B %Y" - -opt = argparse.ArgumentParser() -opt.add_argument('-d', '--dry-run', dest='dryRun', default=False, action='store_true', help='Only parse changelogs and, if needed, the targetFile. (A .dry_changelog.yml will be output for debugging purposes.)') -opt.add_argument('targetFile', help='The HTML changelog we wish to update.') -opt.add_argument('ymlDir', help='The directory of YAML changelogs we will use.') - -args = opt.parse_args() - -all_changelog_entries = {} - -validPrefixes = [ - 'bugfix', - 'wip', - 'tweak', - 'soundadd', - 'sounddel', - 'rscdel', - 'rscadd', - 'imageadd', - 'imagedel', - 'maptweak', - 'spellcheck', - 'experiment' -] - -def dictToTuples(inp): - return [(k, v) for k, v in inp.items()] - -changelog_cache = os.path.join(args.ymlDir, '.all_changelog.yml') - -failed_cache_read = True -if os.path.isfile(changelog_cache): - try: - with open(changelog_cache) as f: - (_, all_changelog_entries) = yaml.load_all(f) - failed_cache_read = False - - # Convert old timestamps to newer format. - new_entries = {} - for _date in all_changelog_entries.keys(): - ty = type(_date).__name__ - # print(ty) - if ty in ['str', 'unicode']: - temp_data = all_changelog_entries[_date] - _date = datetime.strptime(_date, dateformat).date() - new_entries[_date] = temp_data - else: - new_entries[_date] = all_changelog_entries[_date] - all_changelog_entries = new_entries - except Exception as e: - print("Failed to read cache:") - print(e, file=sys.stderr) - -if args.dryRun: - changelog_cache = os.path.join(args.ymlDir, '.dry_changelog.yml') - -if failed_cache_read and os.path.isfile(args.targetFile): - from bs4 import BeautifulSoup - from bs4.element import NavigableString - print(' Generating cache...') - with open(args.targetFile, 'r') as f: - soup = BeautifulSoup(f) - for e in soup.find_all('div', {'class':'commit'}): - entry = {} - date = datetime.strptime(e.h2.string.strip(), dateformat).date() # key - for authorT in e.find_all('h3', {'class':'author'}): - author = authorT.string - # Strip suffix - if author.endswith('updated:'): - author = author[:-8] - author = author.strip() - - # Find