INNER CODE UNIT · Python
md5sum
kblin/ncbi-genome-download · ncbi_genome_download/core.py:626
def md5sum(filename):
"""Calculate the md5sum of a file and return the hexdigest."""
hash_md5 = hashlib.md5()
with open(filename, 'rb') as handle:
for chunk in iter(lambda: handle.read(4096), b''):
hash_md5.update(chunk)
return hash_md5.hexdigest()
# pylint and I disagree on code style here. Shut up, pylint.
# pylint: disable=too-many-arguments
def download_file_job(entry, directory, checksums, filetype='genbank', symlink_path=None):
"""Generate a DownloadJob that actually triggers a file download."""
pattern = NgdConfig.get_fileending(filetype)
filename, expected_checksum = get_name_and_checksum(checksums, pattern)
base_url = convert_ftp_url(entry['ftp_path'])
full_url = '{}/{}'.format(base_url, filename)
local_file = os.path.join(directory, filename)