~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Danilo Segan
  • Date: 2011-08-17 12:53:09 UTC
  • mfrom: (454.1.1 bug-718566)
  • Revision ID: danilo@canonical.com-20110817125309-2r1fgcrqt5kr5h43
Remove FileChangeCache to resolve bug #718566 [r=jam].

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
starts a web server to browse the contents of a branch.
31
31
"""
32
32
 
 
33
import sys
 
34
 
33
35
from info import (
34
36
    bzr_plugin_version as version_info,
35
37
    bzr_compatible_versions,
49
51
    HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
50
52
            (DEFAULT_PORT,))
51
53
 
52
 
    def setup_logging(config):
53
 
        import logging
54
 
        import sys
55
 
 
56
 
        logger = logging.getLogger('loggerhead')
57
 
        handler = logging.StreamHandler(sys.stderr)
58
 
        handler.setLevel(logging.DEBUG)
59
 
        logger.addHandler(handler)
60
 
        logging.getLogger('simpleTAL').addHandler(handler)
61
 
        logging.getLogger('simpleTALES').addHandler(handler)
62
 
 
63
54
    def _ensure_loggerhead_path():
64
55
        """Ensure that you can 'import loggerhead' and get the root."""
65
56
        # loggerhead internal code will try to 'import loggerhead', so
71
62
            sys.path.append(os.path.dirname(__file__))
72
63
 
73
64
    def serve_http(transport, host=None, port=None, inet=None):
 
65
        # TODO: if we supported inet to pass requests in and respond to them,
 
66
        #       then it would be easier to test the full stack, but it probably
 
67
        #       means routing around paste.httpserver.serve which probably
 
68
        #       isn't testing the full stack
74
69
        from paste.httpexceptions import HTTPExceptionHandler
75
70
        from paste.httpserver import serve
76
71
 
77
72
        _ensure_loggerhead_path()
78
73
 
 
74
        from loggerhead.apps.http_head import HeadMiddleware
79
75
        from loggerhead.apps.transport import BranchesFromTransportRoot
80
76
        from loggerhead.config import LoggerheadConfig
 
77
        from loggerhead.main import setup_logging
81
78
 
82
79
        if host is None:
83
80
            host = DEFAULT_HOST
87
84
        if not transport.is_readonly():
88
85
            argv.insert(0, '--allow-writes')
89
86
        config = LoggerheadConfig(argv)
90
 
        setup_logging(config)
 
87
        setup_logging(config, init_logging=False, log_file=sys.stderr)
91
88
        app = BranchesFromTransportRoot(transport.base, config)
 
89
        # Bug #758618, HeadMiddleware seems to break HTTPExceptionHandler from
 
90
        # actually sending appropriate return codes to the client. Since nobody
 
91
        # desperately needs HeadMiddleware right now, just ignoring it.
 
92
        # app = HeadMiddleware(app)
92
93
        app = HTTPExceptionHandler(app)
93
94
        serve(app, host=host, port=port)
94
95