author Gregory Szorc <gps@mozilla.com>
Sat, 24 Jan 2015 19:42:03 -0800
changeset 360256 17f4091a1f7b876e4d3a4f50ef06e3886ba80e03
parent 359771 d8d096f817477019064f6497cb6be7042ab10fe6
permissions -rw-r--r--
testing: prevent double virtualenv activation The bootstrap code was potentially activating a virtualenv on top of itself. This results in the virtualenv's bin directory always being first in PATH. This threw off hg binary detection when running under --with-hg. Prevent double virtualenv activation.

#!/usr/bin/env python
""" TODO: Rewrite this as a WSGI app"""

from mercurial import demandimport
from mercurial.hgweb import hgweb, wsgicgi
from mercurial import ui, hg
import os

prefix = os.environ["CONTEXT_PREFIX"].split("/", 4)[0:4]

repo = os.environ["CONTEXT_PREFIX"].split("/")[2]
bundle = os.environ["CONTEXT_PREFIX"].split("/")[3]
path = "/".join(os.environ["CONTEXT_PREFIX"].split("/")[4:])

prefix = "/".join(prefix)

os.environ["SCRIPT_NAME"] = prefix
os.environ["PATH_INFO"] = path

fh = open("/tmp/env", "w+")

if repo is "" or bundle is "":
    print "Content-type: text/html\n\n"
    print "Missing repo or bundle name!"

if not os.path.isfile('/var/hg/bundles/%s.bundle' % bundle):
    print "Content-type: text/html\n\n"
    print "Error: Bundle '%s' doesn't exist!" % bundle

if not os.path.isdir('/var/hg/repos/%s' % repo):
    print "Content-type: text/html\n\n"
    print "Error: Repository '%s' doesn't exist!" % repo

u = ui.ui()

u.setconfig('bundle', 'mainreporoot', '/var/hg/repos/%s' % repo)
repo = hg.repository(u, '/var/hg/bundles/%s.bundle' % bundle)

application = hgweb(repo)