~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Paul Hummer
  • Date: 2009-03-31 19:31:45 UTC
  • mto: This revision was merged to the branch mainline in revision 318.
  • Revision ID: paul@canonical.com-20090331193145-qbttxd8f3ywrd8lm
Moar integrations for the config codes!

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from loggerhead import __version__
29
29
from loggerhead.apps.filesystem import (
30
30
    BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot)
31
 
from loggerhead.config import command_line_parser
 
31
from loggerhead.config import LoggerheadConfig
32
32
from loggerhead.util import Reloader
33
33
from loggerhead.apps.error import ErrorHandlerApp
34
34
 
35
35
 
36
36
def main(args):
37
 
    parser = command_line_parser()
38
 
    (options, args) = parser.parse_args(sys.argv[1:])
 
37
    config = LoggerheadConfig()
39
38
 
40
 
    if options.show_version:
 
39
    if config.get_option('show_version'):
41
40
        print "loggerhead %s" % __version__
42
41
        sys.exit(0)
43
42
 
44
 
    if len(args) > 1:
45
 
        parser.print_help()
 
43
    if config.arg_count > 1:
 
44
        config.print_help()
46
45
        sys.exit(1)
47
 
    elif len(args) == 1:
 
46
    elif config.arg_count == 1:
48
47
        [path] = args
49
48
    else:
50
49
        path = '.'
53
52
        print "%s is not a directory" % path
54
53
        sys.exit(1)
55
54
 
56
 
    if options.trunk_dir and not options.user_dirs:
 
55
    if config.get_option('trunk_dir') and not config.get_option('user_dirs'):
57
56
        print "--trunk-dir is only valid with --user-dirs"
58
57
        sys.exit(1)
59
58
 
60
 
    if options.reload:
 
59
    if config.get_option('reload'):
61
60
        if Reloader.is_installed():
62
61
            Reloader.install()
63
62
        else:
64
63
            return Reloader.restart_with_reloader()
65
64
 
66
 
    if options.user_dirs:
67
 
        if not options.trunk_dir:
 
65
    if config.get_option('user_dirs'):
 
66
        if not config.get_option['trunk_dir']:
68
67
            print "You didn't specify a directory for the trunk directories."
69
68
            sys.exit(1)
70
 
        app = UserBranchesFromFileSystemRoot(path, options.trunk_dir)
 
69
        app = UserBranchesFromFileSystemRoot(
 
70
            path, config.get_option('trunk_dir'))
71
71
    else:
72
72
        app = BranchesFromFileSystemRoot(path)
73
73
 
75
75
    logging.basicConfig()
76
76
    logging.getLogger('').setLevel(logging.DEBUG)
77
77
    logger = getattr(app, 'log', logging.getLogger('loggerhead'))
78
 
    if options.log_folder:
79
 
        logfile_path = os.path.join(options.log_folder, 'serve-branches.log')
 
78
    if config.get_option('log_folder'):
 
79
        logfile_path = os.path.join(
 
80
            config.get_option['log_folder'], 'serve-branches.log')
80
81
    else:
81
82
        logfile_path = 'serve-branches.log'
82
83
    logfile = logging.FileHandler(logfile_path, 'a')
93
94
    # setup_logging() #end
94
95
 
95
96
    app = TransLogger(app, logger=logger)
96
 
    if options.profile:
 
97
    if config.get_option('profile'):
97
98
        from loggerhead.middleware.profile import LSProfMiddleware
98
99
        app = LSProfMiddleware(app)
99
 
    if options.memory_profile:
 
100
    if config.get_option('memory_profile'):
100
101
        from loggerhead.middleware.profile import MemoryProfileMiddleware
101
102
        app = MemoryProfileMiddleware(app)
102
103
 
103
 
    if not options.user_prefix:
 
104
    if not config.get_option('user_prefix'):
104
105
        prefix = '/'
105
106
    else:
106
 
        prefix = options.user_prefix
 
107
        prefix = config.get_option('user_prefix')
107
108
        if not prefix.startswith('/'):
108
109
            prefix = '/' + prefix
109
110
 
128
129
    app = HTTPExceptionHandler(app)
129
130
    app = ErrorHandlerApp(app)
130
131
 
131
 
    if not options.user_port:
 
132
    if not config.get_option('user_port'):
132
133
        port = '8080'
133
134
    else:
134
 
        port = options.user_port
 
135
        port = config.get_option('user_port')
135
136
 
136
 
    if not options.user_host:
 
137
    if not config.get_option('user_host'):
137
138
        host = '0.0.0.0'
138
139
    else:
139
 
        host = options.user_host
 
140
        host = config.get_option('user_host')
140
141
 
141
142
    load_plugins()
142
143