~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Michael Hudson
  • Date: 2008-09-29 21:35:13 UTC
  • Revision ID: michael.hudson@canonical.com-20080929213513-ools0krfn8l9wwf0
clean up flakes and whitespace in diff_ui.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from loggerhead.apps.filesystem import (
30
30
    BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot)
31
31
from loggerhead.util import Reloader
32
 
from loggerhead.apps.error import ErrorHandlerApp
33
32
 
34
33
 
35
34
def command_line_parser():
37
36
    parser.set_defaults(
38
37
        user_dirs=False,
39
38
        show_version=False,
40
 
        log_folder=None,
41
39
        )
42
40
    parser.add_option("--user-dirs", action="store_true", dest="user_dirs",
43
41
                      help="Serve user directories as ~user.")
44
42
    parser.add_option("--trunk-dir", metavar="DIR",
45
43
                      help="The directory that contains the trunk branches.")
46
44
    parser.add_option("--port", dest="user_port",
47
 
                      help=("Port Loggerhead should listen on "
48
 
                            "(defaults to 8080)."))
 
45
                      help="Port Loggerhead should listen on (defaults to 8080).")
49
46
    parser.add_option("--host", dest="user_host",
50
47
                      help="Host Loggerhead should listen on.")
51
48
    parser.add_option("--prefix", dest="user_prefix",
53
50
    parser.add_option("--reload", action="store_true", dest="reload",
54
51
                      help="Restarts the application when changing python"
55
52
                           " files. Only used for development purposes.")
56
 
    parser.add_option('--log-folder', dest="log_folder",
57
 
                      type=str, help="The directory to place log files in.")
58
53
    parser.add_option("--version", action="store_true", dest="show_version",
59
54
                      help="Print the software version and exit")
60
55
    return parser
61
56
 
62
57
 
63
58
def main(args):
 
59
    logging.basicConfig()
 
60
    logging.getLogger().setLevel(logging.DEBUG)
 
61
 
64
62
    parser = command_line_parser()
65
63
    (options, args) = parser.parse_args(sys.argv[1:])
66
64
 
83
81
    if options.trunk_dir and not options.user_dirs:
84
82
        print "--trunk-dir is only valid with --user-dirs"
85
83
        sys.exit(1)
86
 
 
 
84
        
87
85
    if options.reload:
88
86
        if Reloader.is_installed():
89
87
            Reloader.install()
97
95
        app = UserBranchesFromFileSystemRoot(path, options.trunk_dir)
98
96
    else:
99
97
        app = BranchesFromFileSystemRoot(path)
100
 
 
101
 
    # setup_logging()
102
 
    logging.basicConfig()
103
 
    logging.getLogger('').setLevel(logging.DEBUG)
104
 
    logger = getattr(app, 'log', logging.getLogger('loggerhead'))
105
 
    if options.log_folder:
106
 
        logfile_path = os.path.join(options.log_folder, 'serve-branches.log')
107
 
    else:
108
 
        logfile_path = 'serve-branches.log'
109
 
    logfile = logging.FileHandler(logfile_path, 'a')
110
 
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)s:'
111
 
                                  ' %(message)s')
112
 
    logfile.setFormatter(formatter)
113
 
    logfile.setLevel(logging.DEBUG)
114
 
    logger.addHandler(logfile)
115
 
    # setup_logging() #end
116
 
    app = ErrorHandlerApp(app)
117
98
    app = HTTPExceptionHandler(app)
118
 
    app = TransLogger(app, logger=logger)
 
99
    app = TransLogger(app)
119
100
 
120
101
    if not options.user_prefix:
121
102
        prefix = '/'
128
109
        pass
129
110
    else:
130
111
        app = PrefixMiddleware(app, prefix=prefix)
131
 
 
 
112
    
132
113
    if not options.user_port:
133
114
        port = '8080'
134
115
    else: