Review:
authorMatt Nordhoff <mnordhoff@mattnordhoff.com>
Mon, 4 May 2009 20:21:08 +0000 (20:21 +0000)
committerMatt Nordhoff <mnordhoff@mattnordhoff.com>
Mon, 4 May 2009 20:21:08 +0000 (20:21 +0000)
* Fix hiding directories that start with "." in DirectoryUI.

* Rename loggerhead.apps.filesystem to loggerhead.apps.transport, along with its classes.

* Fix NEWS syntax and mention bug number.

NEWS
__init__.py
loggerhead/apps/filesystem.py [deleted file]
loggerhead/apps/transport.py [new file with mode: 0644]
loggerhead/controllers/directory_ui.py
serve-branches

diff --git a/NEWS b/NEWS
index ab1e123..22742b9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -50,7 +50,7 @@ dev [future]
       incorrectly and failing). (Matt Nordhoff)
 
     - Use transport API internally, so it is possible to specify a remote 
-         URL to serve-branches. (Jelmer vernooij)
+      URL to serve-branches. (Jelmer vernooij, #371787)
 
 1.10 [22Dec2008]
 ---------------
index 2f543fe..914317b 100644 (file)
@@ -71,10 +71,10 @@ if __name__ == 'bzrlib.plugins.loggerhead':
                 import os.path, sys
                 sys.path.append(os.path.dirname(__file__))
 
-                from loggerhead.apps.filesystem import BranchesFromFileSystemRoot
+                from loggerhead.apps.transport import BranchesFromTransportRoot
                 from paste.httpexceptions import HTTPExceptionHandler
                 from paste.httpserver import serve
-                a = HTTPExceptionHandler(BranchesFromFileSystemRoot('.'))
+                a = HTTPExceptionHandler(BranchesFromTransportRoot('.'))
                 port = kw.get('port', DEFAULT_PORT)
                 # port might be an int already...
                 if isinstance(port, basestring) and ':' in port:
diff --git a/loggerhead/apps/filesystem.py b/loggerhead/apps/filesystem.py
deleted file mode 100644 (file)
index 36e4b37..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-"""Serve branches at urls that mimic the file system layout."""
-
-from bzrlib import branch, errors, lru_cache, urlutils
-
-from paste.request import path_info_pop
-from paste import httpexceptions
-from paste import urlparser
-
-from loggerhead.apps.branch import BranchWSGIApp
-from loggerhead.apps import favicon_app, static_app
-from loggerhead.config import LoggerheadConfig
-from loggerhead.controllers.directory_ui import DirectoryUI
-
-
-class BranchesFromFileSystemServer(object):
-
-    def __init__(self, transport, root, name=None):
-        self.transport = transport
-        self.root = root
-        self.name = name
-        self._config = root._config
-
-    def app_for_branch(self, branch):
-        if not self.name:
-            name = branch.get_config().get_nickname()
-            is_root = True
-        else:
-            name = self.name
-            is_root = False
-        branch_app = BranchWSGIApp(
-            branch, name,
-            {'cachepath': self._config.SQL_DIR},
-            self.root.graph_cache, is_root=is_root,
-            use_cdn=self._config.get_option('use_cdn'))
-        return branch_app.app
-
-    def app_for_non_branch(self, environ):
-        segment = path_info_pop(environ)
-        if segment is None:
-            raise httpexceptions.HTTPMovedPermanently(
-                environ['SCRIPT_NAME'] + '/')
-        elif segment == '':
-            if self.name:
-                name = self.name
-            else:
-                name = '/'
-            return DirectoryUI(environ['loggerhead.static.url'],
-                               self.transport,
-                               name)
-        else:
-            new_transport = self.transport.clone(segment)
-            if self.name:
-                new_name = urlutils.join(self.name, segment)
-            else:
-                new_name = '/' + segment
-            return BranchesFromFileSystemServer(new_transport, self.root, new_name)
-
-    def __call__(self, environ, start_response):
-        try:
-            b = branch.Branch.open_from_transport(self.transport)
-        except errors.NotBranchError:
-            if not self.transport.listable() or not self.transport.has('.'):
-                raise httpexceptions.HTTPNotFound()
-            return self.app_for_non_branch(environ)(environ, start_response)
-        else:
-            return self.app_for_branch(b)(environ, start_response)
-
-
-class BranchesFromFileSystemRoot(object):
-
-    def __init__(self, transport, config):
-        self.graph_cache = lru_cache.LRUCache(10)
-        self.transport = transport
-        self._config = config
-
-    def __call__(self, environ, start_response):
-        environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
-        if environ['PATH_INFO'].startswith('/static/'):
-            segment = path_info_pop(environ)
-            assert segment == 'static'
-            return static_app(environ, start_response)
-        elif environ['PATH_INFO'] == '/favicon.ico':
-            return favicon_app(environ, start_response)
-        elif '/.bzr/' in environ['PATH_INFO']:
-            app = urlparser.make_static(None, self.transport)
-            return app(environ, start_response)
-        else:
-            return BranchesFromFileSystemServer(
-                self.transport, self)(environ, start_response)
-
-
-class UserBranchesFromFileSystemRoot(object):
-
-    def __init__(self, transport, config):
-        self.graph_cache = lru_cache.LRUCache(10)
-        self.transport = transport
-        self._config = config
-        self.trunk_dir = config.get_option('trunk_dir')
-
-    def __call__(self, environ, start_response):
-        environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
-        path_info = environ['PATH_INFO']
-        if path_info.startswith('/static/'):
-            segment = path_info_pop(environ)
-            assert segment == 'static'
-            return static_app(environ, start_response)
-        elif path_info == '/favicon.ico':
-            return favicon_app(environ, start_response)
-        else:
-            # segments starting with ~ are user branches
-            if path_info.startswith('/~'):
-                segment = path_info_pop(environ)
-                new_transport = self.transport.clone(segment[1:])
-                return BranchesFromFileSystemServer(
-                    new_transport, self, segment)(environ, start_response)
-            else:
-                new_transport = self.transport.clone(self.trunk_dir)
-                return BranchesFromFileSystemServer(
-                    new_transport, self)(environ, start_response)
diff --git a/loggerhead/apps/transport.py b/loggerhead/apps/transport.py
new file mode 100644 (file)
index 0000000..1d21313
--- /dev/null
@@ -0,0 +1,119 @@
+"""Serve branches at urls that mimic a transport's file system layout."""
+
+from bzrlib import branch, errors, lru_cache, urlutils
+
+from paste.request import path_info_pop
+from paste import httpexceptions
+from paste import urlparser
+
+from loggerhead.apps.branch import BranchWSGIApp
+from loggerhead.apps import favicon_app, static_app
+from loggerhead.config import LoggerheadConfig
+from loggerhead.controllers.directory_ui import DirectoryUI
+
+
+class BranchesFromTransportServer(object):
+
+    def __init__(self, transport, root, name=None):
+        self.transport = transport
+        self.root = root
+        self.name = name
+        self._config = root._config
+
+    def app_for_branch(self, branch):
+        if not self.name:
+            name = branch.get_config().get_nickname()
+            is_root = True
+        else:
+            name = self.name
+            is_root = False
+        branch_app = BranchWSGIApp(
+            branch, name,
+            {'cachepath': self._config.SQL_DIR},
+            self.root.graph_cache, is_root=is_root,
+            use_cdn=self._config.get_option('use_cdn'))
+        return branch_app.app
+
+    def app_for_non_branch(self, environ):
+        segment = path_info_pop(environ)
+        if segment is None:
+            raise httpexceptions.HTTPMovedPermanently(
+                environ['SCRIPT_NAME'] + '/')
+        elif segment == '':
+            if self.name:
+                name = self.name
+            else:
+                name = '/'
+            return DirectoryUI(environ['loggerhead.static.url'],
+                               self.transport,
+                               name)
+        else:
+            new_transport = self.transport.clone(segment)
+            if self.name:
+                new_name = urlutils.join(self.name, segment)
+            else:
+                new_name = '/' + segment
+            return BranchesFromTransportServer(new_transport, self.root, new_name)
+
+    def __call__(self, environ, start_response):
+        try:
+            b = branch.Branch.open_from_transport(self.transport)
+        except errors.NotBranchError:
+            if not self.transport.listable() or not self.transport.has('.'):
+                raise httpexceptions.HTTPNotFound()
+            return self.app_for_non_branch(environ)(environ, start_response)
+        else:
+            return self.app_for_branch(b)(environ, start_response)
+
+
+class BranchesFromTransportRoot(object):
+
+    def __init__(self, transport, config):
+        self.graph_cache = lru_cache.LRUCache(10)
+        self.transport = transport
+        self._config = config
+
+    def __call__(self, environ, start_response):
+        environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
+        if environ['PATH_INFO'].startswith('/static/'):
+            segment = path_info_pop(environ)
+            assert segment == 'static'
+            return static_app(environ, start_response)
+        elif environ['PATH_INFO'] == '/favicon.ico':
+            return favicon_app(environ, start_response)
+        elif '/.bzr/' in environ['PATH_INFO']:
+            app = urlparser.make_static(None, self.transport)
+            return app(environ, start_response)
+        else:
+            return BranchesFromTransportServer(
+                self.transport, self)(environ, start_response)
+
+
+class UserBranchesFromTransportRoot(object):
+
+    def __init__(self, transport, config):
+        self.graph_cache = lru_cache.LRUCache(10)
+        self.transport = transport
+        self._config = config
+        self.trunk_dir = config.get_option('trunk_dir')
+
+    def __call__(self, environ, start_response):
+        environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
+        path_info = environ['PATH_INFO']
+        if path_info.startswith('/static/'):
+            segment = path_info_pop(environ)
+            assert segment == 'static'
+            return static_app(environ, start_response)
+        elif path_info == '/favicon.ico':
+            return favicon_app(environ, start_response)
+        else:
+            # segments starting with ~ are user branches
+            if path_info.startswith('/~'):
+                segment = path_info_pop(environ)
+                new_transport = self.transport.clone(segment[1:])
+                return BranchesFromTransportServer(
+                    new_transport, self, segment)(environ, start_response)
+            else:
+                new_transport = self.transport.clone(self.trunk_dir)
+                return BranchesFromTransportServer(
+                    new_transport, self)(environ, start_response)
index 135a423..59b8b6f 100644 (file)
@@ -64,7 +64,9 @@ class DirectoryUI(TemplatedBranchView):
         self.log = logging.getLogger('')
 
     def get_values(self, path, kwargs, response):
-        listing = self.transport.list_dir('.')
+        listing = [d for d in self.transport.list_dir('.')
+                   if not d.startswith('.')
+                   and stat.S_ISDIR(self.transport.stat(d).st_mode)]
         listing.sort(key=lambda x: x.lower())
         dirs = []
         parity = 0
@@ -73,8 +75,6 @@ class DirectoryUI(TemplatedBranchView):
                 b = branch.Branch.open_from_transport(self.transport.clone(d))
             except:
                 b = None
-                if not stat.S_ISDIR(self.transport.stat(d).st_mode):
-                    continue
             dirs.append(DirEntry(d, parity, b))
             parity = 1 - parity
         # Create breadcrumb trail
index c08cddb..d8b4979 100755 (executable)
@@ -27,8 +27,8 @@ from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
 from paste.translogger import TransLogger
 
 from loggerhead import __version__
-from loggerhead.apps.filesystem import (
-    BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot)
+from loggerhead.apps.transport import (
+    BranchesFromTransportRoot, UserBranchesFromTransportRoot)
 from loggerhead.config import LoggerheadConfig
 from loggerhead.util import Reloader
 from loggerhead.apps.error import ErrorHandlerApp
@@ -67,9 +67,9 @@ def main(args):
         if not config.get_option('trunk_dir'):
             print "You didn't specify a directory for the trunk directories."
             sys.exit(1)
-        app = UserBranchesFromFileSystemRoot(transport, config)
+        app = UserBranchesFromTransportRoot(transport, config)
     else:
-        app = BranchesFromFileSystemRoot(transport, config)
+        app = BranchesFromTransportRoot(transport, config)
 
     # setup_logging()
     logging.basicConfig()