##// END OF EJS Templates
server: initialize wsgi app in command, then wrap server around it
Dirkjan Ochtman -
r10644:63948e7d default
parent child Browse files
Show More
@@ -12,7 +12,7 b' import os, re, sys, difflib, time, tempf'
12 12 import hg, util, revlog, bundlerepo, extensions, copies, error
13 13 import patch, help, mdiff, url, encoding, templatekw
14 14 import archival, changegroup, cmdutil, sshserver, hbisect
15 from hgweb import server
15 from hgweb import server, hgweb_mod, hgwebdir_mod
16 16 import merge as merge_
17 17 import minirst
18 18
@@ -2887,7 +2887,7 b' def serve(ui, repo, **opts):'
2887 2887
2888 2888 baseui = repo and repo.baseui or ui
2889 2889 optlist = ("name templates style address port prefix ipv6"
2890 " accesslog errorlog webdir_conf certificate encoding")
2890 " accesslog errorlog certificate encoding")
2891 2891 for o in optlist.split():
2892 2892 val = opts.get(o, '')
2893 2893 if val in (None, ''): # should check against default options instead
@@ -2896,14 +2896,18 b' def serve(ui, repo, **opts):'
2896 2896 if repo and repo.ui != baseui:
2897 2897 repo.ui.setconfig("web", o, val)
2898 2898
2899 if repo is None and not ui.config("web", "webdir_conf"):
2900 raise error.RepoError(_("There is no Mercurial repository here"
2901 " (.hg not found)"))
2899 if opts.get('webdir_conf'):
2900 app = hgwebdir_mod.hgwebdir(opts['webdir_conf'], ui)
2901 elif repo is not None:
2902 app = hgweb_mod.hgweb(hg.repository(repo.ui, repo.root))
2903 else:
2904 raise error.RepoError(_("There is no Mercurial repository"
2905 " here (.hg not found)"))
2902 2906
2903 2907 class service(object):
2904 2908 def init(self):
2905 2909 util.set_signal_handler()
2906 self.httpd = server.create_server(baseui, repo)
2910 self.httpd = server.create_server(ui, app)
2907 2911
2908 2912 if opts['port'] and not ui.verbose:
2909 2913 return
@@ -8,8 +8,6 b''
8 8
9 9 import os, sys, errno, urllib, BaseHTTPServer, socket, SocketServer, traceback
10 10 from mercurial import hg, util, error
11 from hgweb_mod import hgweb
12 from hgwebdir_mod import hgwebdir
13 11 from mercurial.i18n import _
14 12
15 13 def _splitURI(uri):
@@ -255,39 +253,25 b' class IPv6HTTPServer(MercurialHTTPServer'
255 253 raise error.RepoError(_('IPv6 is not available on this system'))
256 254 super(IPv6HTTPServer, self).__init__(*args, **kwargs)
257 255
258 def create_server(ui, repo):
256 def create_server(ui, app):
259 257
260 if repo is None:
261 myui = ui
262 else:
263 myui = repo.ui
264 address = myui.config("web", "address", "")
265 port = int(myui.config("web", "port", 8000))
266
267 if myui.config('web', 'certificate'):
258 if ui.config('web', 'certificate'):
268 259 handler = _shgwebhandler
269 260 else:
270 261 handler = _hgwebhandler
271 262
272 if myui.configbool('web', 'ipv6'):
263 if ui.configbool('web', 'ipv6'):
273 264 cls = IPv6HTTPServer
274 265 else:
275 266 cls = MercurialHTTPServer
276 267
277 webdir_conf = myui.config("web", "webdir_conf")
278 if webdir_conf:
279 hgwebobj = hgwebdir(webdir_conf, ui)
280 elif repo is not None:
281 hgwebobj = hgweb(hg.repository(repo.ui, repo.root))
282 else:
283 raise error.RepoError(_("There is no Mercurial repository"
284 " here (.hg not found)"))
285
286 268 # ugly hack due to python issue5853 (for threaded use)
287 269 import mimetypes; mimetypes.init()
288 270
271 address = ui.config('web', 'address', '')
272 port = int(ui.config('web', 'port', 8000))
289 273 try:
290 return cls(myui, hgwebobj, (address, port), handler)
274 return cls(ui, app, (address, port), handler)
291 275 except socket.error, inst:
292 276 raise util.Abort(_("cannot start server at '%s:%d': %s")
293 277 % (address, port, inst.args[1]))
General Comments 0
You need to be logged in to leave comments. Login now