view example/example.py @ 26:ccd73b01ba79 default tip

py3
author Jeff Hammel <k0scist@gmail.com>
date Tue, 03 Nov 2020 10:00:32 -0800
parents 099f270654ae
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()