예제 #1
0
파일: peepin.py 프로젝트: peterbe/peepin
def get_hashes(data, version, verbose=False):
    yielded = []
    try:
        releases = data['releases'][version]
    except KeyError:
        raise PackageError('No data found for version {0}'.format(version))
    for found in releases:
        url = found['url']
        if verbose:
            _verbose("Found URL", url)
        download_dir = tempfile.gettempdir()
        filename = os.path.join(
            download_dir,
            os.path.basename(url.split('#')[0])
        )
        if not os.path.isfile(filename):
            if verbose:
                _verbose("  Downloaded to", filename)
            with open(filename, 'wb') as f:
                f.write(_download(url, binary=True))
        elif verbose:
            _verbose("  Re-using", filename)
        hash_ = peep.hash_of_file(filename)
        if hash_ in yielded:
            continue
        if verbose:
            _verbose("  Hash", hash_)
        yield hash_
        yielded.append(hash_)

    if not yielded:
        raise PackageError(
            "No packages could be found on {0}".format(url)
        )
예제 #2
0
파일: peepin.py 프로젝트: davehunt/peepin
def get_hashes(package, version, verbose=False):

    url = 'https://pypi.python.org/pypi/%s/json' % package
    if verbose:
        print(url)
    content = json.loads(_download(url))
    yielded = []
    try:
        latest_version = content['info']['version']
        releases = content['releases'][latest_version]
    except KeyError:
        raise PackageError('package JSON is not sane')
    for found in releases:
        url = found['url']
        if verbose:
            _verbose("Found URL", url)
        download_dir = tempfile.gettempdir()
        filename = os.path.join(
            download_dir,
            os.path.basename(url.split('#')[0])
        )
        if not os.path.isfile(filename):
            if verbose:
                _verbose("  Downloaded to", filename)
            with open(filename, 'wb') as f:
                f.write(_download(url, binary=True))
        elif verbose:
            _verbose("  Re-using", filename)
        hash_ = peep.hash_of_file(filename)
        if hash_ in yielded:
            continue
        if verbose:
            _verbose("  Hash", hash_)
        yield hash_
        yielded.append(hash_)

    if not yielded:
        raise PackageError(
            "No packages could be found on {0}".format(url)
        )
예제 #3
0
파일: peepin.py 프로젝트: pmclanahan/peepin
def get_hashes(package, version, verbose=False):

    url = 'https://pypi.python.org/pypi/%s/json' % package
    if verbose:
        print(url)
    content = json.loads(_download(url))
    yielded = []
    try:
        latest_version = content['info']['version']
        releases = content['releases'][latest_version]
    except KeyError:
        raise PackageError('package JSON is not sane')
    for found in releases:
        url = found['url']
        if verbose:
            _verbose("Found URL", url)
        download_dir = tempfile.gettempdir()
        filename = os.path.join(download_dir,
                                os.path.basename(url.split('#')[0]))
        if not os.path.isfile(filename):
            if verbose:
                _verbose("  Downloaded to", filename)
            with open(filename, 'wb') as f:
                f.write(_download(url, binary=True))
        elif verbose:
            _verbose("  Re-using", filename)
        hash_ = peep.hash_of_file(filename)
        if hash_ in yielded:
            continue
        if verbose:
            _verbose("  Hash", hash_)
        yield hash_
        yielded.append(hash_)

    if not yielded:
        raise PackageError("No packages could be found on {0}".format(url))