~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: John Arbash Meinel
  • Date: 2011-02-10 23:05:31 UTC
  • mto: This revision was merged to the branch mainline in revision 426.
  • Revision ID: john@arbash-meinel.com-20110210230531-spb87czp526tljp7
Add a NEWS update, and HACKING commentary about the new code.

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
 
 
35
33
from info import (
36
34
    bzr_plugin_version as version_info,
37
35
    bzr_compatible_versions,
51
49
    HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
52
50
            (DEFAULT_PORT,))
53
51
 
 
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
 
54
63
    def _ensure_loggerhead_path():
55
64
        """Ensure that you can 'import loggerhead' and get the root."""
56
65
        # loggerhead internal code will try to 'import loggerhead', so
62
71
            sys.path.append(os.path.dirname(__file__))
63
72
 
64
73
    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
69
74
        from paste.httpexceptions import HTTPExceptionHandler
70
75
        from paste.httpserver import serve
71
76
 
72
77
        _ensure_loggerhead_path()
73
78
 
74
 
        from loggerhead.apps.http_head import HeadMiddleware
75
79
        from loggerhead.apps.transport import BranchesFromTransportRoot
76
80
        from loggerhead.config import LoggerheadConfig
77
 
        from loggerhead.main import setup_logging
78
81
 
79
82
        if host is None:
80
83
            host = DEFAULT_HOST
84
87
        if not transport.is_readonly():
85
88
            argv.insert(0, '--allow-writes')
86
89
        config = LoggerheadConfig(argv)
87
 
        setup_logging(config, init_logging=False, log_file=sys.stderr)
 
90
        setup_logging(config)
88
91
        app = BranchesFromTransportRoot(transport.base, config)
89
 
        app = HeadMiddleware(app)
90
92
        app = HTTPExceptionHandler(app)
91
93
        serve(app, host=host, port=port)
92
94