Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/websdk/hatta/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to 'websdk/hatta/__main__.py')
-rw-r--r--websdk/hatta/__main__.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/websdk/hatta/__main__.py b/websdk/hatta/__main__.py
new file mode 100644
index 0000000..55b51a1
--- /dev/null
+++ b/websdk/hatta/__main__.py
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+
+from config import read_config
+from wiki import Wiki
+
+# Avoid WSGI errors, see http://mercurial.selenic.com/bts/issue1095
+sys.stdout = sys.__stdout__
+sys.stderr = sys.__stderr__
+
+
+def application(env, start):
+ """Detect that we are being run as WSGI application."""
+
+ global application
+ config = read_config()
+ script_dir = os.path.dirname(os.path.abspath(__file__))
+ if config.get('pages_path') is None:
+ config.set('pages_path', os.path.join(script_dir, 'docs'))
+ wiki = Wiki(config)
+ application = wiki.application
+ return application(env, start)
+
+
+def main(config=None, wiki=None):
+ """Start a standalone WSGI server."""
+
+ config = config or read_config()
+ wiki = wiki or Wiki(config)
+ app = wiki.application
+
+ host, port = (config.get('interface', '0.0.0.0'),
+ int(config.get('port', 8080)))
+ try:
+ from cherrypy import wsgiserver
+ except ImportError:
+ try:
+ from cherrypy import _cpwsgiserver as wsgiserver
+ except ImportError:
+ import wsgiref.simple_server
+ server = wsgiref.simple_server.make_server(host, port, app)
+ try:
+ server.serve_forever()
+ except KeyboardInterrupt:
+ pass
+ return
+ apps = [('', app)]
+ name = wiki.site_name
+ server = wsgiserver.CherryPyWSGIServer((host, port), apps,
+ server_name=name)
+ try:
+ server.start()
+ except KeyboardInterrupt:
+ server.stop()
+
+if __name__ == "__main__":
+ main()