~loggerhead-team/loggerhead/experimental

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-11 14:55:55 UTC
  • mfrom: (419.2.26 loggerhead)
  • Revision ID: john@arbash-meinel.com-20110411145555-7xflzcipb32kuknh
Merge trunk into the history-db branch.

We had to disable the mainline tests, because they were monkey-patching
a parameter that we have removed. We need to figure out a way to
do a similar test.

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
 
        log_level = config.get_log_level()
58
 
        if log_level is not None:
59
 
            logger.setLevel(log_level)
60
 
        handler = logging.StreamHandler(sys.stderr)
61
 
        handler.setLevel(logging.DEBUG)
62
 
        logger.addHandler(handler)
63
 
        logging.getLogger('simpleTAL').addHandler(handler)
64
 
        logging.getLogger('simpleTALES').addHandler(handler)
65
 
        def _restrict_logging(logger_name):
66
 
            logger = logging.getLogger(logger_name)
67
 
            if logger.getEffectiveLevel() < logging.INFO:
68
 
                logger.setLevel(logging.INFO)
69
 
        # simpleTAL is *very* verbose in DEBUG mode, which is otherwise the
70
 
        # default. So quiet it up a bit.
71
 
        _restrict_logging('simpleTAL')
72
 
        _restrict_logging('simpleTALES')
73
 
 
74
 
 
75
 
 
76
54
    def _ensure_loggerhead_path():
77
55
        """Ensure that you can 'import loggerhead' and get the root."""
78
56
        # loggerhead internal code will try to 'import loggerhead', so
84
62
            sys.path.append(os.path.dirname(__file__))
85
63
 
86
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
87
69
        from paste.httpexceptions import HTTPExceptionHandler
88
70
        from paste.httpserver import serve
89
71
 
90
72
        _ensure_loggerhead_path()
91
73
 
 
74
        from loggerhead.apps.http_head import HeadMiddleware
92
75
        from loggerhead.apps.transport import BranchesFromTransportRoot
93
76
        from loggerhead.config import LoggerheadConfig
 
77
        from loggerhead.main import setup_logging
94
78
 
95
79
        if host is None:
96
80
            host = DEFAULT_HOST
100
84
        if not transport.is_readonly():
101
85
            argv.insert(0, '--allow-writes')
102
86
        config = LoggerheadConfig(argv)
103
 
        setup_logging(config)
 
87
        setup_logging(config, init_logging=False, log_file=sys.stderr)
104
88
        app = BranchesFromTransportRoot(transport.base, config)
 
89
        app = HeadMiddleware(app)
105
90
        app = HTTPExceptionHandler(app)
106
91
        serve(app, host=host, port=port)
107
92