Пример #1
0
def simple():
    ''' Return the template which list all the packages that are installed
    '''
    packages = []
    for filename in listdir(get_base_path()):
        packages.append(filename)
    return render_template('simple.html', packages=packages)
Пример #2
0
def simple():
    ''' Return the template which list all the packages that are installed
    '''
    packages = []
    for filename in listdir(get_base_path()):
        packages.append(filename)

    packages.sort()
    return render_template('simple.html', packages=packages)
Пример #3
0
def package(package_type, letter, package_name, package_file):
    ''' Downloads the egg

    :param str package_type: the nature of the package. For example:
                              'source' or '2.7'
    :param str letter: the first char of the package name. For example:
                              D
    :param str package_name: the name of the package. For example: Django
    :param str package_file: the name of the package and it's version. For
                             example: Django-1.5.0.tar.gz
    '''
    egg_filename = join(get_base_path(), package_name, package_file)
    url = request.args.get('remote')

    if request.method == 'HEAD':
        # in this case the content type of the file is what is
        # required
        if not exists(egg_filename):
            pypi_response = head(url)
            return _respond(pypi_response.content, pypi_response.headers['content-type'])

        else:
            mimetype = magic.from_file(egg_filename, mime=True)
            return _respond('', mimetype)

    app.logger.debug('Downloading: %s', package_file)
    if exists(egg_filename):
        app.logger.debug('Found local file in repository for: %s', package_file)
        # if the file exists, then use the local file.
        path = get_package_path(package_name)
        path = join(path, package_file)
        with open(path, 'rb') as egg:
            content = egg.read(-1)
        mimetype = magic.from_file(egg_filename, mime=True)
        return _respond(content, mimetype)

    else:
        # Downloads the egg from pypi and saves it locally, then
        # it will return it.
        package_path = get_package_path(package_name)
        app.logger.debug('Starting to download: %s using the url: %s',
                         package_file, url)
        pypi_response = get(url)
        app.logger.debug('Finished downloading package: %s', package_file)

        if pypi_response.status_code != 200:
            app.logger.warning('Error respose while downloading for proxy: %s'
                               'Response details: %s', package_file,
                               pypi_response.text)
            abort(pypi_response.status_code)

        if not exists(package_path):
            makedirs(package_path)

        with open(egg_filename, 'w') as egg_file:
            egg_file.write(pypi_response.content)

        with open(egg_filename) as egg_file:
            filecontent = egg_file.read(-1)
            mimetype = magic.from_file(egg_filename, mime=True)

        with open(egg_filename + '.md5', 'w') as md5_output:
            md5 = get_md5_for_content(filecontent)
            md5_output.write(md5)

        return _respond(filecontent, mimetype)
Пример #4
0
def package(package_type, letter, package_name, package_file):
    """ Downloads the egg

    :param str package_type: the nature of the package. For example:
                              'source' or '2.7'
    :param str letter: the first char of the package name. For example:
                              D
    :param str package_name: the name of the package. For example: Django
    :param str package_file: the name of the package and it's version. For
                             example: Django-1.5.0.tar.gz
    """
    egg_filename = join(get_base_path(), package_name, package_file)
    url = unquote(request.args.get('remote'))

    if request.method == 'HEAD':
        # in this case the content type of the file is what is
        # required
        if not exists(egg_filename):
            pypi_response = head(url)
            return _respond(pypi_response.content,
                            pypi_response.headers['content-type'])

        else:
            mimetype = magic.from_file(egg_filename, mime=True)
            return _respond('', mimetype)

    app.logger.debug('Downloading: %s', package_file)
    if exists(egg_filename):
        app.logger.debug('Found local file in repository for: %s',
                         package_file)
        # if the file exists, then use the local file.
        path = get_package_path(package_name)
        path = join(path, package_file)
        with open(path, 'rb') as egg:
            content = egg.read()
        mimetype = magic.from_file(egg_filename, mime=True)
        return _respond(content, mimetype)

    else:
        # Downloads the egg from pypi and saves it locally, then
        # it will return it.
        package_path = get_package_path(package_name)
        app.logger.debug('Starting to download: %s using the url: %s',
                         package_file, url)
        pypi_response = get(url)
        app.logger.debug('Finished downloading package: %s', package_file)

        if pypi_response.status_code != 200:
            app.logger.warning(
                'Error respose while downloading for proxy: %s'
                'Response details: %s', package_file, pypi_response.text)
            abort(pypi_response.status_code)

        if not exists(package_path):
            makedirs(package_path)

        with open(egg_filename, 'wb') as egg_file:
            egg_file.write(pypi_response.content)

        with open(egg_filename, 'rb') as egg_file:
            filecontent = egg_file.read()
            mimetype = magic.from_file(egg_filename, mime=True)

        with open(egg_filename + '.sha256', 'w') as sha256_output:
            sha256 = get_sha256_for_content(filecontent)
            sha256_output.write(sha256)

        return _respond(filecontent, mimetype)