dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00090
[PATCH 4/4] Move dul-web's main functionality to web.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: I54a5c821e4cb92e6e71540a9a8bca4ccda89a706
---
bin/dul-web | 35 +++--------------------------------
dulwich/web.py | 33 ++++++++++++++++++++++++++++++++-
2 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/bin/dul-web b/bin/dul-web
index c68a7b2..910356a 100755
--- a/bin/dul-web
+++ b/bin/dul-web
@@ -17,36 +17,7 @@
# 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()
diff --git a/dulwich/web.py b/dulwich/web.py
index da11553..af98755 100644
--- a/dulwich/web.py
+++ b/dulwich/web.py
@@ -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,
ReceivePackHandler,
UploadPackHandler,
DEFAULT_HANDLERS,
@@ -353,6 +358,7 @@ class HTTPGitApplication(object):
try:
from wsgiref.simple_server import (
WSGIRequestHandler,
+ make_server,
)
class HTTPGitRequestHandler(WSGIRequestHandler):
@@ -367,7 +373,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)
--
1.7.0.4
References