mail[Wesnoth-commits] r44639 - /trunk/data/tools/wesnoth/wmlparser2.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by elias on July 24, 2010 - 18:36:
Author: elias
Date: Sat Jul 24 18:36:11 2010
New Revision: 44639

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44639&view=rev
Log:
[python wmlparser] Added options to not pre-process.

Modified:
    trunk/data/tools/wesnoth/wmlparser2.py

Modified: trunk/data/tools/wesnoth/wmlparser2.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmlparser2.py?rev=44639&r1=44638&r2=44639&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmlparser2.py (original)
+++ trunk/data/tools/wesnoth/wmlparser2.py Sat Jul 24 18:36:11 2010
@@ -172,7 +172,8 @@
         return s
 
 class Parser:
-    def __init__(self, wesnoth_exe, config_dir, data_dir):
+    def __init__(self, wesnoth_exe, config_dir, data_dir,
+        no_preprocess):
         """
         path - Path to the file to parse.
         wesnoth_exe - Wesnoth executable to use. This should have been
@@ -181,6 +182,7 @@
         self.wesnoth_exe = wesnoth_exe
         self.config_dir = config_dir
         self.data_dir = data_dir
+        self.no_preprocess = no_preprocess
         self.preprocessed = None
 
         self.last_wml_line = "?"
@@ -188,7 +190,8 @@
 
     def parse_file(self, path, defines = ""):
         self.path = path
-        self.preprocess(defines)
+        if not self.no_preprocess:
+            self.preprocess(defines)
         self.parse()
 
     def parse_text(self, text, defines = ""):
@@ -197,7 +200,8 @@
         temp.write(text)
         temp.flush()
         self.path = temp.name
-        self.preprocess(defines)
+        if not self.no_preprocess:
+            self.preprocess(defines)
         self.parse()
 
     def preprocess(self, defines):
@@ -499,6 +503,7 @@
     opt.add_option("-d", "--defines", help = "comma separated list of WML 
defines")
     opt.add_option("-T", "--test", action = "store_true")
     opt.add_option("-j", "--to-json", action = "store_true")
+    opt.add_option("-n", "--no-preprocess", action = "store_true")
     opt.add_option("-x", "--to-xml", action = "store_true")
     options, args = opt.parse_args()
 
@@ -506,13 +511,15 @@
         sys.stderr.write("No input given. Use -h for help.\n")
         sys.exit(1)
 
-    if not options.wesnoth or not os.path.exists(options.wesnoth):
+    if not options.no_preprocess and (not options.wesnoth or not
+        os.path.exists(options.wesnoth)):
         sys.stderr.write("Wesnoth executable not found.\n")
         sys.exit(1)
 
     if options.test:
         print("Running tests")
-        p = Parser(options.wesnoth)
+        p = Parser(options.wesnoth, options.config_dir,
+            options.data_dir, options.no_preprocess)
 
         only = None
         def test2(input, expected, note, function):
@@ -644,7 +651,8 @@
 
         sys.exit(0)
 
-    p = Parser(options.wesnoth, options.config_dir, options.data_dir)
+    p = Parser(options.wesnoth, options.config_dir, options.data_dir,
+        options.no_preprocess)
     if options.input: p.parse_file(options.input, options.defines)
     elif options.text: p.parse_text(options.text, options.defines)
     if options.to_json:




Related Messages


Powered by MHonArc, Updated Sat Jul 24 19:20:14 2010