Author: elias
Date: Thu Apr 16 00:20:49 2009
New Revision: 34955
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34955&view=rev
Log:
Added --ignore-fatal-errors option to wmlunits.
Modified:
branches/1.6/data/tools/unit_tree/helpers.py
branches/1.6/data/tools/wesnoth/wmlparser.py
branches/1.6/data/tools/wmlunits
Modified: branches/1.6/data/tools/unit_tree/helpers.py
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/data/tools/unit_tree/helpers.py?rev=34955&r1=34954&r2=34955&view=diff
==============================================================================
--- branches/1.6/data/tools/unit_tree/helpers.py (original)
+++ branches/1.6/data/tools/unit_tree/helpers.py Thu Apr 16 00:20:49 2009
@@ -29,7 +29,8 @@
parser.parse_top(None)
self.core_macros = parser.macros
- def parse(self, text_to_parse, ignore_macros = None):
+ def parse(self, text_to_parse, ignore_macros = None,
+ ignore_fatal_errors = False):
# Create the real parser.
parser = wmlparser.Parser(self.datadir, self.userdir)
parser.gettext = self.gettext
@@ -47,9 +48,13 @@
# Create a WML root element and parse the given text into it.
WML = wmldata.DataSub("WML")
+ parser.ignore_fatal_errors = ignore_fatal_errors
+
parser.parse_text(text_to_parse)
parser.parse_top(WML)
+
+ parser.ignore_fatal_errors = False
return WML
@@ -151,6 +156,7 @@
self.era_lookup = {}
self.campaign_lookup = {}
self.parser = ParserWithCoreMacros(isocode, datadir, userdir, transdir)
+ self.ignore_fatal_errors = False
def add_terrains(self):
"""
@@ -235,10 +241,11 @@
#define MULTIPLAYER\n#enddef
#define RANDOM_SIDE\n#enddef
{~campaigns}
- """)
+ """, ignore_fatal_errors = self.ignore_fatal_errors)
except wmlparser.Error, e:
print e
return n
+
for campaign in WML.find_all("campaign"):
cid = self.add_campaign(campaign)
Modified: branches/1.6/data/tools/wesnoth/wmlparser.py
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/data/tools/wesnoth/wmlparser.py?rev=34955&r1=34954&r2=34955&view=diff
==============================================================================
--- branches/1.6/data/tools/wesnoth/wmlparser.py (original)
+++ branches/1.6/data/tools/wesnoth/wmlparser.py Thu Apr 16 00:20:49 2009
@@ -85,6 +85,8 @@
# Whether to print current file, comments, and macro replacements.
self.verbose = False
+
+ self.ignore_fatal_errors = False
def read_encoded(self, filename):
"""
@@ -471,9 +473,16 @@
text = macro.text
for i in range(len(macro.params)):
if 1 + i >= len(params):
- raise Error(self, "Not enough parameters for macro %s. " %
name +
- "%d given but %d needed %s." % (len(params) - 1,
- len(macro.params), macro.params))
+ if self.ignore_fatal_errors:
+ sys.stderr.write("***TRYING TO IGNORE FATAL ERROR
***\n")
+ sys.stderr.write("Not enough parameters for macro %s.
" % name +
+ "%d given but %d needed %s.\n" % (len(params) - 1,
+ len(macro.params), macro.params))
+ params.append("")
+ else:
+ raise Error(self, "Not enough parameters for macro %s.
" % name +
+ "%d given but %d needed %s." % (len(params) - 1,
+ len(macro.params), macro.params))
rep = params[1 + i]
# Handle gettext replacement here, since inside the macro
# the textdomain will be wrong.
@@ -748,7 +757,14 @@
if name[0] == '/':
if state == name[1:]:
return
- raise Error(self, "Mismatched closing tag [%s], expected
[/%s]" % (name, state))
+ if self.ignore_fatal_errors:
+ # This is just a hack to get broken addons to still
show
+ # up with wmlunits.
+ sys.stderr.write("***TRYING TO IGNORE FATAL ERROR
***\n")
+ sys.stderr.write("Mismatched closing tag [%s],
expected [/%s]\n" % (name, state))
+ continue
+ else:
+ raise Error(self, "Mismatched closing tag [%s],
expected [/%s]" % (name, state))
#TODO: make a [+tag] properly append to most recent [tag]
# The below is an ugly hack, but better than keeping the '+'
in the tag name.
elif name[0] == '+':
Modified: branches/1.6/data/tools/wmlunits
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/data/tools/wmlunits?rev=34955&r1=34954&r2=34955&view=diff
==============================================================================
--- branches/1.6/data/tools/wmlunits (original)
+++ branches/1.6/data/tools/wmlunits Thu Apr 16 00:20:49 2009
@@ -852,6 +852,8 @@
print "WML parser language reset to %s." % isocode
stuff = helpers.WesnothList(isocode, datadir, userdir, transdir)
+ if options.ignore_fatal_errors:
+ stuff.ignore_fatal_errors = True
# Parse some stuff we may need.
print "Parsing terrains ...",
@@ -961,6 +963,13 @@
op.add_option("-t", "--transdir",
help = "Specify the directory which has a po subfolder for
translations. "+\
"(Defaults to the current directory.)")
+ op.add_option("-E", "--ignore-fatal-errors", action = "store_true",
+ help = "This is strongly advised against and usually will just" +\
+ " result in everything blowing up. Do *not* use unless you have " +\
+ " first run without this option and informed the authors of broken " +\
+ " WML or of the Python WML Parser of it first. There is a very " +\
+ " small chance that with this option the parser can self-recover from
" +\
+ " some normally fatal errors.")
options, args = op.parse_args()
if not options.output:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits