36
37
from loggerhead.apps.error import ErrorHandlerApp
39
def get_config_and_path(args):
40
config = LoggerheadConfig(args)
41
config = LoggerheadConfig()
42
43
if config.get_option('show_version'):
43
44
print "loggerhead %s" % __version__
47
48
config.print_help()
49
50
elif config.arg_count == 1:
50
base = config.get_arg(0)
54
if not config.get_option('allow_writes'):
55
base = 'readonly+' + base
60
def setup_logging(config):
51
path = config.get_arg(0)
57
if config.get_option('allow_writes'):
58
transport = get_transport(path)
60
transport = get_transport('readonly+' + path)
62
if config.get_option('trunk_dir') and not config.get_option('user_dirs'):
63
print "--trunk-dir is only valid with --user-dirs"
66
if config.get_option('reload'):
67
if Reloader.is_installed():
70
return Reloader.restart_with_reloader()
72
if config.get_option('user_dirs'):
73
if not config.get_option('trunk_dir'):
74
print "You didn't specify a directory for the trunk directories."
76
app = UserBranchesFromTransportRoot(transport, config)
78
app = BranchesFromTransportRoot(transport, config)
61
81
logging.basicConfig()
62
82
logging.getLogger('').setLevel(logging.DEBUG)
63
logger = logging.getLogger('loggerhead')
83
logger = getattr(app, 'log', logging.getLogger('loggerhead'))
64
84
if config.get_option('log_folder'):
65
85
logfile_path = os.path.join(
66
86
config.get_option('log_folder'), 'serve-branches.log')
72
92
logfile.setFormatter(formatter)
73
93
logfile.setLevel(logging.DEBUG)
74
94
logger.addHandler(logfile)
78
def make_app_for_config_and_path(config, base):
79
if config.get_option('trunk_dir') and not config.get_option('user_dirs'):
80
print "--trunk-dir is only valid with --user-dirs"
83
if config.get_option('reload'):
84
if Reloader.is_installed():
87
return Reloader.restart_with_reloader()
89
if config.get_option('user_dirs'):
90
if not config.get_option('trunk_dir'):
91
print "You didn't specify a directory for the trunk directories."
93
app = UserBranchesFromTransportRoot(base, config)
95
app = BranchesFromTransportRoot(base, config)
96
# setup_logging() #end
99
98
if config.get_option('profile'):
100
99
from loggerhead.middleware.profile import LSProfMiddleware
131
130
app = HTTPExceptionHandler(app)
132
131
app = ErrorHandlerApp(app)
133
app = TransLogger(app, logger=logging.getLogger('loggerhead'))
141
config, path = get_config_and_path(args)
143
app = make_app_for_config_and_path(config, path)
132
app = TransLogger(app, logger=logger)
145
134
if not config.get_option('user_port'):