mercurial/hgweb/__init__.py
changeset 27138 ea8e27e6098d
parent 27046 37fcfe52c68c
child 27139 d73f23344dc7
equal deleted inserted replaced
27137:25e4b2f000c5 27138:ea8e27e6098d
     8 
     8 
     9 from __future__ import absolute_import
     9 from __future__ import absolute_import
    10 
    10 
    11 import os
    11 import os
    12 
    12 
       
    13 from ..i18n import _
       
    14 
       
    15 from .. import (
       
    16     util,
       
    17 )
       
    18 
    13 from . import (
    19 from . import (
    14     hgweb_mod,
    20     hgweb_mod,
    15     hgwebdir_mod,
    21     hgwebdir_mod,
       
    22     server,
    16 )
    23 )
    17 
    24 
    18 def hgweb(config, name=None, baseui=None):
    25 def hgweb(config, name=None, baseui=None):
    19     '''create an hgweb wsgi object
    26     '''create an hgweb wsgi object
    20 
    27 
    33     return hgweb_mod.hgweb(config, name=name, baseui=baseui)
    40     return hgweb_mod.hgweb(config, name=name, baseui=baseui)
    34 
    41 
    35 def hgwebdir(config, baseui=None):
    42 def hgwebdir(config, baseui=None):
    36     return hgwebdir_mod.hgwebdir(config, baseui=baseui)
    43     return hgwebdir_mod.hgwebdir(config, baseui=baseui)
    37 
    44 
       
    45 class httpservice(object):
       
    46     def __init__(self, ui, app, opts):
       
    47         self.ui = ui
       
    48         self.app = app
       
    49         self.opts = opts
       
    50 
       
    51     def init(self):
       
    52         util.setsignalhandler()
       
    53         self.httpd = server.create_server(self.ui, self.app)
       
    54 
       
    55         if self.opts['port'] and not self.ui.verbose:
       
    56             return
       
    57 
       
    58         if self.httpd.prefix:
       
    59             prefix = self.httpd.prefix.strip('/') + '/'
       
    60         else:
       
    61             prefix = ''
       
    62 
       
    63         port = ':%d' % self.httpd.port
       
    64         if port == ':80':
       
    65             port = ''
       
    66 
       
    67         bindaddr = self.httpd.addr
       
    68         if bindaddr == '0.0.0.0':
       
    69             bindaddr = '*'
       
    70         elif ':' in bindaddr: # IPv6
       
    71             bindaddr = '[%s]' % bindaddr
       
    72 
       
    73         fqaddr = self.httpd.fqaddr
       
    74         if ':' in fqaddr:
       
    75             fqaddr = '[%s]' % fqaddr
       
    76         if self.opts['port']:
       
    77             write = self.ui.status
       
    78         else:
       
    79             write = self.ui.write
       
    80         write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
       
    81               (fqaddr, port, prefix, bindaddr, self.httpd.port))
       
    82         self.ui.flush()  # avoid buffering of status message
       
    83 
       
    84     def run(self):
       
    85         self.httpd.serve_forever()