-
-
Save zinglax/9612715 to your computer and use it in GitHub Desktop.
Generates a test file for MeeshQuest veeeerrry easy
This file contains hidden or 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
1024 1024 1 4 | |
city A 100 100 | |
city B 1020 1020 | |
city C 100 1020 | |
city Cp 450 900 | |
city D 800 500 | |
city E 100 1021 | |
city F 2048 1023 | |
city G 2048 1000 | |
road A B | |
road A C | |
road A D | |
savemap before | |
delete A | |
savemap after |
This file contains hidden or 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 sys | |
from xml.dom import minidom | |
# ***NOTE***: input file should have no extra blank lines! | |
_IMPL = minidom.getDOMImplementation() | |
_ROOT_ATTRS = { | |
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", | |
"xsi:noNamespaceSchemaLocation": "part2in.xsd" | |
} | |
class Commands(object): | |
def do_city(self, doc, name, x, y): | |
me = doc.createElement("createCity") | |
me.setAttribute("name", name) | |
me.setAttribute("x", x) | |
me.setAttribute("y", y) | |
me.setAttribute("radius", "5") | |
me.setAttribute("color", "black") | |
return me | |
def do_mapCity(self, doc, name): | |
me = doc.createElement("mapCity") | |
me.setAttribute("name", name) | |
return me | |
def do_printTree(self, doc, id_num): | |
me = doc.createElement("printPMQuadtree") | |
me.setAttribute("id", id_num) | |
return me | |
def do_road(self, doc, start, end): | |
me = doc.createElement("mapRoad") | |
me.setAttribute("start", start) | |
me.setAttribute("end", end) | |
return me | |
def do_savemap(self, doc, name): | |
me = doc.createElement("saveMap") | |
me.setAttribute("name", name) | |
return me | |
def do_delete(self, doc, name): | |
me = doc.createElement("deleteCity") | |
me.setAttribute("name", name) | |
return me | |
def main(f): | |
doc = _IMPL.createDocument(None, "commands", None) | |
id = 1 | |
root = doc.documentElement | |
for (name, attr) in _ROOT_ATTRS.items(): | |
root.setAttribute(name, attr) | |
cmd_attrs = f.readline().split() | |
# first line should be WIDTH HEIGHT PMORDER LEAFORDER | |
# space-separated, in that order | |
root.setAttribute("spatialWidth", cmd_attrs[0]) | |
root.setAttribute("spatialHeight", cmd_attrs[1]) | |
root.setAttribute("pmOrder", cmd_attrs[2]) | |
root.setAttribute("g", cmd_attrs[3]) | |
c = Commands() | |
for line in f: | |
args = line.split() | |
cmd = args.pop(0) | |
fname = "do_" + cmd | |
if hasattr(c, fname): | |
fn = getattr(c, fname) | |
elt = fn(doc, *args) | |
else: | |
elt = doc.createElement(cmd) | |
elt.setAttribute("id", str(id)) | |
id += 1 | |
root.appendChild(elt) | |
print(doc.toprettyxml()) | |
if __name__ == '__main__': | |
with open(sys.argv[1], "r") as f: | |
main(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment