Add support for multiple changelog sources

develop
lethosor 2020-04-03 23:29:10 -04:00
parent 7052903f96
commit 0c85494a99
1 changed files with 57 additions and 45 deletions

@ -4,6 +4,12 @@ import itertools
import os import os
import sys import sys
CHANGELOG_PATHS = (
'docs/changelog.txt',
'scripts/changelog.txt',
'library/xml/changelog.txt',
)
CHANGELOG_SECTIONS = [ CHANGELOG_SECTIONS = [
'New Plugins', 'New Plugins',
'New Scripts', 'New Scripts',
@ -83,55 +89,61 @@ class ChangelogEntry(object):
return 'ChangelogEntry(%r, %r)' % (self.feature, self.children) return 'ChangelogEntry(%r, %r)' % (self.feature, self.children)
def parse_changelog(): def parse_changelog():
cur_stable = None
cur_dev = None
cur_section = None
last_entry = None
entries = [] entries = []
with open('docs/changelog.txt') as f: for fpath in CHANGELOG_PATHS:
multiline = '' if not os.path.isfile(fpath):
for line_id, line in enumerate(f.readlines()): continue
line_id += 1 with open(fpath) as f:
cur_stable = None
if multiline: cur_dev = None
multiline += line cur_section = None
elif '[[[' in line: last_entry = None
multiline = line.replace('[[[', '') multiline = ''
for line_id, line in enumerate(f.readlines()):
if ']]]' in multiline: line_id += 1
line = multiline.replace(']]]', '')
multiline = '' if multiline:
elif multiline: multiline += line
continue elif '[[[' in line:
multiline = line.replace('[[[', '')
if ']]]' in multiline:
line = multiline.replace(']]]', '')
multiline = ''
elif multiline:
continue
if not line.strip() or line.startswith('==='): if not line.strip() or line.startswith('==='):
continue continue
if line.startswith('##'): if line.startswith('##'):
cur_section = line.lstrip('#').strip() cur_section = line.lstrip('#').strip()
elif line.startswith('#'): elif line.startswith('#'):
cur_dev = line.lstrip('#').strip().lower() cur_dev = line.lstrip('#').strip().lower()
if ('alpha' not in cur_dev and 'beta' not in cur_dev and if ('alpha' not in cur_dev and 'beta' not in cur_dev and
'rc' not in cur_dev): 'rc' not in cur_dev):
cur_stable = cur_dev cur_stable = cur_dev
elif line.startswith('-'): elif line.startswith('-'):
if not cur_stable or not cur_dev or not cur_section: if not cur_stable or not cur_dev or not cur_section:
raise ValueError( raise ValueError(
'changelog.txt:%i: Entry without section' % line_id) '%s:%i: Entry without section' % (fpath, line_id))
last_entry = ChangelogEntry(line.strip(), cur_section, last_entry = ChangelogEntry(line.strip(), cur_section,
cur_stable, cur_dev) cur_stable, cur_dev)
entries.append(last_entry) entries.append(last_entry)
elif line.lstrip().startswith('-'): elif line.lstrip().startswith('-'):
if not cur_stable or not cur_dev: if not cur_stable or not cur_dev:
raise ValueError( raise ValueError(
'changelog.txt:%i: Sub-entry without section' % line_id) '%s:%i: Sub-entry without section' % (fpath, line_id))
if not last_entry: if not last_entry:
raise ValueError( raise ValueError(
'changelog.txt:%i: Sub-entry without parent' % line_id) '%s:%i: Sub-entry without parent' % (fpath, line_id))
last_entry.children.append(line.strip('- \n')) last_entry.children.append(line.strip('- \n'))
else: else:
raise ValueError('Invalid line: ' + line) raise ValueError('Invalid line: ' + line)
if not entries:
raise RuntimeError('No changelog files with contents found')
return entries return entries