~bzr/loggerhead/daily-ppa

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Max Bowsher
  • Date: 2011-03-17 08:33:16 UTC
  • mfrom: (182.150.20 trunk-rich)
  • Revision ID: maxb@f2s.com-20110317083316-n5nq18tsaaxkskut
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009, 2010, 2011 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
 
18
 
# This file allows loggerhead to be treated as a plugin for bzr.
19
 
#
20
 
# XXX: Because loggerhead already contains a loggerhead directory, much of the
21
 
# code is going to appear loaded at bzrlib.plugins.loggerhead.loggerhead.
22
 
# This seems like the easiest thing, because bzrlib wants the top-level plugin
23
 
# directory to be the module, but when it's used as a library people expect
24
 
# the source directory to contain a directory called loggerhead.  -- mbp
 
1
# Copyright 2009, 2010, 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 # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version.  # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the # GNU General Public License for more details.  # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA # This file allows loggerhead to be treated as a plugin for bzr.  # # XXX: Because loggerhead already contains a loggerhead directory, much of the # code is going to appear loaded at bzrlib.plugins.loggerhead.loggerhead.  # This seems like the easiest thing, because bzrlib wants the top-level plugin # directory to be the module, but when it's used as a library people expect # the source directory to contain a directory called loggerhead.  -- mbp
25
2
# 20090123
26
3
 
27
4
"""Loggerhead web viewer for Bazaar branches.
30
7
starts a web server to browse the contents of a branch.
31
8
"""
32
9
 
 
10
import sys
 
11
 
33
12
from info import (
34
13
    bzr_plugin_version as version_info,
35
14
    bzr_compatible_versions,
49
28
    HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
50
29
            (DEFAULT_PORT,))
51
30
 
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
31
    def _ensure_loggerhead_path():
64
32
        """Ensure that you can 'import loggerhead' and get the root."""
65
33
        # loggerhead internal code will try to 'import loggerhead', so
78
46
 
79
47
        from loggerhead.apps.transport import BranchesFromTransportRoot
80
48
        from loggerhead.config import LoggerheadConfig
 
49
        from loggerhead.main import setup_logging
81
50
 
82
51
        if host is None:
83
52
            host = DEFAULT_HOST
87
56
        if not transport.is_readonly():
88
57
            argv.insert(0, '--allow-writes')
89
58
        config = LoggerheadConfig(argv)
90
 
        setup_logging(config)
 
59
        setup_logging(config, init_logging=False, log_file=sys.stderr)
91
60
        app = BranchesFromTransportRoot(transport.base, config)
92
61
        app = HTTPExceptionHandler(app)
93
62
        serve(app, host=host, port=port)