Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/server.py @ 10640:90a095c24bc4
server: handle server-internal config setup inside server class
author | Dirkjan Ochtman <djc.ochtman@kentyde.com> |
---|---|
date | Thu, 11 Mar 2010 13:30:52 +0100 |
parents | a6808629f450 |
children | dedf88fe945a |
comparison
equal
deleted
inserted
replaced
10639:a6808629f450 | 10640:90a095c24bc4 |
---|---|
216 myui = ui | 216 myui = ui |
217 else: | 217 else: |
218 myui = repo.ui | 218 myui = repo.ui |
219 address = myui.config("web", "address", "") | 219 address = myui.config("web", "address", "") |
220 port = int(myui.config("web", "port", 8000)) | 220 port = int(myui.config("web", "port", 8000)) |
221 prefix = myui.config("web", "prefix", "") | |
222 if prefix: | |
223 prefix = "/" + prefix.strip("/") | |
224 use_ipv6 = myui.configbool("web", "ipv6") | 221 use_ipv6 = myui.configbool("web", "ipv6") |
225 webdir_conf = myui.config("web", "webdir_conf") | 222 webdir_conf = myui.config("web", "webdir_conf") |
226 ssl_cert = myui.config("web", "certificate") | |
227 accesslog = openlog(myui.config("web", "accesslog", "-"), sys.stdout) | |
228 errorlog = openlog(myui.config("web", "errorlog", "-"), sys.stderr) | |
229 | 223 |
230 if webdir_conf: | 224 if webdir_conf: |
231 hgwebobj = hgwebdir(webdir_conf, ui) | 225 hgwebobj = hgwebdir(webdir_conf, ui) |
232 elif repo is not None: | 226 elif repo is not None: |
233 hgwebobj = hgweb(hg.repository(repo.ui, repo.root)) | 227 hgwebobj = hgweb(hg.repository(repo.ui, repo.root)) |
239 | 233 |
240 # SO_REUSEADDR has broken semantics on windows | 234 # SO_REUSEADDR has broken semantics on windows |
241 if os.name == 'nt': | 235 if os.name == 'nt': |
242 allow_reuse_address = 0 | 236 allow_reuse_address = 0 |
243 | 237 |
244 def __init__(self, *args, **kargs): | 238 def __init__(self, ui, *args, **kargs): |
245 BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs) | 239 BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs) |
246 self.accesslog = accesslog | |
247 self.errorlog = errorlog | |
248 self.daemon_threads = True | 240 self.daemon_threads = True |
249 self.application = hgwebobj | 241 self.application = hgwebobj |
250 | 242 |
243 ssl_cert = ui.config('web', 'certificate') | |
251 if ssl_cert: | 244 if ssl_cert: |
252 try: | 245 try: |
253 from OpenSSL import SSL | 246 from OpenSSL import SSL |
254 ctx = SSL.Context(SSL.SSLv23_METHOD) | 247 ctx = SSL.Context(SSL.SSLv23_METHOD) |
255 except ImportError: | 248 except ImportError: |
259 sock = socket.socket(self.address_family, self.socket_type) | 252 sock = socket.socket(self.address_family, self.socket_type) |
260 self.socket = SSL.Connection(ctx, sock) | 253 self.socket = SSL.Connection(ctx, sock) |
261 self.server_bind() | 254 self.server_bind() |
262 self.server_activate() | 255 self.server_activate() |
263 | 256 |
257 prefix = ui.config('web', 'prefix', '') | |
258 if prefix: | |
259 prefix = '/' + prefix.strip('/') | |
260 self.prefix = prefix | |
261 | |
262 alog = openlog(ui.config('web', 'accesslog', '-'), sys.stdout) | |
263 elog = openlog(ui.config('web', 'errorlog', '-'), sys.stderr) | |
264 self.accesslog = alog | |
265 self.errorlog = elog | |
266 | |
264 self.addr, self.port = self.socket.getsockname()[0:2] | 267 self.addr, self.port = self.socket.getsockname()[0:2] |
265 self.prefix = prefix | |
266 self.fqaddr = socket.getfqdn(address) | 268 self.fqaddr = socket.getfqdn(address) |
267 | 269 |
268 class IPv6HTTPServer(MercurialHTTPServer): | 270 class IPv6HTTPServer(MercurialHTTPServer): |
269 address_family = getattr(socket, 'AF_INET6', None) | 271 address_family = getattr(socket, 'AF_INET6', None) |
270 | 272 |
271 def __init__(self, *args, **kwargs): | 273 def __init__(self, *args, **kwargs): |
272 if self.address_family is None: | 274 if self.address_family is None: |
273 raise error.RepoError(_('IPv6 is not available on this system')) | 275 raise error.RepoError(_('IPv6 is not available on this system')) |
274 super(IPv6HTTPServer, self).__init__(*args, **kwargs) | 276 super(IPv6HTTPServer, self).__init__(*args, **kwargs) |
275 | 277 |
276 if ssl_cert: | 278 if myui.config('web', 'certificate'): |
277 handler = _shgwebhandler | 279 handler = _shgwebhandler |
278 else: | 280 else: |
279 handler = _hgwebhandler | 281 handler = _hgwebhandler |
280 | 282 |
281 # ugly hack due to python issue5853 (for threaded use) | 283 # ugly hack due to python issue5853 (for threaded use) |
282 import mimetypes; mimetypes.init() | 284 import mimetypes; mimetypes.init() |
283 | 285 |
284 try: | 286 try: |
285 if use_ipv6: | 287 if use_ipv6: |
286 return IPv6HTTPServer((address, port), handler) | 288 return IPv6HTTPServer(myui, (address, port), handler) |
287 else: | 289 else: |
288 return MercurialHTTPServer((address, port), handler) | 290 return MercurialHTTPServer(myui, (address, port), handler) |
289 except socket.error, inst: | 291 except socket.error, inst: |
290 raise util.Abort(_("cannot start server at '%s:%d': %s") | 292 raise util.Abort(_("cannot start server at '%s:%d': %s") |
291 % (address, port, inst.args[1])) | 293 % (address, port, inst.args[1])) |