~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Michael Hudson
  • Date: 2009-04-01 14:40:05 UTC
  • Revision ID: michael.hudson@canonical.com-20090401144005-trxdnfy5hd5wrd39
a quick dose of IE compatibility:
* ''.splice behaves differently
* io-queue doesn't seem to work, but isn't useful for me anyway...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
 
#
3
 
# Copyright (C) 2008, 2009 Canonical Ltd
4
 
#
5
2
# This program is free software; you can redistribute it and/or modify
6
3
# it under the terms of the GNU General Public License as published by
7
4
# the Free Software Foundation; either version 2 of the License, or
23
20
import sys
24
21
 
25
22
from bzrlib.plugin import load_plugins
26
 
from bzrlib.transport import get_transport
27
23
 
28
24
from paste import httpserver
29
25
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
30
26
from paste.translogger import TransLogger
31
27
 
32
28
from loggerhead import __version__
33
 
from loggerhead.apps.transport import (
34
 
    BranchesFromTransportRoot, UserBranchesFromTransportRoot)
 
29
from loggerhead.apps.filesystem import (
 
30
    BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot)
35
31
from loggerhead.config import LoggerheadConfig
36
32
from loggerhead.util import Reloader
37
33
from loggerhead.apps.error import ErrorHandlerApp
48
44
        config.print_help()
49
45
        sys.exit(1)
50
46
    elif config.arg_count == 1:
51
 
        path = config.get_arg(0)
 
47
        [path] = args
52
48
    else:
53
49
        path = '.'
54
50
 
55
 
    load_plugins()
56
 
 
57
 
    if config.get_option('allow_writes'):
58
 
        transport = get_transport(path)
59
 
    else:
60
 
        transport = get_transport('readonly+' + path)
 
51
    if not os.path.isdir(path):
 
52
        print "%s is not a directory" % path
 
53
        sys.exit(1)
61
54
 
62
55
    if config.get_option('trunk_dir') and not config.get_option('user_dirs'):
63
56
        print "--trunk-dir is only valid with --user-dirs"
70
63
            return Reloader.restart_with_reloader()
71
64
 
72
65
    if config.get_option('user_dirs'):
73
 
        if not config.get_option('trunk_dir'):
 
66
        if not config.get_option['trunk_dir']:
74
67
            print "You didn't specify a directory for the trunk directories."
75
68
            sys.exit(1)
76
 
        app = UserBranchesFromTransportRoot(transport, config)
 
69
        app = UserBranchesFromFileSystemRoot(
 
70
            path, config.get_option('trunk_dir'))
77
71
    else:
78
 
        app = BranchesFromTransportRoot(transport, config)
 
72
        app = BranchesFromFileSystemRoot(path)
79
73
 
80
74
    # setup_logging()
81
75
    logging.basicConfig()
83
77
    logger = getattr(app, 'log', logging.getLogger('loggerhead'))
84
78
    if config.get_option('log_folder'):
85
79
        logfile_path = os.path.join(
86
 
            config.get_option('log_folder'), 'serve-branches.log')
 
80
            config.get_option['log_folder'], 'serve-branches.log')
87
81
    else:
88
82
        logfile_path = 'serve-branches.log'
89
83
    logfile = logging.FileHandler(logfile_path, 'a')
93
87
    logfile.setLevel(logging.DEBUG)
94
88
    logger.addHandler(logfile)
95
89
 
 
90
    if config.get_option('memory_profile'):
 
91
        memprofile = logging.getLogger('loggerhead-memprofile')
 
92
        memprofile.setLevel(logging.DEBUG)
 
93
        memprofile.addHandler(logging.FileHandler('loggerhead-memprofile'))
 
94
 
96
95
    # setup_logging() #end
97
96
 
 
97
    app = TransLogger(app, logger=logger)
98
98
    if config.get_option('profile'):
99
99
        from loggerhead.middleware.profile import LSProfMiddleware
100
100
        app = LSProfMiddleware(app)
101
101
    if config.get_option('memory_profile'):
102
 
        from dozer import Dozer
103
 
        app = Dozer(app)
 
102
        from loggerhead.middleware.profile import MemoryProfileMiddleware
 
103
        app = MemoryProfileMiddleware(app)
104
104
 
105
105
    if not config.get_option('user_prefix'):
106
106
        prefix = '/'
129
129
 
130
130
    app = HTTPExceptionHandler(app)
131
131
    app = ErrorHandlerApp(app)
132
 
    app = TransLogger(app, logger=logger)
133
132
 
134
133
    if not config.get_option('user_port'):
135
134
        port = '8080'
141
140
    else:
142
141
        host = config.get_option('user_host')
143
142
 
 
143
    load_plugins()
 
144
 
144
145
    httpserver.serve(app, host=host, port=port)
145
146
 
146
147