changeset 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
files mercurial/hgweb/server.py
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/server.py	Thu Mar 11 13:28:39 2010 +0100
+++ b/mercurial/hgweb/server.py	Thu Mar 11 13:30:52 2010 +0100
@@ -218,14 +218,8 @@
         myui = repo.ui
     address = myui.config("web", "address", "")
     port = int(myui.config("web", "port", 8000))
-    prefix = myui.config("web", "prefix", "")
-    if prefix:
-        prefix = "/" + prefix.strip("/")
     use_ipv6 = myui.configbool("web", "ipv6")
     webdir_conf = myui.config("web", "webdir_conf")
-    ssl_cert = myui.config("web", "certificate")
-    accesslog = openlog(myui.config("web", "accesslog", "-"), sys.stdout)
-    errorlog = openlog(myui.config("web", "errorlog", "-"), sys.stderr)
 
     if webdir_conf:
         hgwebobj = hgwebdir(webdir_conf, ui)
@@ -241,13 +235,12 @@
         if os.name == 'nt':
             allow_reuse_address = 0
 
-        def __init__(self, *args, **kargs):
+        def __init__(self, ui, *args, **kargs):
             BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs)
-            self.accesslog = accesslog
-            self.errorlog = errorlog
             self.daemon_threads = True
             self.application = hgwebobj
 
+            ssl_cert = ui.config('web', 'certificate')
             if ssl_cert:
                 try:
                     from OpenSSL import SSL
@@ -261,8 +254,17 @@
                 self.server_bind()
                 self.server_activate()
 
+            prefix = ui.config('web', 'prefix', '')
+            if prefix:
+                prefix = '/' + prefix.strip('/')
+            self.prefix = prefix
+
+            alog = openlog(ui.config('web', 'accesslog', '-'), sys.stdout)
+            elog = openlog(ui.config('web', 'errorlog', '-'), sys.stderr)
+            self.accesslog = alog
+            self.errorlog = elog
+
             self.addr, self.port = self.socket.getsockname()[0:2]
-            self.prefix = prefix
             self.fqaddr = socket.getfqdn(address)
 
     class IPv6HTTPServer(MercurialHTTPServer):
@@ -273,7 +275,7 @@
                 raise error.RepoError(_('IPv6 is not available on this system'))
             super(IPv6HTTPServer, self).__init__(*args, **kwargs)
 
-    if ssl_cert:
+    if myui.config('web', 'certificate'):
         handler = _shgwebhandler
     else:
         handler = _hgwebhandler
@@ -283,9 +285,9 @@
 
     try:
         if use_ipv6:
-            return IPv6HTTPServer((address, port), handler)
+            return IPv6HTTPServer(myui, (address, port), handler)
         else:
-            return MercurialHTTPServer((address, port), handler)
+            return MercurialHTTPServer(myui, (address, port), handler)
     except socket.error, inst:
         raise util.Abort(_("cannot start server at '%s:%d': %s")
                          % (address, port, inst.args[1]))