~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Guillermo Gonzalez
  • Date: 2008-09-10 23:12:59 UTC
  • mfrom: (221 trunk)
  • mto: (217.1.9 logging)
  • mto: This revision was merged to the branch mainline in revision 226.
  • Revision ID: guillo.gonzo@gmail.com-20080910231259-4wnfmu30f4n90w6x
 * merge with trunk (resolve conflicts in NEWS and serve-branches)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from optparse import OptionParser
23
23
 
24
 
from bzrlib.plugin import load_plugins
25
 
 
26
24
from paste import httpserver
27
 
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
 
25
from paste.httpexceptions import HTTPExceptionHandler
28
26
from paste.translogger import TransLogger
29
27
 
30
28
from loggerhead import __version__
46
44
    parser.add_option("--trunk-dir", metavar="DIR",
47
45
                      help="The directory that contains the trunk branches.")
48
46
    parser.add_option("--port", dest="user_port",
49
 
                      help=("Port Loggerhead should listen on "
50
 
                            "(defaults to 8080)."))
 
47
                      help="Port Loggerhead should listen on (defaults to 8080).")
51
48
    parser.add_option("--host", dest="user_host",
52
49
                      help="Host Loggerhead should listen on.")
53
50
    parser.add_option("--prefix", dest="user_prefix",
54
51
                      help="Specify host prefix.")
55
 
    parser.add_option("--profile", action="store_true", dest="profile",
56
 
                      help="Generate callgrind profile data to "
57
 
                        "%d-stats.callgrind on each request.")
58
52
    parser.add_option("--reload", action="store_true", dest="reload",
59
53
                      help="Restarts the application when changing python"
60
54
                           " files. Only used for development purposes.")
61
 
    parser.add_option('--log-folder', dest="log_folder",
62
 
                      type=str, help="The directory to place log files in.")
 
55
    parser.add_option('--log-folder', dest="log_folder", 
 
56
                      type=str, help="The directory to place log files")
63
57
    parser.add_option("--version", action="store_true", dest="show_version",
64
58
                      help="Print the software version and exit")
65
59
    return parser
88
82
    if options.trunk_dir and not options.user_dirs:
89
83
        print "--trunk-dir is only valid with --user-dirs"
90
84
        sys.exit(1)
91
 
 
 
85
        
92
86
    if options.reload:
93
87
        if Reloader.is_installed():
94
88
            Reloader.install()
102
96
        app = UserBranchesFromFileSystemRoot(path, options.trunk_dir)
103
97
    else:
104
98
        app = BranchesFromFileSystemRoot(path)
105
 
 
 
99
    
106
100
    # setup_logging()
107
101
    logging.basicConfig()
108
102
    logging.getLogger('').setLevel(logging.DEBUG)
118
112
    logfile.setLevel(logging.DEBUG)
119
113
    logger.addHandler(logfile)
120
114
    # setup_logging() #end
 
115
    app = ErrorHandlerApp(app)
 
116
    app = HTTPExceptionHandler(app)
121
117
    app = TransLogger(app, logger=logger)
122
 
    if options.profile:
123
 
        from loggerhead.middleware.profile import LSProfMiddleware
124
 
        app = LSProfMiddleware(app)
125
118
 
126
119
    if not options.user_prefix:
127
120
        prefix = '/'
131
124
    try:
132
125
        from paste.deploy.config import PrefixMiddleware
133
126
    except ImportError:
134
 
        cant_proxy_correctly_message = (
135
 
            'Unsupported configuration: PasteDeploy not available, but '
136
 
            'loggerhead appears to be behind a proxy.')
137
 
        def check_not_proxied(app):
138
 
            def wrapped(environ, start_response):
139
 
                if 'HTTP_X_FORWARDED_SERVER' in environ:
140
 
                    exc = HTTPInternalServerError()
141
 
                    exc.explanation = cant_proxy_correctly_message
142
 
                    raise exc
143
 
                return app(environ, start_response)
144
 
            return wrapped
145
 
        app = check_not_proxied(app)
 
127
        pass
146
128
    else:
147
129
        app = PrefixMiddleware(app, prefix=prefix)
148
 
 
149
 
    app = HTTPExceptionHandler(app)
150
 
    app = ErrorHandlerApp(app)
151
 
 
 
130
    
152
131
    if not options.user_port:
153
132
        port = '8080'
154
133
    else:
159
138
    else:
160
139
        host = options.user_host
161
140
 
162
 
    load_plugins()
163
 
 
164
141
    httpserver.serve(app, host=host, port=port)
165
142
 
166
143