Automatically replace search with search-plugin in changelog

develop
lethosor 2018-04-05 11:21:45 -04:00
parent ef7dc06221
commit cb463c34d8
2 changed files with 24 additions and 12 deletions

@ -26,7 +26,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
are not of interest to users of stable builds only.
- Three ``[`` characters indicate the start of a block (possibly a comment) that
spans multiple lines. Three ``]`` characters indicate the end of such a block.
- ``!`` immediately before a blacklisted phrase (see gen_changelog.py) allows that occurrence only.
- ``!`` immediately before a phrase set up to be replaced (see gen_changelog.py) stops that occurrence from being replaced.
===end
]]]
@ -39,7 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Fixes
- `liquids`: fixed "range" command to default to 1 for dimensions consistently
- `search-plugin`: fixed 4/6 keys in unit screen search
- `search`: fixed 4/6 keys in unit screen search
================================================================================
# 0.44.09-r1

@ -19,9 +19,9 @@ CHANGELOG_SECTIONS = [
'Ruby',
]
BLACKLIST = [
'`search`',
]
REPLACEMENTS = {
'`search`': '`search-plugin`',
}
def find_all_indices(string, substr):
start = 0
@ -32,6 +32,24 @@ def find_all_indices(string, substr):
yield i
start = i + 1
def replace_text(string, replacements):
for old_text, new_text in replacements.items():
new_string = ''
new_string_end = 0 # number of characters from string in new_string
for i in find_all_indices(string, old_text):
if i > 0 and string[i - 1] == '!':
# exempt if preceded by '!'
new_string += string[new_string_end:i - 1]
new_string += old_text
else:
# copy until this occurrence
new_string += string[new_string_end:i]
new_string += new_text
new_string_end = i + len(old_text)
new_string += string[new_string_end:]
string = new_string
return string
class ChangelogEntry(object):
def __init__(self, text, section, stable_version, dev_version):
text = text.lstrip('- ')
@ -70,13 +88,7 @@ def parse_changelog():
for line_id, line in enumerate(f.readlines()):
line_id += 1
for phrase in BLACKLIST:
for i in find_all_indices(line, phrase):
if i == 0 or line[i - 1] != '!':
raise ValueError(
'changelog.txt:%i: blacklisted phrase: %r' %
(line_id, phrase))
line = line.replace('!' + phrase, phrase)
line = replace_text(line, REPLACEMENTS)
if multiline:
multiline += line