changeset 10644:63948e7d37f7

server: initialize wsgi app in command, then wrap server around it
author Dirkjan Ochtman <djc.ochtman@kentyde.com>
date Thu, 11 Mar 2010 13:33:29 +0100
parents 1874697a8863
children 4ba41eebb3a8
files mercurial/commands.py mercurial/hgweb/server.py
diffstat 2 files changed, 16 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Mar 11 13:32:43 2010 +0100
+++ b/mercurial/commands.py	Thu Mar 11 13:33:29 2010 +0100
@@ -12,7 +12,7 @@
 import hg, util, revlog, bundlerepo, extensions, copies, error
 import patch, help, mdiff, url, encoding, templatekw
 import archival, changegroup, cmdutil, sshserver, hbisect
-from hgweb import server
+from hgweb import server, hgweb_mod, hgwebdir_mod
 import merge as merge_
 import minirst
 
@@ -2887,7 +2887,7 @@
 
     baseui = repo and repo.baseui or ui
     optlist = ("name templates style address port prefix ipv6"
-               " accesslog errorlog webdir_conf certificate encoding")
+               " accesslog errorlog certificate encoding")
     for o in optlist.split():
         val = opts.get(o, '')
         if val in (None, ''): # should check against default options instead
@@ -2896,14 +2896,18 @@
         if repo and repo.ui != baseui:
             repo.ui.setconfig("web", o, val)
 
-    if repo is None and not ui.config("web", "webdir_conf"):
-        raise error.RepoError(_("There is no Mercurial repository here"
-                                " (.hg not found)"))
+    if opts.get('webdir_conf'):
+        app = hgwebdir_mod.hgwebdir(opts['webdir_conf'], ui)
+    elif repo is not None:
+        app = hgweb_mod.hgweb(hg.repository(repo.ui, repo.root))
+    else:
+        raise error.RepoError(_("There is no Mercurial repository"
+                                " here (.hg not found)"))
 
     class service(object):
         def init(self):
             util.set_signal_handler()
-            self.httpd = server.create_server(baseui, repo)
+            self.httpd = server.create_server(ui, app)
 
             if opts['port'] and not ui.verbose:
                 return
--- a/mercurial/hgweb/server.py	Thu Mar 11 13:32:43 2010 +0100
+++ b/mercurial/hgweb/server.py	Thu Mar 11 13:33:29 2010 +0100
@@ -8,8 +8,6 @@
 
 import os, sys, errno, urllib, BaseHTTPServer, socket, SocketServer, traceback
 from mercurial import hg, util, error
-from hgweb_mod import hgweb
-from hgwebdir_mod import hgwebdir
 from mercurial.i18n import _
 
 def _splitURI(uri):
@@ -255,39 +253,25 @@
             raise error.RepoError(_('IPv6 is not available on this system'))
         super(IPv6HTTPServer, self).__init__(*args, **kwargs)
 
-def create_server(ui, repo):
+def create_server(ui, app):
 
-    if repo is None:
-        myui = ui
-    else:
-        myui = repo.ui
-    address = myui.config("web", "address", "")
-    port = int(myui.config("web", "port", 8000))
-
-    if myui.config('web', 'certificate'):
+    if ui.config('web', 'certificate'):
         handler = _shgwebhandler
     else:
         handler = _hgwebhandler
 
-    if myui.configbool('web', 'ipv6'):
+    if ui.configbool('web', 'ipv6'):
         cls = IPv6HTTPServer
     else:
         cls = MercurialHTTPServer
 
-    webdir_conf = myui.config("web", "webdir_conf")
-    if webdir_conf:
-        hgwebobj = hgwebdir(webdir_conf, ui)
-    elif repo is not None:
-        hgwebobj = hgweb(hg.repository(repo.ui, repo.root))
-    else:
-        raise error.RepoError(_("There is no Mercurial repository"
-                                " here (.hg not found)"))
-
     # ugly hack due to python issue5853 (for threaded use)
     import mimetypes; mimetypes.init()
 
+    address = ui.config('web', 'address', '')
+    port = int(ui.config('web', 'port', 8000))
     try:
-        return cls(myui, hgwebobj, (address, port), handler)
+        return cls(ui, app, (address, port), handler)
     except socket.error, inst:
         raise util.Abort(_("cannot start server at '%s:%d': %s")
                          % (address, port, inst.args[1]))