annotate hgwebsite.py @ 448:c79d1a115f49

temlpates: update numerous links to wiki
author Anton Shestakov <av6@dwimlabs.net>
date Wed, 23 Mar 2016 13:59:31 +0800
parents b173399d3635
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
400
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
1 #
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
2 # (c) 2014 David Soria Parra <dsp@php.net>
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
3 #
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
4 # This software may be used and distributed according to the terms of the
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
5 # GNU General Public License version 2 or any later version.
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
6 import os
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
7 import flask
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
8
407
8e93934dc587 Route static url directly
David Soria Parra <davidsp@fb.com>
parents: 405
diff changeset
9 app = flask.Flask(__name__, static_url_path='')
400
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
10
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
11
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
12 @app.route('/')
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
13 def indexpage():
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
14 return flask.render_template('frontpage.html')
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
15
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
16
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
17 @app.route('/<site>')
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
18 def about(site=None):
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
19 if not site:
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
20 flask.abort(404)
401
4d4c4b73808e Use absolute paths
David Soria Parra <dsp@php.net>
parents: 400
diff changeset
21 root = os.path.dirname(os.path.abspath(__file__))
4d4c4b73808e Use absolute paths
David Soria Parra <dsp@php.net>
parents: 400
diff changeset
22 tpath = os.path.join(root, 'templates', site, 'index.html')
405
4dfad479ee98 Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents: 401
diff changeset
23 if os.path.exists(tpath):
4dfad479ee98 Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents: 401
diff changeset
24 t = os.path.join(site, 'index.html')
4dfad479ee98 Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents: 401
diff changeset
25 return flask.render_template(t)
4dfad479ee98 Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents: 401
diff changeset
26 spath = os.path.join(root, 'static', site)
4dfad479ee98 Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents: 401
diff changeset
27 if os.path.exists(spath):
4dfad479ee98 Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents: 401
diff changeset
28 return app.send_static_file(site)
4dfad479ee98 Properly serve static files in static/$FILE directly
David Soria Parra <davidsp@fb.com>
parents: 401
diff changeset
29 flask.abort(404)
400
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
30
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
31
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
32 if os.getenv("HGWEBSITE_DEBUG", None):
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
33 app.debug = True
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
34
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
35 if __name__ == '__main__':
435
b173399d3635 thepage: update thepage site with more recent information
David Soria Parra <dsp@experimentalworks.net>
parents: 407
diff changeset
36 app.run(host='0.0.0.0')