annotate hgwebsite.py @ 400:20cfd68e9c49

Add hgwebsite wsgi handler
author David Soria Parra <davidsp@fb.com>
date Fri, 07 Mar 2014 16:08:01 -0800
parents
children 4d4c4b73808e
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)
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
21 tpath = os.path.join('templates', site, 'index.html')
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
22 if not os.path.exists(tpath):
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
23 flask.abort(404)
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
24 t = os.path.join(site, 'index.html')
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
25 return flask.render_template(t)
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
26
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 if os.getenv("HGWEBSITE_DEBUG", None):
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
29 app.debug = True
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 if __name__ == '__main__':
20cfd68e9c49 Add hgwebsite wsgi handler
David Soria Parra <davidsp@fb.com>
parents:
diff changeset
32 app.run()