def updateCache(*args):
    """
    """
    isDir = os.path.isdir
    pathJoin = os.path.join
    update = False
    index_file = pathJoin(EGGS_DIR, 'index.html')

    if isOutDated(index_file):
        eggs_index_proxy.updateBaseIndex()

    for package_name in os.listdir(EGGS_DIR):
        dir_path = pathJoin(EGGS_DIR, package_name)
        if not isDir(dir_path):
            continue

        index_file = pathJoin(dir_path, 'index.html')
        if isOutDated(index_file):
            try:
                eggs_index_proxy.updatePackageIndex(package_name)
            except PackageNotFound, msg:
                # FIXME: use logging
                print msg
Example #2
0
def updateCache(*args):
    """
    """
    isDir = os.path.isdir
    pathJoin = os.path.join
    update = False
    index_file = pathJoin(EGGS_DIR, 'index.html')

    if isOutDated(index_file):
        eggs_index_proxy.updateBaseIndex()

    for package_name in os.listdir(EGGS_DIR):
        dir_path = pathJoin(EGGS_DIR, package_name)
        if not isDir(dir_path):
            continue

        index_file = pathJoin(dir_path, 'index.html')
        if isOutDated(index_file):
            try:
                eggs_index_proxy.updatePackageIndex(package_name)
            except PackageNotFound, msg:
                # FIXME: use logging
                print msg
def modpython_handler(req):

    options = req.get_options()
    document_root = EGGS_DIR
    url_prefix = options['URLPrefix']
    url_prefix = [part for part in url_prefix.split('/') if part]
    url_prefix_len = len(url_prefix)
    uri_path = req.parsed_uri[apache.URI_PATH]
    uri_path = [part for part in uri_path.split('/') if part][url_prefix_len:]

    if len(uri_path) > 0 and uri_path[-1] == 'index.html':
        uri_path.pop()

    real_path = os.path.join(document_root, *uri_path)
    real_path_exists = os.path.exists(real_path)

    if real_path_exists:
        if not os.path.isdir(real_path):
            return apache.DECLINED

        #FIXME we are doing the job of mod_dir
        real_path = os.path.join(real_path, 'index.html')
        if os.path.exists(real_path):
            req.internal_redirect(req.uri + 'index.html')
##             req.content_type = 'text/html'
##             req.sendfile(real_path)
            return apache.OK

    uri_path_len = len(uri_path)

    if uri_path_len > 2:
        # we are not supposed to go deeper than package/filename.egg
        return apache.HTTP_NOT_FOUND

    if uri_path_len == 0:
        # build the base index
        eggs_index_proxy.updateBaseIndex()
        req.internal_redirect(req.uri + 'index.html')
        return apache.OK

    package_name = uri_path[0]

    if uri_path_len == 1:
        try:
            eggs_index_proxy.updatePackageIndex(package_name)
        except ValueError:
            return apache.HTTP_NOT_FOUND

        req.internal_redirect(req.uri)
        return apache.OK
    else:
        eggname = uri_path[1]

        # avoid downloading the whole version file when pip is just checking
        # whether or not it exists by proxying to the file in the main index
        if req.method == 'HEAD':
            try:
                remote_uri = eggs_index_proxy.remoteURIOfEggFor(package_name, eggname)
            except ValueError:
                return apache.HTTP_NOT_FOUND
            remote_resource = Resource(remote_uri)
            remote_headers = remote_resource.head()
            for name, header in remote_headers.headerslist:
                if name == 'Content-Type':
                    req.content_type = header
                    continue
                req.headers_out[name] = header
            return apache.OK

        try:
            eggs_index_proxy.updateEggFor(package_name, eggname)
        except ValueError:
            return apache.HTTP_NOT_FOUND

        req.internal_redirect(req.uri)
        return apache.OK

    return apache.HTTP_NOT_FOUND
def modpython_handler(req):

    options = req.get_options()
    document_root = EGGS_DIR
    url_prefix = options['URLPrefix']
    url_prefix = [part for part in url_prefix.split('/') if part]
    url_prefix_len = len(url_prefix)
    uri_path = req.parsed_uri[apache.URI_PATH]
    uri_path = [part for part in uri_path.split('/') if part][url_prefix_len:]

    if len(uri_path) > 0 and uri_path[-1] == 'index.html':
        uri_path.pop()

    real_path = os.path.join(document_root, *uri_path)
    real_path_exists = os.path.exists(real_path)

    if real_path_exists:
        if not os.path.isdir(real_path):
            return apache.DECLINED

        #FIXME we are doing the job of mod_dir
        real_path = os.path.join(real_path, 'index.html')
        if os.path.exists(real_path):
            req.internal_redirect(req.uri + 'index.html')
##             req.content_type = 'text/html'
##             req.sendfile(real_path)
            return apache.OK

    uri_path_len = len(uri_path)

    if uri_path_len > 2:
        # we are not supposed to go deeper than package/filename.egg
        return apache.HTTP_NOT_FOUND

    if uri_path_len == 0:
        # build the base index
        eggs_index_proxy.updateBaseIndex()
        req.internal_redirect(req.uri + 'index.html')
        return apache.OK

    package_name = uri_path[0]

    if uri_path_len == 1:
        try:
            eggs_index_proxy.updatePackageIndex(package_name)
        except ValueError:
            return apache.HTTP_NOT_FOUND

        req.internal_redirect(req.uri)
        return apache.OK
    else:
        eggname = uri_path[1]
        try:
            eggs_index_proxy.updateEggFor(package_name, eggname)
        except ValueError:
            return apache.HTTP_NOT_FOUND

        req.internal_redirect(req.uri)
        return apache.OK

    return apache.HTTP_NOT_FOUND