annotate hgwebsite.py @ 401:4d4c4b73808e

Use absolute paths
author David Soria Parra <dsp@php.net>
date Sat, 08 Mar 2014 02:03:33 +0000
parents 20cfd68e9c49
children 4dfad479ee98
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
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
9 app = flask.Flask(__name__)
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')
400
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
23 if not os.path.exists(tpath):
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
24 flask.abort(404)
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
25 t = os.path.join(site, 'index.html')
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
26 return flask.render_template(t)
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
27
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
28
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
29 if os.getenv("HGWEBSITE_DEBUG", None):
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
30 app.debug = True
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 __name__ == '__main__':
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
33 app.run()