Skip to content

Commit

Permalink
Create py bottle file loader
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinLesterSynamedia committed Sep 19, 2016
1 parent de910d8 commit 62dd089
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ map*.bin
process.log*
xml/
*.xml
*.pyc
55 changes: 40 additions & 15 deletions map-bin2xml.py → bin2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,35 @@ def generateXML(dest):
except Exception as e:
print(("Error generating '" + filename + "' : " + str(e)))

#################################################################################################
#################################################################################################
#################################################################################################
#################################################################################################
return filename


def generateJSON(dest):
print (("Need to do it"))


def common(output):
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--source", type=str, required=True, help="uniwar map*.bin file. Wild cards permitted")
parser.add_argument("-d", "--dest", type=str, default=".", help="Optional output folder")

args = parser.parse_args()
#print (args)

parser = argparse.ArgumentParser()
parser.add_argument("-s", "--source", type=str, required=True, help="uniwar map*.bin file. Wild cards permitted")
parser.add_argument("-d", "--dest", type=str, default=".", help="Optional output folder")
maps = glob.glob(args.source)

args = parser.parse_args()
#print (args)
if maps == 0:
print(("No maps found: " + args.source))
exit(0)

maps = glob.glob(args.source)
for m in maps:
if output == "json":
return bin2json(m, args.dest)
else:
return bin2xml(m, args.dest)

if maps == 0:
print(("No maps found: " + args.source))
exit(0)

for m in maps:
def openFile(m):
f = open(m, 'rb')
file_data = f.read()

Expand All @@ -328,5 +338,20 @@ def generateXML(dest):
except Exception as e:
print(("Error parsing file " + m + ": " + str(e)))

generateXML(args.dest)

def bin2xml(file, dest="."):
openFile(file)
return generateXML(dest)


def bin2json(file, dest="."):
openFile(file)
return generateJSON(dest)

#################################################################################################
#################################################################################################
#################################################################################################
#################################################################################################

if __name__ == "__main__":
common("xml")
34 changes: 34 additions & 0 deletions fetch_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import bin2xml
from bottle import *

@route('/')
@route('/info')
@route('/map')
@route('/map/')
@route('/mapid')
@route('/mapid/')
def info():
text = "Use http://url:port/map/[map name] to load a map by name<br>"
text += "Use http://url:port/mapid/[map db id] to load a map by an id<br>"


@route('/map/<name>')
def map(name):
return "Loading '%s'" % name


@route('/map/test')
def map(name):
return static_file("/raidstore/netbeans/uniwar-map/xml/EdTestairisland.xml", root='')


@route('/mapid/<id:int>')
def mapid(id):
binfile = "map.bin.files/map" + str(id) + ".bin"
xmlfile = bin2xml.bin2xml(binfile, 'xml')
print (("Loading '" + xmlfile + "' ( " + binfile + " )"))

return static_file(xmlfile, root='./')


run(host='localhost', port=8080, debug=True)

0 comments on commit 62dd089

Please sign in to comment.