Author: ai0867
Date: Mon Sep 29 10:37:58 2008
New Revision: 29751

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29751&view=rev
Log:
* Check in proof-of-concept version of wmltest.

Added:
    trunk/data/tools/wesnoth/wmlgrammar.py
    trunk/data/tools/wmltest   (with props)

Added: trunk/data/tools/wesnoth/wmlgrammar.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmlgrammar.py?rev=29751&view=auto
==============================================================================
--- trunk/data/tools/wesnoth/wmlgrammar.py (added)
+++ trunk/data/tools/wesnoth/wmlgrammar.py Mon Sep 29 10:37:58 2008
@@ -1,0 +1,34 @@
+"""
+This file is used to store the grammar of WML for wmltest.
+"""
+grammar = {
+'WML' : (
+    [ 'textdomain', 'game_config', 'about' ],
+    [] ),
+'textdomain' : (
+    [],
+    [ 'name' ]),
+'game_config' : (
+    [ 'server', 'color_range', 'color_palette' ],
+    [ 'wesnothd_name', 'base_income', 'village_income', 'poison_amount', 
'rest_heal_amount', 'recall_cost', 'kill_experience', 'lobby_refresh', 'icon', 
'title', 'logo', 'title_music', 'lobby_music', 'logo_x', 'logo_y', 'buttons_x', 
'buttons_y', 'buttons_padding', 'tip_x', 'tip_width', 'tip_padding', 
'energy_image', 'moved_ball_image', 'unmoved_ball_image', 
'partmoved_ball_image', 'enemy_ball_image', 'ally_ball_image', 'flag_image', 
'flag_icon_image', 'cross_image', 'hp_bar_scaling', 'xp_bar_scaling', 
'lobby_refresh', 'footprint_prefix', 'footprint_teleport_enter', 
'footprint_teleport_exit', 'terrain_mask_image', 'grid_image', 
'unreachable_image', 'observer_image', 'tod_bright_image', 'level_image', 
'ellipsis_image', 'default_victory_music', 'default_defeat_music', 
'defense_color_scale', 'flag_rgb' ]),
+'color_palette' : (
+    [],
+    [ 'magenta', 'flag_green', 'ellipse_red' ]),
+'about' : (
+    [ 'entry' ],
+    [ 'images', 'title' ]),
+'entry' : (
+    [],
+    [ 'name', 'comment', 'wikiuser', 'email', 'ircuser' ]),
+'server' : (
+    [],
+    [ 'name', 'address' ]),
+'color_range' : (
+    [],
+    [ 'id', 'rgb', 'name' ]),
+'color_palette' : (
+    [],
+    [ 'magenta', 'flag_green', 'ellipse_red' ]),
+
+}
+

Added: trunk/data/tools/wmltest
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wmltest?rev=29751&view=auto
==============================================================================
--- trunk/data/tools/wmltest (added)
+++ trunk/data/tools/wmltest Mon Sep 29 10:37:58 2008
@@ -1,0 +1,90 @@
+#!/usr/bin/env python
+"""
+wmltest -- tool to test the integrity and meaning of WML.
+
+Run without arguments to see usage.
+"""
+
+import wesnoth.wmldata as wmldata
+import wesnoth.wmlparser as wmlparser
+# Not needed yet
+#import wesnoth.wmltools as wmltools
+import wesnoth.wmlgrammar as wmlgrammar
+
+class Tester:
+    """
+    The Tester class, this walks the WML tree and checks wheter stuff has 
meaning.
+    """
+    def __init__(self, wmltree, verbosity):
+        self.wmltree = wmltree
+        self.verbosity = verbosity
+    def test(self, tag=None, depth=0):
+        if not tag:
+            tag = self.wmltree
+        if self.verbosity > 2:
+            print "%sTesting tag %s" % (depth * ' ', tag.name, )
+        for item in tag.data:
+            if isinstance(item, wmldata.DataSub):
+                if item.name in wmlgrammar.grammar[tag.name][0]:
+                    self.test(item, depth + 1)
+                else:
+                    print "Found tag %s which is meaningless in %s" % 
(item.name, tag.name)
+            elif isinstance(item, wmldata.DataText):
+                if item.name in wmlgrammar.grammar[tag.name][1]:
+                    if self.verbosity > 2:
+                        print "%sFound key %s with contents %s" % ((depth + 1) 
* ' ', item.name, item.data)
+                else:
+                    print "Found key %s with value %s, which is meaningless in 
%s" % (item.name, item.data, tag.name)
+            else:
+                raise Exception( "WTF we found something of class %s" % 
(item.__class__,) )
+
+
+if __name__ == '__main__':
+    import optparse, subprocess, os, codecs, sys
+
+    # Ugly hack to force the output of UTF-8.
+    # This prevents us from crashing when we're being verbose 
+    #  and encounter a non-ascii character.
+    sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
+
+    op = optparse.OptionParser()
+    op.set_usage("Usage: %prog [options] [filename]")
+    op.add_option("-p", "--path",
+        help = "Specify Wesnoth's data dir.",
+        dest = "path")
+    op.add_option("-u", "--userpath",
+        help = "Specify user data dir..",
+        dest = "userpath")
+    op.add_option("-v", "--verbose",
+        action = "count",
+        dest = "verbose",
+        help = "Increase verbosity, 4 is the maximum.")
+    (options, args) = op.parse_args()
+
+    if not options.path:
+        try:
+            p = subprocess.Popen(["wesnoth", "--path"], stdout = 
subprocess.PIPE)
+            path = p.stdout.read().strip()
+            options.path = os.path.join(path, "data")
+        except OSError:
+            sys.stderr.write("Could not determine Wesnoth path.\nAssuming 
'.'\n")
+            options.path = '.'
+
+    if len(args) < 1:
+        args.append('%s/_main.cfg' % options.path)
+
+    if options.verbose > 1:
+        print "Options: %s\nArgs: %s\n"% (options, args)
+
+    parser = wmlparser.Parser(options.path, options.userpath)
+
+    if options.verbose > 3:
+        parser.verbose = True
+
+    map(parser.parse_file, args)
+
+    data = wmldata.DataSub("WML")
+    parser.parse_top(data)
+
+    tester = Tester(data, options.verbose)
+    tester.test()

Propchange: trunk/data/tools/wmltest
------------------------------------------------------------------------------
    svn:executable = *


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to