Ejemplo n.º 1
0
        def __init__(self, *args, **kargs):
            BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs)
            self.accesslog = accesslog
            self.errorlog = errorlog
            self.daemon_threads = True

            def make_handler():
                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)"))
                return hgwebobj

            self.application = make_handler()

            if ssl_cert:
                try:
                    from OpenSSL import SSL
                    ctx = SSL.Context(SSL.SSLv23_METHOD)
                except ImportError:
                    raise util.Abort(_("SSL support is unavailable"))
                ctx.use_privatekey_file(ssl_cert)
                ctx.use_certificate_file(ssl_cert)
                sock = socket.socket(self.address_family, self.socket_type)
                self.socket = SSL.Connection(ctx, sock)
                self.server_bind()
                self.server_activate()

            self.addr, self.port = self.socket.getsockname()[0:2]
            self.prefix = prefix
            self.fqaddr = socket.getfqdn(address)
Ejemplo n.º 2
0
        def __init__(self, *args, **kargs):
            BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs)
            self.accesslog = accesslog
            self.errorlog = errorlog
            self.daemon_threads = True
            def make_handler():
                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)"))
                return hgwebobj
            self.application = make_handler()

            if ssl_cert:
                try:
                    from OpenSSL import SSL
                    ctx = SSL.Context(SSL.SSLv23_METHOD)
                except ImportError:
                    raise util.Abort(_("SSL support is unavailable"))
                ctx.use_privatekey_file(ssl_cert)
                ctx.use_certificate_file(ssl_cert)
                sock = socket.socket(self.address_family, self.socket_type)
                self.socket = SSL.Connection(ctx, sock)
                self.server_bind()
                self.server_activate()

            self.addr, self.port = self.socket.getsockname()[0:2]
            self.prefix = prefix
            self.fqaddr = socket.getfqdn(address)
Ejemplo n.º 3
0
        def entries(sortcolumn="", descending=False, subdir="", **map):
            rows = []
            parity = paritygen(self.stripecount)
            for name, path in self.repos:
                if not name.startswith(subdir):
                    continue
                name = name[len(subdir):]

                u = self.ui.copy()
                try:
                    u.readconfig(os.path.join(path, '.hg', 'hgrc'))
                except Exception, e:
                    u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e))
                    continue

                def get(section, name, default=None):
                    return u.config(section, name, default, untrusted=True)

                if u.configbool("web", "hidden", untrusted=True):
                    continue

                if not self.read_allowed(u, req):
                    continue

                parts = [name]
                if 'PATH_INFO' in req.env:
                    parts.insert(0, req.env['PATH_INFO'].rstrip('/'))
                if req.env['SCRIPT_NAME']:
                    parts.insert(0, req.env['SCRIPT_NAME'])
                m = re.match('((?:https?://)?)(.*)', '/'.join(parts))
                # squish repeated slashes out of the path component
                url = m.group(1) + re.sub('/+', '/', m.group(2)) + '/'

                # update time with local timezone
                try:
                    d = (get_mtime(path), util.makedate()[1])
                except OSError:
                    continue

                contact = get_contact(get)
                description = get("web", "description", "")
                name = get("web", "name", name)
                row = dict(contact=contact or "unknown",
                           contact_sort=contact.upper() or "unknown",
                           name=name,
                           name_sort=name,
                           url=url,
                           description=description or "unknown",
                           description_sort=description.upper() or "unknown",
                           lastchange=d,
                           lastchange_sort=d[1] - d[0],
                           archives=archivelist(u, "tip", url))
                if (not sortcolumn or (sortcolumn, descending) == sortdefault):
                    # fast path for unsorted output
                    row['parity'] = parity.next()
                    yield row
                else:
                    rows.append((row["%s_sort" % sortcolumn], row))
Ejemplo n.º 4
0
        def entries(sortcolumn="", descending=False, subdir="", **map):
            rows = []
            parity = paritygen(self.stripecount)
            for name, path in self.repos:
                if not name.startswith(subdir):
                    continue
                name = name[len(subdir):]

                u = self.ui.copy()
                try:
                    u.readconfig(os.path.join(path, '.hg', 'hgrc'))
                except Exception, e:
                    u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e))
                    continue
                def get(section, name, default=None):
                    return u.config(section, name, default, untrusted=True)

                if u.configbool("web", "hidden", untrusted=True):
                    continue

                if not self.read_allowed(u, req):
                    continue

                parts = [name]
                if 'PATH_INFO' in req.env:
                    parts.insert(0, req.env['PATH_INFO'].rstrip('/'))
                if req.env['SCRIPT_NAME']:
                    parts.insert(0, req.env['SCRIPT_NAME'])
                m = re.match('((?:https?://)?)(.*)', '/'.join(parts))
                # squish repeated slashes out of the path component
                url = m.group(1) + re.sub('/+', '/', m.group(2)) + '/'

                # update time with local timezone
                try:
                    d = (get_mtime(path), util.makedate()[1])
                except OSError:
                    continue

                contact = get_contact(get)
                description = get("web", "description", "")
                name = get("web", "name", name)
                row = dict(contact=contact or "unknown",
                           contact_sort=contact.upper() or "unknown",
                           name=name,
                           name_sort=name,
                           url=url,
                           description=description or "unknown",
                           description_sort=description.upper() or "unknown",
                           lastchange=d,
                           lastchange_sort=d[1]-d[0],
                           archives=archivelist(u, "tip", url))
                if (not sortcolumn or (sortcolumn, descending) == sortdefault):
                    # fast path for unsorted output
                    row['parity'] = parity.next()
                    yield row
                else:
                    rows.append((row["%s_sort" % sortcolumn], row))
Ejemplo n.º 5
0
 def make_handler():
     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)"))
     return hgwebobj
Ejemplo n.º 6
0
 def make_handler():
     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)"))
     return hgwebobj
Ejemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     if self.address_family is None:
         raise error.RepoError(
             _('IPv6 is not available on this system'))
     super(IPv6HTTPServer, self).__init__(*args, **kwargs)
Ejemplo n.º 8
0
def create_server(ui, repo):
    use_threads = True

    def openlog(opt, default):
        if opt and opt != '-':
            return open(opt, 'a')
        return default

    if repo is None:
        myui = ui
    else:
        myui = repo.ui
    address = myui.config("web", "address", "")
    port = int(myui.config("web", "port", 8000))
    prefix = myui.config("web", "prefix", "")
    if prefix:
        prefix = "/" + prefix.strip("/")
    use_ipv6 = myui.configbool("web", "ipv6")
    webdir_conf = myui.config("web", "webdir_conf")
    ssl_cert = myui.config("web", "certificate")
    accesslog = openlog(myui.config("web", "accesslog", "-"), sys.stdout)
    errorlog = openlog(myui.config("web", "errorlog", "-"), sys.stderr)

    if use_threads:
        try:
            from threading import activeCount
        except ImportError:
            use_threads = False

    if use_threads:
        _mixin = SocketServer.ThreadingMixIn
    else:
        if hasattr(os, "fork"):
            _mixin = SocketServer.ForkingMixIn
        else:

            class _mixin:
                pass

    class MercurialHTTPServer(object, _mixin, BaseHTTPServer.HTTPServer):

        # SO_REUSEADDR has broken semantics on windows
        if os.name == 'nt':
            allow_reuse_address = 0

        def __init__(self, *args, **kargs):
            BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs)
            self.accesslog = accesslog
            self.errorlog = errorlog
            self.daemon_threads = True

            def make_handler():
                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)"))
                return hgwebobj

            self.application = make_handler()

            if ssl_cert:
                try:
                    from OpenSSL import SSL
                    ctx = SSL.Context(SSL.SSLv23_METHOD)
                except ImportError:
                    raise util.Abort(_("SSL support is unavailable"))
                ctx.use_privatekey_file(ssl_cert)
                ctx.use_certificate_file(ssl_cert)
                sock = socket.socket(self.address_family, self.socket_type)
                self.socket = SSL.Connection(ctx, sock)
                self.server_bind()
                self.server_activate()

            self.addr, self.port = self.socket.getsockname()[0:2]
            self.prefix = prefix
            self.fqaddr = socket.getfqdn(address)

    class IPv6HTTPServer(MercurialHTTPServer):
        address_family = getattr(socket, 'AF_INET6', None)

        def __init__(self, *args, **kwargs):
            if self.address_family is None:
                raise error.RepoError(
                    _('IPv6 is not available on this system'))
            super(IPv6HTTPServer, self).__init__(*args, **kwargs)

    if ssl_cert:
        handler = _shgwebhandler
    else:
        handler = _hgwebhandler

    # ugly hack due to python issue5853 (for threaded use)
    import mimetypes
    mimetypes.init()

    try:
        if use_ipv6:
            return IPv6HTTPServer((address, port), handler)
        else:
            return MercurialHTTPServer((address, port), handler)
    except socket.error, inst:
        raise util.Abort(
            _("cannot start server at '%s:%d': %s") %
            (address, port, inst.args[1]))
Ejemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     if self.address_family is None:
         raise error.RepoError(_('IPv6 is not available on this system'))
     super(IPv6HTTPServer, self).__init__(*args, **kwargs)
Ejemplo n.º 10
0
def create_server(ui, repo):
    use_threads = True

    def openlog(opt, default):
        if opt and opt != '-':
            return open(opt, 'a')
        return default

    if repo is None:
        myui = ui
    else:
        myui = repo.ui
    address = myui.config("web", "address", "")
    port = int(myui.config("web", "port", 8000))
    prefix = myui.config("web", "prefix", "")
    if prefix:
        prefix = "/" + prefix.strip("/")
    use_ipv6 = myui.configbool("web", "ipv6")
    webdir_conf = myui.config("web", "webdir_conf")
    ssl_cert = myui.config("web", "certificate")
    accesslog = openlog(myui.config("web", "accesslog", "-"), sys.stdout)
    errorlog = openlog(myui.config("web", "errorlog", "-"), sys.stderr)

    if use_threads:
        try:
            from threading import activeCount
        except ImportError:
            use_threads = False

    if use_threads:
        _mixin = SocketServer.ThreadingMixIn
    else:
        if hasattr(os, "fork"):
            _mixin = SocketServer.ForkingMixIn
        else:
            class _mixin:
                pass

    class MercurialHTTPServer(object, _mixin, BaseHTTPServer.HTTPServer):

        # SO_REUSEADDR has broken semantics on windows
        if os.name == 'nt':
            allow_reuse_address = 0

        def __init__(self, *args, **kargs):
            BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs)
            self.accesslog = accesslog
            self.errorlog = errorlog
            self.daemon_threads = True
            def make_handler():
                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)"))
                return hgwebobj
            self.application = make_handler()

            if ssl_cert:
                try:
                    from OpenSSL import SSL
                    ctx = SSL.Context(SSL.SSLv23_METHOD)
                except ImportError:
                    raise util.Abort(_("SSL support is unavailable"))
                ctx.use_privatekey_file(ssl_cert)
                ctx.use_certificate_file(ssl_cert)
                sock = socket.socket(self.address_family, self.socket_type)
                self.socket = SSL.Connection(ctx, sock)
                self.server_bind()
                self.server_activate()

            self.addr, self.port = self.socket.getsockname()[0:2]
            self.prefix = prefix
            self.fqaddr = socket.getfqdn(address)

    class IPv6HTTPServer(MercurialHTTPServer):
        address_family = getattr(socket, 'AF_INET6', None)

        def __init__(self, *args, **kwargs):
            if self.address_family is None:
                raise error.RepoError(_('IPv6 is not available on this system'))
            super(IPv6HTTPServer, self).__init__(*args, **kwargs)

    if ssl_cert:
        handler = _shgwebhandler
    else:
        handler = _hgwebhandler

    # ugly hack due to python issue5853 (for threaded use)
    import mimetypes; mimetypes.init()

    try:
        if use_ipv6:
            return IPv6HTTPServer((address, port), handler)
        else:
            return MercurialHTTPServer((address, port), handler)
    except socket.error, inst:
        raise util.Abort(_("cannot start server at '%s:%d': %s")
                         % (address, port, inst.args[1]))