Update to Python3: using print function
This commit is contained in:
parent
adacf79111
commit
b9f1ff84be
3 changed files with 21 additions and 18 deletions
|
@ -15,6 +15,7 @@ textdomain stuff in here is therefore only useful to CampGen, as that does
|
|||
not allow composed strings like above.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import re, sys
|
||||
import wmlparser
|
||||
import codecs
|
||||
|
@ -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
|
||||
|
||||
|
@ -182,7 +183,7 @@ class DataSub(Data):
|
|||
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=""):
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
wmlgrammar -- parses a given schema into a more usable form
|
||||
"""
|
||||
from __future__ import print_function
|
||||
import collections
|
||||
import re
|
||||
|
||||
|
@ -54,7 +55,7 @@ class Node(object):
|
|||
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")
|
||||
|
|
|
@ -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:
|
||||
"""
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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')
|
||||
|
|
Loading…
Add table
Reference in a new issue