Mercurial > hg > svgsitemap
annotate 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 |
| 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 |
| 23 | 35 def main(args=sys.argv[1:]): |
| 36 """CLI""" | |
| 37 | |
| 38 # parse command line options | |
| 39 parser = argparse.ArgumentParser(description=__doc__) | |
| 24 | 40 options = parser.parse_args(args) |
|
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
41 |
|
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
42 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
|
43 server.serve_forever() |
|
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
44 |
| 0 | 45 if __name__ == '__main__': |
|
22
1b077cb84be5
make the example more of a real program
Jeff Hammel <k0scist@gmail.com>
parents:
9
diff
changeset
|
46 main() |
