Преглед на файлове

Merge dul-web into dulwich command.

Jelmer Vernooij преди 10 години
родител
ревизия
989e63744c
променени са 7 файла, в които са добавени 60 реда и са изтрити 26 реда
  1. 5 0
      NEWS
  2. 0 23
      bin/dul-web
  3. 22 0
      bin/dulwich
  4. 23 0
      dulwich/porcelain.py
  5. 8 1
      dulwich/server.py
  6. 1 1
      dulwich/tests/test_server.py
  7. 1 1
      setup.py

+ 5 - 0
NEWS

@@ -18,6 +18,11 @@
 
   * Add 'status' support to bin/dulwich. (Jelmer Vernooij)
 
+ CHANGES
+
+  * dul-web is now available as 'dulwich web-daemon'.
+    (Jelmer Vernooij)
+
 0.9.7	2014-06-08
 
  BUG FIXES

+ 0 - 23
bin/dul-web

@@ -1,23 +0,0 @@
-#!/usr/bin/python
-# dul-web - HTTP-based git server
-# Copyright (C) 2010 Google, Inc. <dborowitz@google.com>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; version 2
-# or (at your option) a later version of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA  02110-1301, USA.
-
-from dulwich.web import main
-
-if __name__ == '__main__':
-    main()

+ 22 - 0
bin/dulwich

@@ -274,6 +274,27 @@ def cmd_daemon(args):
                      port=options.port)
 
 
+def cmd_web_daemon(args):
+    from dulwich import log_utils
+    parser = optparse.OptionParser()
+    parser.add_option("-l", "--listen_address", dest="listen_address",
+                      default="",
+                      help="Binding IP address.")
+    parser.add_option("-p", "--port", dest="port", type=int,
+                      default=8000,
+                      help="Binding TCP port.")
+    options, args = parser.parse_args(args)
+
+    log_utils.default_logging_config()
+    if len(args) >= 1:
+        gitdir = args[0]
+    else:
+        gitdir = '.'
+    from dulwich import porcelain
+    porcelain.daemon(gitdir, address=options.listen_address,
+                     port=options.port)
+
+
 def cmd_receive_pack(args):
     parser = optparse.OptionParser()
     options, args = parser.parse_args(args)
@@ -345,6 +366,7 @@ commands = {
     "tag": cmd_tag,
     "update-server-info": cmd_update_server_info,
     "upload-pack": cmd_upload_pack,
+    "web-daemon": cmd_web_daemon,
     }
 
 if len(sys.argv) < 2:

+ 23 - 0
dulwich/porcelain.py

@@ -560,6 +560,8 @@ def daemon(path=".", address=None, port=None):
     """Run a daemon serving Git requests over TCP/IP.
 
     :param path: Path to the directory to serve.
+    :param address: Optional address to listen on (defaults to ::)
+    :param port: Optional port to listen on (defaults to TCP_GIT_PORT)
     """
     # TODO(jelmer): Support git-daemon-export-ok and --export-all.
     backend = FileSystemBackend(path)
@@ -567,6 +569,27 @@ def daemon(path=".", address=None, port=None):
     server.serve_forever()
 
 
+def web_daemon(path=".", address=None, port=None):
+    """Run a daemon serving Git requests over HTTP.
+
+    :param path: Path to the directory to serve
+    :param address: Optional address to listen on (defaults to ::)
+    :param port: Optional port to listen on (defaults to 80)
+    """
+    from dulwich.web import (
+        make_wsgi_chain,
+        make_server,
+        WSGIRequestHandlerLogger,
+        WSGIServerLogger)
+
+    backend = FileSystemBackend(path)
+    app = make_wsgi_chain(backend)
+    server = make_server(address, port, app,
+                         handler_class=WSGIRequestHandlerLogger,
+                         server_class=WSGIServerLogger)
+    server.serve_forever()
+
+
 def upload_pack(path=".", inf=sys.stdin, outf=sys.stdout):
     """Upload a pack file after negotiating its contents using smart protocol.
 

+ 8 - 1
dulwich/server.py

@@ -162,9 +162,16 @@ class DictBackend(Backend):
 class FileSystemBackend(Backend):
     """Simple backend that looks up Git repositories in the local file system."""
 
+    def __init__(self, root="/"):
+        super(FileSystemBackend, self).__init__()
+        self.root = (os.path.abspath(root) + "/").replace("//", "/")
+
     def open_repository(self, path):
         logger.debug('opening repository at %s', path)
-        return Repo(path)
+        abspath = os.path.abspath(os.path.join(self.root, path)) + "/"
+        if not abspath.startswith(self.root):
+            raise NotGitRepository("Invalid path %r" % path)
+        return Repo(abspath)
 
 
 class Handler(object):

+ 1 - 1
dulwich/tests/test_server.py

@@ -839,7 +839,7 @@ class FileSystemBackendTests(TestCase):
 
     def test_absolute(self):
         repo = self.backend.open_repository(self.path)
-        self.assertEqual(repo.path, self.repo.path)
+        self.assertEqual(os.path.abspath(repo.path), os.path.abspath(self.repo.path))
 
     def test_child(self):
         self.assertRaises(NotGitRepository,

+ 1 - 1
setup.py

@@ -67,7 +67,7 @@ setup(name='dulwich',
       in the particular Monty Python sketch.
       """,
       packages=['dulwich', 'dulwich.tests', 'dulwich.tests.compat', 'dulwich.contrib'],
-      scripts=['bin/dulwich', 'bin/dul-web', 'bin/dul-receive-pack', 'bin/dul-upload-pack'],
+      scripts=['bin/dulwich', 'bin/dul-receive-pack', 'bin/dul-upload-pack'],
       ext_modules=[
           Extension('dulwich._objects', ['dulwich/_objects.c'],
                     include_dirs=include_dirs),