From 09e183bbe00971b57f29a88431e36ea7139c4e7a Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Fri, 17 May 2013 12:41:41 -0700 Subject: Make the tmx converter update resnametable.txt If/when we use static instancing, we'll have to change this. --- tmx_converter.py | 5 ++++ web/README | 3 +++ web/main.py | 28 ++++++++++++++++++++++ web/with_xml.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 web/README create mode 100755 web/main.py create mode 100644 web/with_xml.py diff --git a/tmx_converter.py b/tmx_converter.py index 17773dc..94cf0b2 100755 --- a/tmx_converter.py +++ b/tmx_converter.py @@ -328,11 +328,13 @@ def main(argv): mob_names[int(k)] = v.strip() npc_master = [] + map_basenames = [] for arg in os.listdir(tmx_dir): base, ext = posixpath.splitext(arg) if ext == '.tmx': + map_basenames.append(base) tmx = posixpath.join(tmx_dir, arg) wlk = posixpath.join(wlk_dir, base + '.wlk') this_map_npc_dir = posixpath.join(npc_dir, base) @@ -344,6 +346,9 @@ def main(argv): xml.sax.parse(tmx, ContentHandler(wlk, this_map_npc_dir, mobs, warps, imports)) npc_master.append('import: %s\n' % posixpath.join(SERVER_NPCS, base, NPC_IMPORTS)) + with open(posixpath.join(wlk_dir, 'resnametable.txt'), 'w') as resname: + for base in sorted(map_basenames): + resname.write('%s.gat#%s.wlk#\n' % (base, base)) with open(posixpath.join(npc_dir, NPC_MASTER_IMPORTS), 'w') as out: out.write('// %s\n\n' % MESSAGE) npc_master.sort() diff --git a/web/README b/web/README new file mode 100644 index 0000000..dc7bc55 --- /dev/null +++ b/web/README @@ -0,0 +1,3 @@ +This is a flask app to manage accounts. + +It implements a full-featured webserver, but is usually proxied by nginx. diff --git a/web/main.py b/web/main.py new file mode 100755 index 0000000..b7501c5 --- /dev/null +++ b/web/main.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python2.6 + +from flask import Flask + +from with_xml import Node + +app = Flask(__name__) + +@app.route('/') +def index(): + content = Node() + tag = content.tag + put = content.put + a = tag('a') + with tag('html'): + with tag('head'): + with tag('title'): + put('Title') + with tag('body'): + with tag('h1'): + put('Header') + put('This is ') + with a(href='http://google.com/'): + put('a link to Google.') + return str(content) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/web/with_xml.py b/web/with_xml.py new file mode 100644 index 0000000..bc49a94 --- /dev/null +++ b/web/with_xml.py @@ -0,0 +1,71 @@ +''' A stupid little way of generating xml +''' + +import re + +from flask import escape + +PRETTY = True + +class Context(object): + __slots__ = ('_node', '_name', '_kwargs') + pattern = re.compile(r'[A-Za-z]\w*') + + def __init__(self, node, name, kwargs): + self._node = node + self._name = name + self._kwargs = kwargs + + def __enter__(self): + _node = self._node + _buffer = _node._buffer + _node.nl() + _buffer.extend(['<', escape(self._name)]) + for k, v in self._kwargs.iteritems(): + assert Context.pattern.match(k) + _buffer.extend([' ', k, '="', escape(v), '"']) + _buffer.append('>') + _node._indent += 1 + _node.nl() + + def __exit__(self, exc_type, exc_value, traceback): + _node = self._node + _buffer = _node._buffer + _node._indent -= 1 + _node.nl() + if _buffer[-1] == '>' and _buffer[-3] != '' + else: + _buffer.extend(['']) + _node.nl() + + def __call__(_self, **kwargs): + new_kwargs = dict(_self._kwargs) + new_kwargs.update(kwargs) + return Context(_self._node, _self._name, new_kwargs) + +class Node(object): + __slots__ = ('_buffer', '_indent') + + def __init__(self): + self._buffer = ['', '\n', ''] + self._indent = 0 + + def tag(_self, _name, **kwargs): + return Context(_self, _name, kwargs) + + + def put(self, text): + self._buffer.append(escape(text)) + + def __str__(self): + return ''.join(self._buffer) + + def nl(self): + if PRETTY: + _buffer = self._buffer + if _buffer[-2] == '\n': + _buffer.pop() + else: + _buffer.append('\n') + _buffer.extend([' ' * self._indent]) -- cgit v1.2.3-70-g09d2