remove '~' in [textdomain] and [binary_path] paths

Although the original purpose of the in_textdomain and in_binary_path code, an aborted effort to update their paths to "data/add-ons/", has been superseded by code that updates those paths on all lines, it can still be put to use.

Our first step is to move that section below the code that updated UMC paths, so our regexes won't have to deal with "@campaigns" and "data/campaigns" strings. Then we delete the 'if 0:' line that was neutralizing this section, as well as the obsolete path-changing code. The rest is de-indented one level.

Then we look for the use of "~" for userdata, which does not work for textdomains and binary paths.

Our regex object, 'tilde', is constituted thusly: (1) We make sure that the line starts with the "path" key. Any line we're interested in ought to start with this, and this will also keep this code from going wild on the campaign includes, if an author forgot a closing tag (no reset to False). (x) There shouldn't be any whitespace around the = sign, but we'll be kind. (2) On the value side, there shouldn't be anything before the tilde except perhaps a quote. Rather than underestimate the ingenuity of authors in coming up with weird code, however, I allow anything except a comment to match for a few characters. But if we haven't hit the '~' after five characters, I figure something's wrong, and bail. (3) Then we come to the tilde. Normally, it would be adjoining "add-ons/", but some authors interpolate a slash, or 'data/' (here represented as an optional string).

If we match, we rebuild the line, except 'data/add-ons' is substituted for group(3), and we log to stdout.
This commit is contained in:
Groggy Dice 2013-03-29 23:50:24 -04:00
parent 8efffbe86f
commit f6fca7c4e7

View file

@ -1682,19 +1682,6 @@ def hack_syntax(filename, lines):
break
if lines[i].lstrip().startswith("#"):
pass
# The trouble with this transformation is that it's only right for UMC;
# it clobbers mainline.
if 0:
if "[binary_path]" in lines[i]:
in_binary_path = True
if "[/binary_path]" in lines[i]:
in_binary_path = False
if "[textdomain]" in lines[i]:
in_textdomain = True
if "[/textdomain]" in lines[i]:
in_textdomain = False
if in_binary_path or in_textdomain:
lines[i] = re.sub(r"data/campaigns", r"data/add_ons", lines[i])
# This is done on every line
if "campaigns/" in lines[i]:
lines[i] = lines[i].replace("{~campaigns/", "{~add-ons/")
@ -1717,6 +1704,22 @@ def hack_syntax(filename, lines):
%(filename, i+1, dc.group(1), dc.group(1))
elif "@add-ons/" in lines[i]:
lines[i] = lines[i].replace("{@add-ons/", "{~add-ons/")
# Occasionally authors try to use '~' with [textdomain] or [binary_path].
if "[binary_path]" in lines[i]:
in_binary_path = True
if "[/binary_path]" in lines[i]:
in_binary_path = False
if "[textdomain]" in lines[i]:
in_textdomain = True
if "[/textdomain]" in lines[i]:
in_textdomain = False
if in_binary_path or in_textdomain:
if '~' in lines[i]:
tilde = re.search('(^\s*path) *= *([^#]{0,5})(~/?(data/)?add-ons/)', lines[i])
if tilde:
lines[i] = tilde.group(1) + '=' + tilde.group(2) + 'data/add-ons' + lines[i][tilde.end():]
print '"%s", line %d: %s -> data/add-ons -- [textdomain] and [binary_path] paths do not accept "~" for userdata'\
% (filename, i+1, tilde.group(3))
# More syntax transformations would go here.
return lines