Anonymous avatar Anonymous committed f1b9d23

Move web startup code to __init__.py.

Comments (0)

Files changed (2)

     :copyright: 2007 by Armin Ronacher, Georg Brandl.
     :license: Python license.
 """
-import os
+
 import sys
-import getopt
-
-import sphinx
-from sphinx.web.application import setup_app
-from sphinx.web.serve import run_simple
-
-try:
-    from werkzeug.debug import DebuggedApplication
-except ImportError:
-    DebuggedApplication = lambda x, y: x
-
-
-def main(argv):
-    opts, args = getopt.getopt(argv[1:], "dhf:")
-    opts = dict(opts)
-    if len(args) != 1 or '-h' in opts:
-        print 'usage: %s [-d] [-f cfg.py] <doc_root>' % argv[0]
-        print ' -d: debug mode, use werkzeug debugger if installed'
-        print ' -f: use "cfg.py" file instead of doc_root/webconf.py'
-        return 2
-
-    conffile = opts.get('-f', os.path.join(args[0], 'webconf.py'))
-    config = {}
-    execfile(conffile, config)
-
-    port = config.get('listen_port', 3000)
-    hostname = config.get('listen_addr', 'localhost')
-    debug = ('-d' in opts) or (hostname == 'localhost')
-
-    config['data_root_path'] = args[0]
-    config['debug'] = debug
-
-    def make_app():
-        app = setup_app(config, check_superuser=True)
-        if debug:
-            app = DebuggedApplication(app, True)
-        return app
-
-    if os.environ.get('RUN_MAIN') != 'true':
-        print '* Sphinx %s- Python documentation web application' % \
-              sphinx.__version__.replace('$', '').replace('Revision:', 'rev.')
-        if debug:
-            print '* Running in debug mode'
-
-    run_simple(hostname, port, make_app, use_reloader=debug)
-
 
 if __name__ == '__main__':
+    from sphinx.web import main
     sys.exit(main(sys.argv))

sphinx/web/__init__.py

     :copyright: 2007 by Georg Brandl.
     :license: Python license.
 """
+
+import os
+import sys
+import getopt
+
+import sphinx
+from sphinx.web.application import setup_app
+from sphinx.web.serve import run_simple
+
+try:
+    from werkzeug.debug import DebuggedApplication
+except ImportError:
+    DebuggedApplication = lambda x, y: x
+
+
+def main(argv):
+    opts, args = getopt.getopt(argv[1:], "dhf:")
+    opts = dict(opts)
+    if len(args) != 1 or '-h' in opts:
+        print 'usage: %s [-d] [-f cfg.py] <doc_root>' % argv[0]
+        print ' -d: debug mode, use werkzeug debugger if installed'
+        print ' -f: use "cfg.py" file instead of doc_root/webconf.py'
+        return 2
+
+    conffile = opts.get('-f', os.path.join(args[0], 'webconf.py'))
+    config = {}
+    execfile(conffile, config)
+
+    port = config.get('listen_port', 3000)
+    hostname = config.get('listen_addr', 'localhost')
+    debug = ('-d' in opts) or (hostname == 'localhost')
+
+    config['data_root_path'] = args[0]
+    config['debug'] = debug
+
+    def make_app():
+        app = setup_app(config, check_superuser=True)
+        if debug:
+            app = DebuggedApplication(app, True)
+        return app
+
+    if os.environ.get('RUN_MAIN') != 'true':
+        print '* Sphinx %s- Python documentation web application' % \
+              sphinx.__version__.replace('$', '').replace('Revision:', 'rev.')
+        if debug:
+            print '* Running in debug mode'
+
+    run_simple(hostname, port, make_app, use_reloader=debug)
+
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.