Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/server.py @ 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 | 13a1b2fb7ef2 |
comparison
equal
deleted
inserted
replaced
10643:1874697a8863 | 10644:63948e7d37f7 |
---|---|
6 # This software may be used and distributed according to the terms of the | 6 # This software may be used and distributed according to the terms of the |
7 # GNU General Public License version 2 or any later version. | 7 # GNU General Public License version 2 or any later version. |
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): |
16 """ Return path and query splited from uri | 14 """ Return path and query splited from uri |
17 | 15 |
253 def __init__(self, *args, **kwargs): | 251 def __init__(self, *args, **kwargs): |
254 if self.address_family is None: | 252 if self.address_family is None: |
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 | |
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 | 267 |
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])) |