Rev 438: Merge trunk and resolve NEWS conflict. in http://bazaar.launchpad.net/~jameinel/loggerhead/authors-733015

John Arbash Meinel john at arbash-meinel.com
Wed Mar 16 12:24:14 UTC 2011


At http://bazaar.launchpad.net/~jameinel/loggerhead/authors-733015

------------------------------------------------------------
revno: 438 [merge]
revision-id: john at arbash-meinel.com-20110316122406-xdv5771vlih6s76q
parent: john at arbash-meinel.com-20110311105747-65idldqa8bor92cl
parent: john at arbash-meinel.com-20110316122136-930ttoriqgbw2cy3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: authors-733015
timestamp: Wed 2011-03-16 13:24:06 +0100
message:
  Merge trunk and resolve NEWS conflict.
modified:
  Makefile                       makefile-20061224064204-olufa1zdngeefbi1-2
  NEWS                           news-20070121024650-6cwmhprgtcegpxvm-1
  __init__.py                    __init__.py-20090123174919-ekabddqbmvwuci2i-1
  loggerhead/apps/transport.py   wsgitest.py-20080612051902-5y0zpdi6fhxgun6z-1
  loggerhead/config.py           config.py-20090331163436-x6habdrjtdq2pvxg-1
  loggerhead/controllers/__init__.py __init__.py-20061211064342-102iqirsciyvgtcf-17
  loggerhead/controllers/inventory_ui.py inventory_ui.py-20061212203332-s4vehyfs3tn6zm31-1
  loggerhead/controllers/view_ui.py annotate_ui.py-20061213025409-n0tuh5u7v7kwnmd5-1
  loggerhead/main.py             servebranches.py-20080618011543-s6ydx5c3bl38zap6-1
  loggerhead/tests/test_controllers.py test_controllers.py-20090210051739-5d14nlvjvn2ep4x5-1
  loggerhead/tests/test_simple.py test_simple.py-20070523103003-hrxwg5n1hcebw7l6-1
  loggerhead/wholehistory.py     graphcache.py-20080630085128-vjt0vaigp70he531-1
  loggerhead/zptsupport.py       zptsupport.py-20070629104744-hxhwg7x016jnmjit-7
-------------- next part --------------
=== modified file 'Makefile'
--- a/Makefile	2007-10-29 16:19:30 +0000
+++ b/Makefile	2011-03-14 08:47:03 +0000
@@ -8,5 +8,4 @@
 	rm -rf dist/
 
 check:
-	# XXX MichaelHudson 2007-10-29 bug=158361: We can't run the loggerhead
-	# tests in PQM yet :(
+	BZR_PLUGINS_AT=loggerhead@$$(pwd) bzr selftest -s bp.loggerhead

=== modified file 'NEWS'
--- a/NEWS	2011-03-11 10:57:47 +0000
+++ b/NEWS	2011-03-16 12:24:06 +0000
@@ -16,6 +16,9 @@
     - Merge the pqm changes back into trunk, after trunk was reverted to an old
       revision. (John Arbash Meinel, #716152)
 
+    - Redirect ``/files/file.txt`` to ``/view/file.txt`` and ``/view/dir`` to
+      ``/files/dir``. (Jasper St. Pierre, #569358)
+
     - Remove ``start-loggerhead`` and ``stop-loggerhead`` which were already
       deprecated. (John Arbash Meinel)
 

=== modified file '__init__.py'
--- a/__init__.py	2011-02-10 01:57:32 +0000
+++ b/__init__.py	2011-03-16 11:40:05 +0000
@@ -49,17 +49,6 @@
     HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
             (DEFAULT_PORT,))
 
-    def setup_logging(config):
-        import logging
-        import sys
-
-        logger = logging.getLogger('loggerhead')
-        handler = logging.StreamHandler(sys.stderr)
-        handler.setLevel(logging.DEBUG)
-        logger.addHandler(handler)
-        logging.getLogger('simpleTAL').addHandler(handler)
-        logging.getLogger('simpleTALES').addHandler(handler)
-
     def _ensure_loggerhead_path():
         """Ensure that you can 'import loggerhead' and get the root."""
         # loggerhead internal code will try to 'import loggerhead', so
@@ -78,6 +67,7 @@
 
         from loggerhead.apps.transport import BranchesFromTransportRoot
         from loggerhead.config import LoggerheadConfig
+        from loggerhead.main import setup_logging
 
         if host is None:
             host = DEFAULT_HOST
@@ -87,7 +77,7 @@
         if not transport.is_readonly():
             argv.insert(0, '--allow-writes')
         config = LoggerheadConfig(argv)
-        setup_logging(config)
+        setup_logging(config, init_logging=False, log_file=sys.stderr)
         app = BranchesFromTransportRoot(transport.base, config)
         app = HTTPExceptionHandler(app)
         serve(app, host=host, port=port)

=== modified file 'loggerhead/apps/transport.py'
--- a/loggerhead/apps/transport.py	2010-05-05 18:35:35 +0000
+++ b/loggerhead/apps/transport.py	2011-03-16 11:40:05 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008, 2009 Canonical Ltd.
+# Copyright (C) 2008-2011 Canonical Ltd.
 #
 # 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

=== modified file 'loggerhead/config.py'
--- a/loggerhead/config.py	2010-04-13 23:35:01 +0000
+++ b/loggerhead/config.py	2010-05-12 14:38:05 +0000
@@ -49,6 +49,12 @@
     parser.add_option("--protocol", dest="protocol",
                       help=("Protocol to use: http, scgi, fcgi, ajp"
                            "(defaults to http)."))
+    parser.add_option("--log-level", default=None, action='callback',
+                      callback=_optparse_level_to_int_level,
+                      type="string",
+                      help="Set the verbosity of logging. Can either"
+                           " be set to a numeric or string"
+                           " (eg, 10=debug, 30=warning)")
     parser.add_option("--memory-profile", action="store_true",
                       help="Profile the memory usage using Dozer.")
     parser.add_option("--prefix", dest="user_prefix",
@@ -72,6 +78,29 @@
     return parser
 
 
+_log_levels = {
+    'debug': 10,
+    'info': 20,
+    'warning': 30,
+    'error': 40,
+    'critical': 50,
+}
+
+def _optparse_level_to_int_level(option, opt_str, value, parser):
+    parser.values.log_level = _level_to_int_level(value)
+
+
+def _level_to_int_level(value):
+    """Convert a string level to an integer value."""
+    if value is None:
+        return None
+    try:
+        return int(value)
+    except ValueError:
+        pass
+    return _log_levels[value.lower()]
+
+
 class LoggerheadConfig(object):
     """A configuration object."""
 
@@ -99,6 +128,10 @@
         else:
             return cmd_config
 
+    def get_log_level(self):
+        opt = self.get_option('log_level')
+        return _level_to_int_level(opt)
+
     def get_arg(self, index):
         """Get an arg from the arg list."""
         return self._args[index]

=== modified file 'loggerhead/controllers/__init__.py'
--- a/loggerhead/controllers/__init__.py	2011-02-10 17:01:10 +0000
+++ b/loggerhead/controllers/__init__.py	2011-03-16 11:40:05 +0000
@@ -94,7 +94,7 @@
 
         vals.update(self.get_values(path, kwargs, headers))
 
-        self.log.info('Getting information for %s: %r secs' % (
+        self.log.info('Getting information for %s: %.3f secs' % (
             self.__class__.__name__, time.time() - z))
         if 'Content-Type' not in headers:
             headers['Content-Type'] = 'text/html'
@@ -108,7 +108,7 @@
         template.expand_into(w, **vals)
         w.flush()
         self.log.info(
-            'Rendering %s: %r secs, %s bytes' % (
+            'Rendering %s: %.3f secs, %s bytes' % (
                 self.__class__.__name__, time.time() - z, w.bytes))
         return []
 

=== modified file 'loggerhead/controllers/inventory_ui.py'
--- a/loggerhead/controllers/inventory_ui.py	2009-03-19 00:44:05 +0000
+++ b/loggerhead/controllers/inventory_ui.py	2011-03-12 17:15:08 +0000
@@ -22,7 +22,7 @@
 import posixpath
 import urllib
 
-from paste.httpexceptions import HTTPNotFound
+from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
 
 from bzrlib import errors
 from bzrlib.revision import is_null as is_null_rev
@@ -45,7 +45,7 @@
 
     template_path = 'loggerhead.templates.inventory'
 
-    def get_filelist(self, inv, path, sort_type):
+    def get_filelist(self, inv, path, sort_type, revno_url):
         """
         return the list of all files (and their attributes) within a given
         path subtree.
@@ -58,6 +58,9 @@
         dir_ie = inv[file_id]
         file_list = []
 
+        if dir_ie.kind != 'directory':
+            raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
+
         revid_set = set()
 
         for filename, entry in dir_ie.children.iteritems():
@@ -150,7 +153,7 @@
 
             # Create breadcrumb trail for the path within the branch
             branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
-            filelist = self.get_filelist(rev_tree.inventory, path, sort_type)
+            filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
         else:
             start_revid = None
             change = None

=== modified file 'loggerhead/controllers/view_ui.py'
--- a/loggerhead/controllers/view_ui.py	2010-12-01 08:30:02 +0000
+++ b/loggerhead/controllers/view_ui.py	2011-03-12 17:15:08 +0000
@@ -25,7 +25,7 @@
 import bzrlib.textfile
 import bzrlib.osutils
 
-from paste.httpexceptions import HTTPBadRequest, HTTPServerError
+from paste.httpexceptions import HTTPBadRequest, HTTPServerError, HTTPMovedPermanently
 
 from loggerhead.controllers import TemplatedBranchView
 try:
@@ -120,6 +120,9 @@
             raise HTTPServerError('Could not fetch changes')
         branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')
 
+        if inv[file_id].kind == "directory":
+            raise HTTPMovedPermanently(self._branch.context_url(['/files', revno_url, path]))
+
         return {
             # In AnnotateUI, "annotated" is a generator giving revision
             # numbers per lines, but the template checks if "annotated" is

=== modified file 'loggerhead/main.py'
--- a/loggerhead/main.py	2009-11-27 18:30:24 +0000
+++ b/loggerhead/main.py	2011-03-16 11:39:27 +0000
@@ -56,21 +56,39 @@
     return config, base
 
 
-def setup_logging(config):
-    logging.basicConfig()
-    logging.getLogger('').setLevel(logging.DEBUG)
+def setup_logging(config, init_logging=True, log_file=None):
+    log_level = config.get_log_level()
+    if init_logging:
+        logging.basicConfig()
+        if log_level is not None:
+            logging.getLogger('').setLevel(log_level)
     logger = logging.getLogger('loggerhead')
-    if config.get_option('log_folder'):
-        logfile_path = os.path.join(
-            config.get_option('log_folder'), 'serve-branches.log')
+    if log_level is not None:
+        logger.setLevel(log_level)
+    if log_file is not None:
+        handler = logging.StreamHandler(log_file)
     else:
-        logfile_path = 'serve-branches.log'
-    logfile = logging.FileHandler(logfile_path, 'a')
-    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)s:'
-                                  ' %(message)s')
-    logfile.setFormatter(formatter)
-    logfile.setLevel(logging.DEBUG)
-    logger.addHandler(logfile)
+        if config.get_option('log_folder'):
+            logfile_path = os.path.join(
+                config.get_option('log_folder'), 'serve-branches.log')
+        else:
+            logfile_path = 'serve-branches.log'
+        handler = logging.FileHandler(logfile_path, 'a')
+        formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)s:'
+                                      ' %(message)s')
+        handler.setFormatter(formatter)
+    # We set the handler to accept all messages, the *logger* won't emit them
+    # if it is configured to suppress it
+    handler.setLevel(logging.DEBUG)
+    logger.addHandler(handler)
+    def _restrict_logging(logger_name):
+        logger = logging.getLogger(logger_name)
+        if logger.getEffectiveLevel() < logging.INFO:
+            logger.setLevel(logging.INFO)
+    # simpleTAL is *very* verbose in DEBUG mode, which is otherwise the
+    # default. So quiet it up a bit.
+    _restrict_logging('simpleTAL')
+    _restrict_logging('simpleTALES')
     return logger
 
 

=== modified file 'loggerhead/tests/test_controllers.py'
--- a/loggerhead/tests/test_controllers.py	2011-02-10 17:01:10 +0000
+++ b/loggerhead/tests/test_controllers.py	2011-03-15 02:56:59 +0000
@@ -47,7 +47,7 @@
         bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
             ['filename'])
         inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
-        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
+        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename', 'head')))
 
     def test_smoke(self):
         bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(

=== modified file 'loggerhead/tests/test_simple.py'
--- a/loggerhead/tests/test_simple.py	2011-03-10 14:22:12 +0000
+++ b/loggerhead/tests/test_simple.py	2011-03-15 10:24:40 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2011 Canonical Ltd.
+# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd.
 #
 # 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
@@ -28,7 +28,7 @@
 
 from loggerhead.apps.branch import BranchWSGIApp
 from paste.fixture import TestApp
-from paste.httpexceptions import HTTPExceptionHandler
+from paste.httpexceptions import HTTPExceptionHandler, HTTPMovedPermanently
 
 
 
@@ -170,6 +170,33 @@
         res = app.get('/changes', status=404)
 
 
+class TestControllerRedirects(BasicTests):
+    """
+    Test that a file under /files redirects to /view,
+    and a directory under /view redirects to /files.
+    """
+
+    def setUp(self):
+        BasicTests.setUp(self)
+        self.createBranch()
+        self.build_tree(('file', 'folder/', 'folder/file'))
+        self.tree.smart_add([])
+        self.tree.commit('')
+
+    def test_view_folder(self):
+        app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
+
+        e = self.assertRaises(HTTPMovedPermanently, app.get, '/view/head:/folder')
+        self.assertEqual(e.location(), '/files/head:/folder')
+
+    def test_files_file(self):
+        app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
+
+        e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/folder/file')
+        self.assertEqual(e.location(), '/view/head:/folder/file')
+        e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/file')
+        self.assertEqual(e.location(), '/view/head:/file')
+
 #class TestGlobalConfig(BasicTests):
 #    """
 #    Test that global config settings are respected

=== modified file 'loggerhead/wholehistory.py'
--- a/loggerhead/wholehistory.py	2009-10-21 14:40:23 +0000
+++ b/loggerhead/wholehistory.py	2010-04-26 19:37:26 +0000
@@ -80,6 +80,6 @@
             if revid not in c[1]:
                 c[1] = c[1] + (revid,)
 
-    log.info('built revision graph cache: %r secs' % (time.time() - z,))
+    log.info('built revision graph cache: %.3f secs' % (time.time() - z,))
 
     return (_rev_info, _rev_indices)

=== modified file 'loggerhead/zptsupport.py'
--- a/loggerhead/zptsupport.py	2009-03-02 05:44:20 +0000
+++ b/loggerhead/zptsupport.py	2010-05-12 15:01:44 +0000
@@ -23,10 +23,6 @@
 
 from simpletal import simpleTAL, simpleTALES
 
-logging.getLogger("simpleTAL").setLevel(logging.INFO)
-logging.getLogger("simpleTALES").setLevel(logging.INFO)
-
-
 _zpt_cache = {}
 
 



More information about the bazaar-commits mailing list