From aac6a79a04798f668e0203f12ab82228be896719 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 29 Aug 2008 19:27:10 +0000 Subject: [PATCH] Restore a 1.5 conversion I shouldn't have dropped. --- data/tools/wmllint | 49 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/data/tools/wmllint b/data/tools/wmllint index 51a6646410e..7d112d5bb32 100755 --- a/data/tools/wmllint +++ b/data/tools/wmllint @@ -1131,10 +1131,51 @@ if __name__ == '__main__': if not upconvert: return line original = line - # Perform line changes - if "wmllint: noconvert" not in original: - for (old, new) in linechanges: - line = line.replace(old, new) + if upconvert: + # Perform line changes + if "wmllint: noconvert" not in original: + for (old, new) in linechanges: + line = line.replace(old, new) + # Perform tag renaming for 1.5. Note: this has to happen before + # the sanity check, which assumes [unit] has already been + # mapped to [unit_type]. Also, beware that this test will fail to + # convert any unit definitions not in conventionally-named + # directories -- this is necessary in order to avoid stepping + # on SingleUnitWML in macro files. + # UnitWML + if "units" in filename: + line = line.replace("[unit]", "[unit_type]") + line = line.replace("[+unit]", "[+unit_type]") + line = line.replace("[/unit]", "[/unit_type]") + # Handle SingleUnitWML or Standard Unit Filter or SideWML + # Also, when macro calls have description= in them, the arg is + # a SUF being passed in. + if (under("unit") and not "units" in filename) or \ + standard_unit_filter() or \ + under("side") or \ + re.search("{[A-Z]+.*description=.*}", line): + if "id" not in tagstack[-1][1] and "_" not in line: + line = re.sub(r"\bdescription\s*=", "id=", line) + if "name" not in tagstack[-1][1]: + line = re.sub(r"user_description\s*=", "name=", line) + # Now, inside objects... + if under("object") and "description" not in tagstack[-1][1]: + line = re.sub(r"user_description\s*=", "description=", line) + # Alas, WML variable references cannot be converted so + # automatically. + if ".description" in line: + print '"%s", line %d: .description may need hand fixup' % \ + (filename, lineno) + if ".user_description" in line: + print '"%s", line %d: .user_description may need hand fixup' % \ + (filename, lineno) + # In unit type definitions + if under("unit_type") or under("female") or under("unit"): + line = line.replace("unit_description=", "description=") + line = line.replace("advanceto=", "advances_to=") + # Inside themes + if within("theme"): + line = line.replace("[unit_description]", "[unit_name]") # Report the changes if verbose > 0 and line != original: msg = "%s, line %d: %s -> %s" % \