Add function reversed for python < 2.4
[docutils/kirr.git] / sandbox / py-rest-doc / sphinx-web.py
blob02e722f6cd7fa6a2fe775c1765040c0aaf6b959a
1 # -*- coding: utf-8 -*-
2 """
3 Sphinx - Python documentation webserver
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 :copyright: 2007 by Armin Ronacher.
7 :license: Python license.
8 """
9 import os
10 import sys
11 import getopt
13 import sphinx
14 from sphinx.web.application import setup_app
15 from sphinx.web.serve import run_simple
17 try:
18 from werkzeug.debug import DebuggedApplication
19 except ImportError:
20 DebuggedApplication = lambda x, y: x
23 def main(argv):
24 opts, args = getopt.getopt(argv[1:], "dhf:")
25 opts = dict(opts)
26 if len(args) != 1 or '-h' in opts:
27 print 'usage: %s [-d] [-f cfg.py] <doc_root>' % argv[0]
28 print ' -d: debug mode, use werkzeug debugger if installed'
29 print ' -f: use "cfg.py" file instead of doc_root/webconf.py'
30 return 2
32 conffile = opts.get('-f', os.path.join(args[0], 'webconf.py'))
33 config = {}
34 execfile(conffile, config)
36 port = config.get('listen_port', 3000)
37 hostname = config.get('listen_addr', 'localhost')
38 debug = ('-d' in opts) or (hostname == 'localhost')
40 config['data_root_path'] = args[0]
41 config['debug'] = debug
43 def make_app():
44 app = setup_app(config, check_superuser=True)
45 if debug:
46 app = DebuggedApplication(app, True)
47 return app
49 if os.environ.get('RUN_MAIN') != 'true':
50 print '* Sphinx %s- Python documentation web application' % \
51 sphinx.__version__.replace('$', '').replace('Revision:', 'rev.')
52 if debug:
53 print '* Running in debug mode'
55 run_simple(hostname, port, make_app, use_reloader=debug)
58 if __name__ == '__main__':
59 sys.exit(main(sys.argv))