Mercurial > hg > svgsitemap
annotate example/example.py @ 22:1b077cb84be5
make the example more of a real program
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 10 May 2015 20:52:25 -0700 |
parents | aa4eab6dc994 |
children | 6a7fd9f83554 |
rev | line source |
---|---|
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
1 #!/usr/bin/env python |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
2 |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
3 """ |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
4 site map example application |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
5 """ |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
6 |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
7 # imports |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
8 import argparse |
1 | 9 import os |
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
10 import sys |
0 | 11 from svgsitemap import * |
12 from webob import Request, Response | |
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
13 from wsgiref import simple_server |
0 | 14 |
15 def example(environ, start_response): | |
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
16 """example WSGI app""" |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
17 |
0 | 18 link = '<a href="/%s">%s</a>' |
19 body = '<br/>'.join([link % (i,i) for i in range(30)]) | |
2 | 20 body = '<html><body><a href="/map">map</a><br/>%s</body></html>' % body |
1 | 21 response = Response(content_type='text/html', body=body) |
0 | 22 return response(environ, start_response) |
23 | |
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
24 |
0 | 25 def factory(): |
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
26 """WSGI app factory""" |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
27 |
1 | 28 dirname = os.path.dirname(os.path.abspath(__file__)) |
29 inifile = os.path.join(dirname, 'example.gv.txt') | |
30 svgfile = os.path.join(dirname, 'example.svg') | |
31 app = MapserverMiddleware(example, svgfile) | |
9
aa4eab6dc994
* dont set node width, height; * move save() to its own function
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
32 app = SVGSiteMap(app, file=inifile, output=svgfile) |
1 | 33 return app |
0 | 34 |
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
35 def main(args=sys.argv[1:]) |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
36 |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
37 server = simple_server.make_server(host='0.0.0.0', port=int(54321), app=factory()) |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
38 server.serve_forever() |
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
39 |
0 | 40 if __name__ == '__main__': |
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
41 main() |