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) )
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) )
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))