view example/example.py @ 24:099f270654ae

more wip
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 May 2015 21:05:24 -0700
parents 6a7fd9f83554
children
line wrap: on
line source

#!/usr/bin/env python

"""
site map example application
"""

# imports
import argparse
import os
import sys
from svgsitemap import *
from webob import Request, Response
from wsgiref import simple_server

def example(environ, start_response):
    """example WSGI app"""

    link = '<a href="/%s">%s</a>'
    body = '<br/>'.join([link % (i,i) for i in range(30)])
    body = '<html><body><a href="/map">map</a><br/>%s</body></html>' % body
    response = Response(content_type='text/html', body=body)
    return response(environ, start_response)


def factory():
    """WSGI app factory"""

    dirname = os.path.dirname(os.path.abspath(__file__))
    inifile = os.path.join(dirname, 'example.gv.txt')
    svgfile = os.path.join(dirname, 'example.svg')
    app = MapserverMiddleware(example, svgfile)
    app = SVGSiteMap(app, file=inifile, output=svgfile)
    return app

def main(args=sys.argv[1:]):
    """CLI"""

    # parse command line options
    parser = argparse.ArgumentParser(description=__doc__)
    options = parser.parse_args(args)

    server = simple_server.make_server(host='0.0.0.0', port=int(54321), app=factory())
    server.serve_forever()

if __name__ == '__main__':
    main()