diff options
Diffstat (limited to 'CI/testxml/testxml.py')
-rwxr-xr-x | CI/testxml/testxml.py | 224 |
1 files changed, 112 insertions, 112 deletions
diff --git a/CI/testxml/testxml.py b/CI/testxml/testxml.py index f26af4d..4eb97b1 100755 --- a/CI/testxml/testxml.py +++ b/CI/testxml/testxml.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # -*- coding: utf8 -*- # # Copyright (C) 2010-2011 Evol Online @@ -10,8 +10,8 @@ import re import datetime import xml import csv -import ogg.vorbis -import StringIO +import mutagen.oggvorbis +import io import sys from xml.dom import minidom from xml.etree import ElementTree @@ -65,25 +65,25 @@ class Layer: def printErr(err): errDict.add(err) - print err.encode("utf-8") + print(err.encode("utf-8")) def showFileErrorById(id, rootDir, fileDir): rootDir = rootDir.encode("utf-8") fileDir = fileDir.encode("utf-8") - print "error: id=" + id + ", file not found: " + fileDir + " (" + rootDir + fileDir + ")" + print("error: id=" + id + ", file not found: " + fileDir + " (" + rootDir + fileDir + ")") def showFileWarningById(id, rootDir, fileDir): rootDir = rootDir.encode("utf-8") fileDir = fileDir.encode("utf-8") - print "warn: id=" + id + ", file not found: " + fileDir + " (" + rootDir + fileDir + ")" + print("warn: id=" + id + ", file not found: " + fileDir + " (" + rootDir + fileDir + ")") def showError(id, text): text = text.encode("utf-8") - print "error: id=" + id + " " + text + print("error: id=" + id + " " + text) def showWarning(id, text): text = text.encode("utf-8") - print "warn: id=" + id + " " + text + print("warn: id=" + id + " " + text) def showMsg(id, text, src, iserr): global errors, warnings @@ -136,26 +136,26 @@ def showFileMsgById(id, rootDir, fileDir, iserr): warnings = warnings + 1 def printSeparator(): - print "--------------------------------------------------------------------------------" + print("--------------------------------------------------------------------------------") def showHeader(): - print "Evol client data validator." - print "Run at: " + datetime.datetime.now().isoformat() - print "https://gitlab.com/evol/evol-tools/blob/master/testxml/testxml.py" + print("Evol client data validator.") + print("Run at: " + datetime.datetime.now().isoformat()) + print("https://gitlab.com/evol/evol-tools/blob/master/testxml/testxml.py") printSeparator() def showFooter(): printSeparator() - print "Total:" - print " Warnings: " + str(warnings) - print " Errors: " + str(errors) + print("Total:") + print(" Warnings: " + str(warnings)) + print(" Errors: " + str(errors)) def enumDirs(parentDir): global warnings, errors try: files = os.listdir(parentDir) except OSError: - print "Directory error: " + parentDir + print("Directory error: " + parentDir) if silent == False: warnings = warnings + 1 return @@ -169,10 +169,10 @@ def enumDirs(parentDir): if filt.search(file1): try: if silent == True and not stfu: - print "Checking " + file2 + print("Checking " + file2) minidom.parse(file2) except xml.parsers.expat.ExpatError as err: - print "error: " + file2 + ", line=" + str(err.lineno) + ", char=" + str(err.offset) + print("error: " + file2 + ", line=" + str(err.lineno) + ", char=" + str(err.offset)) errors = errors + 1 if file1 != "testxml.py": checkFilePermission(file2) @@ -180,7 +180,7 @@ def enumDirs(parentDir): def checkFilePermission(fullName): global warnings if os.access(fullName, os.X_OK): - print "warn: execute flag on file: " + fullName + print("warn: execute flag on file: " + fullName) warnings = warnings + 1 @@ -194,14 +194,14 @@ def loadPaths(): if node.attributes["name"].value == "itemIcons": iconsDir = node.attributes["value"].value if iconsDir != "graphics/items/": - print "warn: itemIcons path has not default value."\ - " Will be incampatible with old clients." + print("warn: itemIcons path has not default value."\ + " Will be incampatible with old clients.") warnings = warnings + 1 elif node.attributes["name"].value == "sprites": spritesDir = node.attributes["value"].value if spritesDir != "graphics/sprites/": - print "warn: sprites path has not default value."\ - " Will be incampatible with old clients." + print("warn: sprites path has not default value."\ + " Will be incampatible with old clients.") warnings = warnings + 1 elif node.attributes["name"].value == "sfx": sfxDir = node.attributes["value"].value @@ -209,14 +209,14 @@ def loadPaths(): elif node.attributes["name"].value == "particles": particlesDir = node.attributes["value"].value if particlesDir != "graphics/particles/": - print "warn: particles path has not default value."\ - " Will be incampatible with old clients." + print("warn: particles path has not default value."\ + " Will be incampatible with old clients.") warnings = warnings + 1 elif node.attributes["name"].value == "maps": mapsDir = node.attributes["value"].value if mapsDir != "maps/": - print "warn: maps path has not default value."\ - " Will be incampatible with old clients." + print("warn: maps path has not default value."\ + " Will be incampatible with old clients.") warnings = warnings + 1 elif node.attributes["name"].value == "spriteErrorFile": spriteErrorFile = node.attributes["value"].value @@ -234,7 +234,7 @@ def loadPaths(): musicDir = node.attributes["value"].value except: - print "warn: paths.xml not found" + print("warn: paths.xml not found") warnings = warnings + 1 def splitImage(image): @@ -440,7 +440,7 @@ def testSpriteFile(id, fullPath, file, fileLoc, dnum, variant, checkAction, iser return try: - variants = dom.documentElement.attributes["variants"].value + variants = int(dom.documentElement.attributes["variants"].value) except: variants = 0 @@ -541,7 +541,7 @@ def testSpriteFile(id, fullPath, file, fileLoc, dnum, variant, checkAction, iser if s2 == 0: tmp = int(height) else: - tmp = s2; + tmp = s2 if sizes[1] != s2 and tmp != sizesOGL[1] and sizes[1] != sizesOGL[1]: if silent != True: @@ -725,7 +725,7 @@ def testSpriteAction(file, name, action, numframes, iserr): showMsgSprite(file, "duplicate frame animation for frame index=" \ + str(idx) + " action: " + name + \ ", direction: " + direction + "\n" + node2.toxml(), False) - #print node2.toxml() + #print(node2.toxml()) else: lastIndex1 = idx lastIndex2 = -1 @@ -931,15 +931,15 @@ def testImageFile(file, fullPath, sz, src, iserr): def testSound(file, sfxDir, msg): fullPath = parentDir + "/" + sfxDir + file if not os.path.isfile(fullPath) or os.path.exists(fullPath) == False: - print "error:" + fullPath + print("error:" + fullPath) if msg != "": showMsgFile(file, "sound file not found: " + msg , True) else: showMsgFile(file, "sound file not found", True) return try: - ogg.vorbis.VorbisFile(fullPath) - except ogg.vorbis.VorbisError as e: + mutagen.oggvorbis.OggVorbis(fullPath) + except mutagen.oggvorbis.OggVorbisHeaderError() as e: showMsgFile(file, "sound file incorrect error: " + str(e), True) @@ -997,12 +997,12 @@ def testEmitters(id, file, parentNode, src): def testItems(fileName, imgDir): global warnings, errors, safeDye if not stfu: - print "Checking " + fileName + print("Checking " + fileName) try: dom = minidom.parse(parentDir + "/" + fileName) except Exception as err: - print "error: " + fileName + ": corrupted" - print err + print("error: " + fileName + ": corrupted") + print(err) errors = errors + 1 return idset = set() @@ -1013,11 +1013,11 @@ def testItems(fileName, imgDir): name = node.attributes["name"].value if name == "": errors = errors + 1 - print "error: " + fileName + ": Empty include name"; + print("error: " + fileName + ": Empty include name") testItems(name, imgDir) except: errors = errors + 1 - print "error: " + fileName + ": Broken include tag"; + print("error: " + fileName + ": Broken include tag") continue if node.nodeName != "item": continue @@ -1029,14 +1029,14 @@ def testItems(fileName, imgDir): id = node.attributes["id"].value except: if oldId is None: - print "error: " + fileName + ": item without id" + print("error: " + fileName + ": item without id") else: - print "error: " + fileName + ": item without id. Last id was: " + oldId + print("error: " + fileName + ": item without id. Last id was: " + oldId) errors = errors + 1 continue oldId = id if id in idset: - print "error: " + fileName + ": duplicated id=" + id + print("error: " + fileName + ": duplicated id=" + id) errors = errors + 1 else: idset.add(id) @@ -1052,7 +1052,7 @@ def testItems(fileName, imgDir): type = node.attributes["type"].value except: type = "" - print "warn: " + fileName + ": no type attribute for id=" + id + print("warn: " + fileName + ": no type attribute for id=" + id) warnings = warnings + 1 try: image = node.attributes["image"].value @@ -1103,10 +1103,10 @@ def testItems(fileName, imgDir): if type == "hairsprite": if idI >= 0: - print "error: " + fileName + ": hairsprite with id=" + id + print("error: " + fileName + ": hairsprite with id=" + id) errors = errors + 1 elif idI < -100: - print "error: " + fileName + ": hairsprite override player sprites" + print("error: " + fileName + ": hairsprite override player sprites") errors = errors + 1 safeDye = True @@ -1115,10 +1115,10 @@ def testItems(fileName, imgDir): elif type == "racesprite": if idI >= 0: - print "error: " + fileName + ": racesprite with id=" + id + print("error: " + fileName + ": racesprite with id=" + id) errors = errors + 1 elif idI > -100: - print "error: " + fileName + ": racesprite override player hair" + print("error: " + fileName + ": racesprite override player hair") errors = errors + 1 elif type == "usable" or type == "unusable" or type == "generic" \ or type == "equip-necklace" or type == "equip-torso" or type == "equip-feet" \ @@ -1127,7 +1127,7 @@ def testItems(fileName, imgDir): or type == "equip-charm" or type == "equip-ammo" or type == "equip-neck" \ or type == "equip-ring" or type == "card": if image == "": - print "error: " + fileName + ": missing image attribute on id=" + id + print("error: " + fileName + ": missing image attribute on id=" + id) errors = errors + 1 continue elif len(imagecolor) > 0: @@ -1136,7 +1136,7 @@ def testItems(fileName, imgDir): else: testDyeChannel(id, imagecolor, "image=" + image0, True) if colors not in colorsList: - print "error: " + fileName + ": colors value " + colors + " not found in itemcolors.xml" + print("error: " + fileName + ": colors value " + colors + " not found in itemcolors.xml") errors = errors + 1 if floorcolor != None and len(floorcolor) > 0: @@ -1145,14 +1145,14 @@ def testItems(fileName, imgDir): else: testDyeChannel(id, imagecolor, "floor=" + floor0, True); if colors not in colorsList: - print "error: " + fileName + ": colors value " + colors + " not found in itemcolors.xml" + print("error: " + fileName + ": colors value " + colors + " not found in itemcolors.xml") errors = errors + 1 if description == "": - print "warn: " + fileName + ": missing description attribute on id=" + id + print("warn: " + fileName + ": missing description attribute on id=" + id) warnings = warnings + 1 elif description == ".": - print "warn: " + fileName + ": broken description attribute on id=" + id + print("warn: " + fileName + ": broken description attribute on id=" + id) warnings = warnings + 1 if missile != "": @@ -1166,8 +1166,8 @@ def testItems(fileName, imgDir): floorSprite = None if floorSprite != None: if floor != None: - print "error: " + fileName + ": found attribute floor and tag floor. " + \ - "Should be only one tag or attribute. id=" + id + print("error: " + fileName + ": found attribute floor and tag floor. " + \ + "Should be only one tag or attribute. id=" + id) errors = errors + 1 testSprites(id, floorSprite, False, colors is None, True, "", err) @@ -1208,7 +1208,7 @@ def testItems(fileName, imgDir): elif type == "other": None elif type != "": - print "warn: " + fileName + ": unknown type '" + type + "' for id=" + id + print("warn: " + fileName + ": unknown type '" + type + "' for id=" + id) warnings = warnings + 1 @@ -1221,7 +1221,7 @@ def testItemReplace(id, rootNode, name): sprite = node.attributes["sprite"].value except: if len(node.attributes) != 0: - print "error: reading replace sprite name, id=" + str(id) + print("error: reading replace sprite name, id=" + str(id)) errors = errors + 1 continue checkSpriteName(id, sprite) @@ -1242,14 +1242,14 @@ def checkSpriteName(id, name): and name != "glove" and name != "gloves" and name != "weapon" and \ name != "weapons" and name != "shield" and name != "shields" and \ name != "amulet" and name != "amulets" and name != "ring" and name != "rings": - print "error: unknown sprite name " + name + ", id=" + str(id) + print("error: unknown sprite name " + name + ", id=" + str(id)) errors = errors + 1 def testMonsters(fileName): global warnings, errors if not stfu: - print "Checking " + fileName + print("Checking " + fileName) dom = minidom.parse(parentDir + "/" + fileName) idset = set() for node in dom.documentElement.childNodes: @@ -1258,22 +1258,22 @@ def testMonsters(fileName): name = node.attributes["name"].value if name == "": errors = errors + 1 - print "error: " + fileName + ": Empty include name"; + print("error: " + fileName + ": Empty include name") testMonsters(name) except: errors = errors + 1 - print "error: " + fileName + ": Broken include tag"; + print("error: " + fileName + ": Broken include tag") continue if node.nodeName == "monster": try: id = node.attributes["id"].value except: - print "error: " + fileName + ": no id for monster" + print("error: " + fileName + ": no id for monster") errors = errors + 1 continue if id in idset: - print "error: " + fileName + ": duplicate id=" + id + print("error: " + fileName + ": duplicate id=" + id) errors = errors + 1 else: idset.add(id) @@ -1281,7 +1281,7 @@ def testMonsters(fileName): try: name = node.attributes["name"].value except: - print "error: " + fileName + ": no name for id=" + id + print("error: " + fileName + ": no name for id=" + id) errors = errors + 1 name = "" @@ -1316,17 +1316,17 @@ def testSounds(id, node, type): try: event = sound.attributes["event"].value except: - print "error: no sound event name in id=" + id + print("error: no sound event name in id=" + id) errors = errors + 1 if type == "monster": if event != "hit" and event != "miss" and event != "hurt" and event != "die" \ and event != "move" and event != "sit" and event != "spawn": - print "error: incorrect sound event name " + event + " in id=" + id + print("error: incorrect sound event name " + event + " in id=" + id) errors = errors + 1 elif type == "item": if event != "hit" and event != "strike" and event != "miss": - print "error: incorrect sound event name " + event + " in id=" + id + print("error: incorrect sound event name " + event + " in id=" + id) errors = errors + 1 testSound(sound.childNodes[0].data, sfxDir, "") @@ -1334,7 +1334,7 @@ def testSounds(id, node, type): def testNpcs(file): global warnings, errors if not stfu: - print "Checking " + file + print("Checking " + file) dom = minidom.parse(parentDir + "/" + file) idset = set() for node in dom.documentElement.childNodes: @@ -1343,11 +1343,11 @@ def testNpcs(file): name = node.attributes["name"].value if name == "": errors = errors + 1 - print "error: " + file + ": Empty include name"; + print("error: " + file + ": Empty include name") testNpcs(name) except: errors = errors + 1 - print "error: " + file + ": Broken include tag"; + print("error: " + file + ": Broken include tag") continue if node.nodeName != "npc": continue @@ -1355,12 +1355,12 @@ def testNpcs(file): try: id = node.attributes["id"].value except: - print "error: " + file + ": no id for npc" + print("error: " + file + ": no id for npc") errors = errors + 1 continue if id in idset: - print "error: " + file + ": duplicate npc id=" + id + print("error: " + file + ": duplicate npc id=" + id) errors = errors + 1 else: idset.add(id) @@ -1376,7 +1376,7 @@ def readAttr(node, attr, dv, msg, iserr): try: return node.attributes[attr].value except: - print msg + print(msg) if iserr: errors = errors + 1 else: @@ -1760,8 +1760,8 @@ def testOverSizedTiles(layer, tiles, file): warnings = warnings + 1 if len(oversizeErrList) > 0 and silent != True: - print "error: " + file + ": Oversized tile overlapped to next tile in layer " + layer.name + \ - ". Possible incorrect map drawing" + print("error: " + file + ": Oversized tile overlapped to next tile in layer " + layer.name + \ + ". Possible incorrect map drawing") errors = errors + 1 errStr = "" k = 0 @@ -1771,7 +1771,7 @@ def testOverSizedTiles(layer, tiles, file): if k > 100: errStr = errStr + "..." break - print errStr + print(errStr) if len(ignoreErrList) > 0: errStr = "" @@ -1790,7 +1790,7 @@ def testOverSizedTiles(layer, tiles, file): if k > 100: errStr = errStr + "..." break - print errStr + print(errStr) def testTiles(mapName, file, tilesMap): @@ -1824,7 +1824,7 @@ def reportAboutTiles(file, data): for k in data: d = data[k] if d[0] != 0 and d[2] != 0: - #print file + ": " + str(k) + ": " + str(d) + #print(file + ": " + str(k) + ": " + str(d)) testCollisionPoints(file, k, d, 1, 3, \ "possible tiles should be without collision: ", \ "because no collision: ", False) @@ -1834,7 +1834,7 @@ def reportAboutTiles(file, data): def testCollisionPoints(file, tileId, data, idx1, idx2, msg1, msg2, iserr): - #print "test: " + str(idx1) + ", " + str(idx2) + #print("test: " + str(idx1) + ", " + str(idx2)) cnt1 = 0 cnt2 = 0 for point in data[idx1]: @@ -1846,7 +1846,7 @@ def testCollisionPoints(file, tileId, data, idx1, idx2, msg1, msg2, iserr): ln1 = len(data[idx1]) ln2 = len(data[idx2]) - #print "cnt1=" + str(cnt1) + ", cnt2=" + str(cnt2) + ", ln1=" + str(ln1) + ", ln2=" + str(ln2) + #print("cnt1=" + str(cnt1) + ", cnt2=" + str(cnt2) + ", ln1=" + str(ln1) + ", ln2=" + str(ln2)) if ln1 > 0 and ln2 > 0 and cnt2 > 0 and cnt2 < cnt1 - tileNumDiff and cnt2 < maxNumErrTiles: text = msg1 c = 0 @@ -1991,18 +1991,18 @@ def testLayer(file, node, name, width, height, layer, tiles): arr = array.array("B") arr.fromstring(layerData) layer.arr = arr -# print file +# print(file) # for item in arr: -# print item +# print(item) elif encoding == "csv": if compression != "": showMsgFile(file, "not supported compression " + compression + \ " for csv layer format:" + name, True) binData = data.childNodes[0].data.strip() - f = StringIO.StringIO(binData) + f = io.StringIO(binData) arr = list(csv.reader(f, delimiter=',', quotechar='|')) layer.arr = [] -# print file +# print(file) for row in arr: try: for item in row: @@ -2019,7 +2019,7 @@ def testLayer(file, node, name, width, height, layer, tiles): arr = array.array('i', (layer.arr)) layer.arr = arr # for item in arr: -# print item +# print(item) elif encoding == "": if compression != "": @@ -2028,7 +2028,7 @@ def testLayer(file, node, name, width, height, layer, tiles): layer.arr = [] tiles = data.getElementsByTagName("tile") -# print file +# print(file) for tile in tiles: try: gid = int(tile.attributes["gid"].value) @@ -2044,7 +2044,7 @@ def testLayer(file, node, name, width, height, layer, tiles): arr = array.array('i', (layer.arr)) layer.arr = arr # for item in arr: -# print item +# print(item) # here may be i should check is tiles correct or not, but i will trust to tiled @@ -2141,9 +2141,9 @@ def countCollisionsNear(layer, x, y): def testMaps(dir): global warnings, errors fullPath = parentDir + "/" + dir - print "Checking maps" + print("Checking maps") if not os.path.isdir(fullPath) or not os.path.exists(fullPath): - print "error: maps dir not found: " + dir + print("error: maps dir not found: " + dir) errors = errors + 1 return @@ -2155,15 +2155,15 @@ def testDirExists(path): global errors fullName = parentDir + "/" + path if not os.path.exists(fullName): - print "error: path '" + path + "' not exists." + print("error: path '" + path + "' not exists.") errors = errors + 1 elif not os.path.isdir(fullName): - print "error: path '" + path + "' is incorrect directory." + print("error: path '" + path + "' is incorrect directory.") errors = errors + 1 def testDefaultFiles(): global warnings - print "Checking default files" + print("Checking default files") testDirExists(iconsDir) testDirExists(spritesDir) testDirExists(particlesDir) @@ -2185,10 +2185,10 @@ def testDefaultFiles(): def testMinimapsDir(): global errors, warnings - print "Checking minimaps" + print("Checking minimaps") fullPath = parentDir + "/" + minimapsDir if not os.path.isdir(fullPath) or not os.path.exists(fullPath): - print "warn: minimaps dir not exist" + print("warn: minimaps dir not exist") warnings = warnings + 1 return for file in os.listdir(fullPath): @@ -2265,7 +2265,7 @@ def testSoundsDir(dir, sfxDir): fullPath = parentDir + "/" + sfxDir + dir if not os.path.isdir(fullPath) or not os.path.exists(fullPath): - print "warn: directory " + sfxDir + " not exist" + print("warn: directory " + sfxDir + " not exist") warnings = warnings + 1 return for file in os.listdir(fullPath): @@ -2280,7 +2280,7 @@ def testSoundsDir(dir, sfxDir): def testItemColors(fileName): global warnings, errors, safeDye, colorLists - print "Checking itemcolors.xml" + print("Checking itemcolors.xml") try: dom = minidom.parse(parentDir + "/" + fileName) except: @@ -2293,11 +2293,11 @@ def testItemColors(fileName): try: name = node.attributes["name"].value except: - print "error: colors list dont have name" + print("error: colors list dont have name") errors = errors + 1 continue if name in colorsList: - print "error: duplicate color list: " + name + print("error: duplicate color list: " + name) errors = errors + 1 continue colorsList.add(name) @@ -2309,27 +2309,27 @@ def testItemColors(fileName): try: id = colorNode.attributes["id"].value except: - print "error: getting id in list: " + name + print("error: getting id in list: " + name) errors = errors + 1 continue try: colorName = colorNode.attributes["name"].value except: - print "error: getting name in list: " + name + print("error: getting name in list: " + name) errors = errors + 1 continue try: colorDye = colorNode.attributes["value"].value except: - print "error: getting color in list: " + name + print("error: getting color in list: " + name) errors = errors + 1 if id in colors: - print "error: color with id " + str(id) + " already in list: " + name + print("error: color with id " + str(id) + " already in list: " + name) errors = errors + 1 else: colors.add(id) if colorName in names: - print "error: color with name \"" + colorName + "\" already in list: " + name + print("error: color with name \"" + colorName + "\" already in list: " + name) errors = errors + 1 else: names.add(colorName) @@ -2379,11 +2379,11 @@ def detectClientData(dirs): for dir in dirs: if haveXml(dir): - print "Detected client data directory in: " + dir + print("Detected client data directory in: " + dir) parentDir = dir return True - print "Cant detect client data directory" + print("Cant detect client data directory") exit(1) @@ -2400,9 +2400,9 @@ if len(sys.argv) == 2: herc = True showHeader() -print "Detecting clientdata dir" +print("Detecting clientdata dir") detectClientData([".", "..", "../../../client-data", parentDir]) -print "Checking xml file syntax" +print("Checking xml file syntax") enumDirs(parentDir) loadPaths() (mapToAtlas, atlasToFiles) = loadMapAtlases("/maps.xml") @@ -2413,17 +2413,17 @@ testMonsters("/monsters.xml") testNpcs("/npcs.xml") testMaps(mapsDir) testMinimapsDir() -print "Checking images dir" +print("Checking images dir") testImagesDir(wallpapersDir, 0) -print "Checking icons dir" +print("Checking icons dir") testImagesDir(iconsDir, 32) -print "Checking sprites dir" +print("Checking sprites dir") testSpritesDir("") -print "Checking particles dir" +print("Checking particles dir") testParticlesDir(particlesDir) -print "Checking sfx dir" +print("Checking sfx dir") testSoundsDir("", sfxDir) -print "Checking music dir" +print("Checking music dir") if silent != True: testSoundsDir("", musicDir) showFooter() |