def get(package_id, package_version, urls, download_location): package_found = False log.info("Searching for package: "+str(package_id)+" in "+str(urls)) if not os.path.exists(download_location): os.makedirs(download_location) handle = None if '://' in urls: with urllib.request.urlopen(urls) as uf: handle = StringIO(uf.read()) elif os.path.exists(urls): handle = open(urls, 'r') else: raise Exception("--urls option does not look like a url or a file path") for ld in yield_packages(handle): # TODO: check platform/architecture, failover to all if available? # iid, version, platform, architecture, upstream_url, checksum, alternate_url = line.split('\t') if ld['id'] == package_id.strip() and (package_version == None or ld['version'] == package_version): package_found = True # I worry about this being unreliable. TODO: add target filename column? pkg_name = package_name(ld) storage_path = os.path.join(download_location, pkg_name) url = get_url(ld) urllib.request.urlretrieve(url, storage_path) download_checksum = hashlib.sha256(open(storage_path, 'rb').read()).hexdigest() if ld['sha256sum'] != download_checksum: log.error('Checksum does not match, something seems to be wrong.\n' '{expected}\t(expected)\n{actual}\t(downloaded)').format( expected=ld['sha256sum'], actual=download_checksum) else: log.info('Download successful for %s.' % (pkg_name)) if not package_found: log.warning('Package (%s) could not be found in this server.' % (package_id))
def get(package_id, package_version, download_location): package_found = False database = PACKAGE_SERVER + 'urls.tsv' log.info("Searching for package: "+str(package_id)+" in "+str(database)) if not os.path.exists(download_location): os.makedirs(download_location) for ld in yield_packages(urllib2.urlopen(database)): # TODO: check platform/architecture, failover to all if available? # iid, version, platform, architecture, upstream_url, checksum, alternate_url = line.split('\t') if ld['id'] == package_id.strip() and ld['platform']== 'src' and (package_version == None or ld['version'] == package_version): package_found = True # I worry about this being unreliable. TODO: add target filename column? pkg_name = package_name(ld) storage_path = os.path.join(download_location, pkg_name) url = get_url(ld) urllib.urlretrieve(url, storage_path) download_checksum = hashlib.sha256(open(storage_path, 'rb').read()).hexdigest() if ld['sha256sum'] != download_checksum: log.error('Checksum does not match, something seems to be wrong.\n' '{expected}\t(expected)\n{actual}\t(downloaded)').format( expected=ld['sha256sum'], actual=download_checksum) else: log.info('Download successful for %s.' % (pkg_name)) if not package_found: log.warning('Package (%s) could not be found in this server.' % (package_id))
def main(galaxy_package_file, id, version=None): with open(galaxy_package_file, 'r') as handle: for ld in yield_packages(handle): if ld['id'].lower() != id.lower(): continue if version is not None and ld['version'].lower() != version.lower(): continue print """<action type="download_by_url" sha256sum="{0[sha]}"> {1} </action>""".format(ld, get_url(ld))
def main(galaxy_package_file, id, version=None): with open(galaxy_package_file, 'r') as handle: for ld in yield_packages(handle): if ld['id'].lower() != id.lower(): continue if version is not None and ld['version'].lower() != version.lower(): continue print("""<action type="download_by_url" sha256sum="{0[sha]}"> {1} </action>""".format(ld, get_url(ld)))