Created
March 8, 2018 17:13
-
-
Save SaphireLattice/28b2d0c5f96317a599237291aca03da8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
import os.path as path | |
import os | |
import sys | |
tree = ET.parse(sys.argv[1]) | |
root = tree.getroot() | |
def tryfind(src, what): | |
ls = os.listdir(src) | |
normlist = list(map(lambda name: name.lower(), ls)) | |
if (what.lower() in normlist): | |
return ls[normlist.index(what.lower())] | |
return None | |
def findres(src, name): | |
found = None | |
if (path.dirname(name) == ""): | |
if (name in os.listdir(path.dirname(src))): | |
found = path.dirname(src) + "/" + name | |
else: | |
if (path.basename(name) in os.listdir(path.dirname(name))): | |
found = name | |
return found | |
known = {} | |
def findandcheck(src, parent, element, attribute): | |
for tag in parent: | |
if (tag.tag == element): | |
if not (attribute in tag.attrib): | |
print("\033[91m[ERR!]\033[0m: Tag <" + tag.tag + "> is missing attribute " + attribute + " in " + src) | |
continue | |
texture = tag.attrib[attribute] | |
if not (texture in known) and (findres(src, texture) is None): | |
ignorecase = None | |
if (path.dirname(texture) != ""): | |
if (path.dirname(texture) == path.dirname(src)): | |
print("\033[93m[WARN]\033[0m: Path \"" + texture + "\" can be relative in " + src) | |
ignorecase = tryfind(path.dirname(texture), path.basename(texture)) | |
else: | |
ignorecase = tryfind(path.dirname(src), texture) | |
if (ignorecase is None): | |
print("\033[91m[ERR!]\033[0m: Missing file " + texture + " in " + src) | |
else: | |
print("\033[91m[ERR!]\033[0m: File \"" + texture + "\" was found, but it has incorrect case (should be \"" + ignorecase + "\") in " + src) | |
known[texture] = True | |
else: | |
findandcheck(src, tag, element, attribute) | |
def parsedef(src): | |
if (not path.exists(src)): | |
raise FileNotFoundError("File \"" + src + "\" does not exist!") | |
return | |
print("Parsing \"" + src + "\":") | |
tree = ET.parse(src) | |
root = tree.getroot() | |
findandcheck(src, root, "Sprite", "texture") | |
findandcheck(src, root, "sprite", "texture") | |
findandcheck(src, root, "Blip", "texture") | |
findandcheck(src, root, "ScreenOverlay", "texture") | |
findandcheck(src, root, "sound", "file") | |
for child in root: | |
if (child.tag == "Executable"): | |
continue | |
if ("file" in child.attrib): | |
parsedef(child.attrib["file"]) | |
else: | |
print("\033[91m[ERR!]\033[0m: tag <" + child.tag + "> is missing file attribute!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment