~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Matt Nordhoff
  • Date: 2009-06-17 23:10:38 UTC
  • mfrom: (359.3.7 hpss-writes)
  • Revision ID: mnordhoff@mattnordhoff.com-20090617231038-s01aol77to1x3hq1
Support serving branches over HTTP using the smart server protocol. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from loggerhead.apps.error import ErrorHandlerApp
38
38
 
39
39
 
40
 
def get_config_and_path(args):
 
40
def main(args):
41
41
    config = LoggerheadConfig()
42
42
 
43
43
    if config.get_option('show_version'):
48
48
        config.print_help()
49
49
        sys.exit(1)
50
50
    elif config.arg_count == 1:
51
 
        base = config.get_arg(0)
52
 
    else:
53
 
        base = '.'
54
 
 
55
 
    if not config.get_option('allow_writes'):
56
 
        base = 'readonly+' + base
57
 
 
58
 
    return config, base
59
 
 
60
 
 
61
 
def setup_logging(config):
 
51
        path = config.get_arg(0)
 
52
    else:
 
53
        path = '.'
 
54
 
 
55
    load_plugins()
 
56
 
 
57
    if config.get_option('allow_writes'):
 
58
        transport = get_transport(path)
 
59
    else:
 
60
        transport = get_transport('readonly+' + path)
 
61
 
 
62
    if config.get_option('trunk_dir') and not config.get_option('user_dirs'):
 
63
        print "--trunk-dir is only valid with --user-dirs"
 
64
        sys.exit(1)
 
65
 
 
66
    if config.get_option('reload'):
 
67
        if Reloader.is_installed():
 
68
            Reloader.install()
 
69
        else:
 
70
            return Reloader.restart_with_reloader()
 
71
 
 
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."
 
75
            sys.exit(1)
 
76
        app = UserBranchesFromTransportRoot(transport, config)
 
77
    else:
 
78
        app = BranchesFromTransportRoot(transport, config)
 
79
 
 
80
    # setup_logging()
62
81
    logging.basicConfig()
63
82
    logging.getLogger('').setLevel(logging.DEBUG)
64
 
    logger = logging.getLogger('loggerhead')
 
83
    logger = getattr(app, 'log', logging.getLogger('loggerhead'))
65
84
    if config.get_option('log_folder'):
66
85
        logfile_path = os.path.join(
67
86
            config.get_option('log_folder'), 'serve-branches.log')
73
92
    logfile.setFormatter(formatter)
74
93
    logfile.setLevel(logging.DEBUG)
75
94
    logger.addHandler(logfile)
76
 
    return logger
77
 
 
78
 
 
79
 
def make_app_for_config_and_path(config, base):
80
 
    if config.get_option('trunk_dir') and not config.get_option('user_dirs'):
81
 
        print "--trunk-dir is only valid with --user-dirs"
82
 
        sys.exit(1)
83
 
 
84
 
    if config.get_option('reload'):
85
 
        if Reloader.is_installed():
86
 
            Reloader.install()
87
 
        else:
88
 
            return Reloader.restart_with_reloader()
89
 
 
90
 
    if config.get_option('user_dirs'):
91
 
        if not config.get_option('trunk_dir'):
92
 
            print "You didn't specify a directory for the trunk directories."
93
 
            sys.exit(1)
94
 
        app = UserBranchesFromTransportRoot(base, config)
95
 
    else:
96
 
        app = BranchesFromTransportRoot(base, config)
97
 
 
98
 
    setup_logging(config)
 
95
 
 
96
    # setup_logging() #end
99
97
 
100
98
    if config.get_option('profile'):
101
99
        from loggerhead.middleware.profile import LSProfMiddleware
131
129
 
132
130
    app = HTTPExceptionHandler(app)
133
131
    app = ErrorHandlerApp(app)
134
 
    app = TransLogger(app, logger=logging.getLogger('loggerhead'))
135
 
 
136
 
    return app
137
 
 
138
 
 
139
 
def main(args):
140
 
    load_plugins()
141
 
 
142
 
    config, path = get_config_and_path(args)
143
 
 
144
 
    app = make_app_for_config_and_path(config, path)
 
132
    app = TransLogger(app, logger=logger)
145
133
 
146
134
    if not config.get_option('user_port'):
147
135
        port = '8080'
154
142
        host = config.get_option('user_host')
155
143
 
156
144
    httpserver.serve(app, host=host, port=port)
 
145
 
 
146
 
 
147
if __name__ == "__main__":
 
148
    main(sys.argv)