Skip to content

Commit

Permalink
Update to Python3: using print function
Browse files Browse the repository at this point in the history
  • Loading branch information
macabeus authored and Elvish-Hunter committed Mar 22, 2016
1 parent adacf79 commit b9f1ff8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
5 changes: 3 additions & 2 deletions data/tools/wesnoth/wmldata.py
Expand Up @@ -15,6 +15,7 @@
not allow composed strings like above.
"""

from __future__ import print_function
import re, sys
import wmlparser
import codecs
Expand Down Expand Up @@ -157,7 +158,7 @@ class WMLException(Exception):
def __init__(self, text):
super( WMLException, self ).__init__()
self.text = text
print text
print(text)
def __str__(self):
return self.text

Expand All @@ -182,7 +183,7 @@ def clean_empty_ifdefs(self):
item.clean_empty_ifdefs()
while rem:
item = rem.pop()
print "Removing empty #ifdef %s" % item.name
print("Removing empty #ifdef %s" % item.name)
self.remove(item)

def write_file(self, f, indent=0, textdomain=""):
Expand Down
3 changes: 2 additions & 1 deletion data/tools/wesnoth/wmlgrammar.py
@@ -1,6 +1,7 @@
"""
wmlgrammar -- parses a given schema into a more usable form
"""
from __future__ import print_function
import collections
import re

Expand Down Expand Up @@ -54,7 +55,7 @@ def __init__(self, schema, datatypes):
self.attributes.add(Attribute(item, datatypes))
for item in schema.get_all_subs():
if item.name == "element":
print "[element] found in schema, not parsing yet"
print("[element] found in schema, not parsing yet")
# self.ext_elements...
elif item.name == "description":
self.description = item.get_text("text")
Expand Down
31 changes: 16 additions & 15 deletions data/tools/wmlvalidator
Expand Up @@ -7,13 +7,14 @@ Use --help to see usage.
#TODO:
#-define verbosity levels better

from __future__ import print_function
import wesnoth.wmldata as wmldata
import wesnoth.wmlparser as wmlparser
import wesnoth.wmlgrammar as wmlgrammar
import re

def print_indent(string, depth, char=' '):
print "%s%s" % (depth * char, string)
print("%s%s" % (depth * char, string))

class Validator:
"""
Expand Down Expand Up @@ -41,7 +42,7 @@ class Validator:
try:
schema = self.schema.get_element(name)
except KeyError:
print "No valid schema found for %s" % verbosename
print("No valid schema found for %s" % verbosename)
return


Expand All @@ -53,47 +54,47 @@ class Validator:
matches = node.get_texts(attribute.name)
nummatches = len(matches)
if attribute.freq == wmlgrammar.REQUIRED and nummatches != 1:
print "(%s:%d) Attribute '[%s] %s' should appear exactly once, not %d times" % (node.file, node.line, verbosename, attribute.name, nummatches)
print("(%s:%d) Attribute '[%s] %s' should appear exactly once, not %d times" % (node.file, node.line, verbosename, attribute.name, nummatches))
elif attribute.freq == wmlgrammar.OPTIONAL and nummatches > 1:
print "(%s:%d) Attribute '[%s] %s' should appear at most once, not %d times" % (node.file, node.line, verbosename, attribute.name, nummatches)
print("(%s:%d) Attribute '[%s] %s' should appear at most once, not %d times" % (node.file, node.line, verbosename, attribute.name, nummatches))
elif attribute.freq == wmlgrammar.FORBIDDEN and nummatches > 0:
print "(%s:%d) Attribute '[%s] %s' should not appear. It appears %d times" % (node.file, node.line, verbosename, attribute.name, nummatches)
print("(%s:%d) Attribute '[%s] %s' should not appear. It appears %d times" % (node.file, node.line, verbosename, attribute.name, nummatches))
for match in matches:
if 'translatable' in attribute.optionals and match.is_translatable() == False:
print "(%s:%d) Attribute '[%s] %s's value is translatable, but haven't _ at the beginning" % (node.file, node.line, verbosename, attribute.name)
print("(%s:%d) Attribute '[%s] %s's value is translatable, but haven't _ at the beginning" % (node.file, node.line, verbosename, attribute.name))
elif 'translatable' not in attribute.optionals and match.is_translatable() == True:
print "(%s:%d) Attribute '[%s] %s's value isn't translatable, but have a _ at the beginning" % (node.file, node.line, verbosename, attribute.name)
print("(%s:%d) Attribute '[%s] %s's value isn't translatable, but have a _ at the beginning" % (node.file, node.line, verbosename, attribute.name))
if 'list' in attribute.optionals:
pos = 1
for i in match.data.split(","):
if i[0] == ' ': i = i[1:]
if not attribute.validate(i):
print "(%s:%d) Attribute '[%s] %s's value in list should be %s, found at position %d: %s" % (node.file, node.line, verbosename, attribute.name, attribute.type, pos, i)
print("(%s:%d) Attribute '[%s] %s's value in list should be %s, found at position %d: %s" % (node.file, node.line, verbosename, attribute.name, attribute.type, pos, i))
pos += 1
else:
if not attribute.validate(match.data):
print "(%s:%d) Attribute '[%s] %s's value should be %s, found: %s" % (node.file, node.line, verbosename, attribute.name, attribute.type, match.data)
print("(%s:%d) Attribute '[%s] %s's value should be %s, found: %s" % (node.file, node.line, verbosename, attribute.name, attribute.type, match.data))
node.remove(match) # Get rid of these so we can see what's left
for attribute in node.get_all_text():
print "(%s:%d) Attribute '[%s] %s' found, which has no meaning there" % (node.file, node.line, verbosename, attribute.name)
print("(%s:%d) Attribute '[%s] %s' found, which has no meaning there" % (node.file, node.line, verbosename, attribute.name))

# Validate the elements
for element in schema.get_elements():
matches = node.get_subs(element.name)
nummatches = len(matches)
if element.freq == wmlgrammar.REQUIRED and nummatches != 1:
print "(%s:%d) Element '[%s] [%s]' should appear exactly once, not %d times" % (node.file, node.line, verbosename, element.name, nummatches)
print("(%s:%d) Element '[%s] [%s]' should appear exactly once, not %d times" % (node.file, node.line, verbosename, element.name, nummatches))
elif element.freq == wmlgrammar.OPTIONAL and nummatches > 1:
print "(%s:%d) Element '[%s] [%s]' should appear at most once, not %d times" % (node.file, node.line, verbosename, element.name, nummatches)
print("(%s:%d) Element '[%s] [%s]' should appear at most once, not %d times" % (node.file, node.line, verbosename, element.name, nummatches))
for match in matches:
self.validate(match, depth+1, element.subname)
node.remove(match)

for element in node.get_all_subs():
print "(%s:%d) Element '[%s] [%s]' found, which has no meaning there" % (node.file, node.line, verbosename, element.name)
print("(%s:%d) Element '[%s] [%s]' found, which has no meaning there" % (node.file, node.line, verbosename, element.name))
# Do we want to do this?
if False:
print "Attempting to validate [%s] anyway" % element.name
print("Attempting to validate [%s] anyway" % element.name)
self.validate(element, depth+1)

if __name__ == '__main__':
Expand Down Expand Up @@ -142,7 +143,7 @@ if __name__ == '__main__':
args.filename.append(os.path.join(args.path, '_main.cfg'))

if args.verbose > 1:
print "Args: %s\n"% (args, )
print("Args: %s\n"% (args, ))

if not args.schema:
args.schema = os.path.join(args.path, 'schema.cfg')
Expand Down

0 comments on commit b9f1ff8

Please sign in to comment.