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