Move dul-web's main functionality to web.
authorDave Borowitz <dborowitz@google.com>
Wed, 21 Jul 2010 11:34:59 +0000 (13:34 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 21 Jul 2010 11:34:59 +0000 (13:34 +0200)
NEWS
bin/dul-web
dulwich/web.py

diff --git a/NEWS b/NEWS
index 5cfd441..596b2ee 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -40,7 +40,7 @@
   * dulwich.pack.write_pack_index_v{1,2} now take a file-like object
     rather than a filename. (Jelmer Vernooij)
 
-  * Make dul-daemon a trivial wrapper around server functionality.
+  * Make dul-daemon/dul-web trivial wrappers around server functionality.
     (Dave Borowitz)
 
   * Move reference WSGI handler to web.py. (Dave Borowitz)
index c68a7b2..910356a 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
-import os
-import sys
-from dulwich.log_utils import default_logging_config
-from dulwich.repo import Repo
-from dulwich.server import DictBackend
-from dulwich.web import (
-    logger,
-    HTTPGitApplication,
-    HTTPGitRequestHandler,
-    )
-from wsgiref.simple_server import (
-    make_server,
-    )
+from dulwich.web import main
 
-
-# TODO: allow serving on other addresses/ports via command-line flag
-LISTEN_ADDR=''
-PORT = 8000
-
-
-if __name__ == "__main__":
-    if len(sys.argv) > 1:
-        gitdir = sys.argv[1]
-    else:
-        gitdir = os.getcwd()
-
-    default_logging_config()
-    backend = DictBackend({"/": Repo(gitdir)})
-    app = HTTPGitApplication(backend)
-    server = make_server(LISTEN_ADDR, PORT, app,
-                         handler_class=HTTPGitRequestHandler)
-    logger.info('Listening for HTTP connections on %s:%d', LISTEN_ADDR, PORT)
-    server.serve_forever()
+if __name__ == '__main__':
+    main()
index d1a60d4..f689d18 100644 (file)
@@ -21,6 +21,7 @@
 from cStringIO import StringIO
 import os
 import re
+import sys
 import time
 
 try:
@@ -31,7 +32,11 @@ from dulwich import log_utils
 from dulwich.protocol import (
     ReceivableProtocol,
     )
+from dulwich.repo import (
+    Repo,
+    )
 from dulwich.server import (
+    DictBackend,
     DEFAULT_HANDLERS,
     )
 
@@ -351,6 +356,7 @@ class HTTPGitApplication(object):
 try:
     from wsgiref.simple_server import (
         WSGIRequestHandler,
+        make_server,
         )
 
     class HTTPGitRequestHandler(WSGIRequestHandler):
@@ -365,7 +371,32 @@ try:
 
         def log_error(self, *args):
             logger.error(*args)
+
+
+    def main(argv=sys.argv):
+        """Entry point for starting an HTTP git server."""
+        if len(argv) > 1:
+            gitdir = argv[1]
+        else:
+            gitdir = os.getcwd()
+
+        # TODO: allow serving on other addresses/ports via command-line flag
+        listen_addr=''
+        port = 8000
+
+        log_utils.default_logging_config()
+        backend = DictBackend({'/': Repo(gitdir)})
+        app = HTTPGitApplication(backend)
+        server = make_server(listen_addr, port, app,
+                             handler_class=HTTPGitRequestHandler)
+        logger.info('Listening for HTTP connections on %s:%d', listen_addr,
+                    port)
+        server.serve_forever()
+
 except ImportError:
     # No wsgiref found; don't provide the reference functionality, but leave the
     # rest of the WSGI-based implementation.
-    pass
+    def main(argv=sys.argv):
+        """Stub entry point for failing to start a server without wsgiref."""
+        sys.stderr.write('Sorry, the wsgiref module is required for dul-web.\n')
+        sys.exit(1)