@app.task<EOL>def download_file(pk):
release_file = models.ReleaseFile.objects.get(pk=pk)<EOL>logging.info("<STR_LIT>", release_file.url)<EOL>proxies = None<EOL>if settings.LOCALSHOP_HTTP_PROXY:<EOL><INDENT>proxies = settings.LOCALSHOP_HTTP_PROXY<EOL><DEDENT>response = requests.get(release_file.url, stream=True, proxies=proxies)<EOL>filename = os.path.basename(release_file.url)<EOL>if '<STR_LIT>' in response.headers:<EOL><INDENT>size = int(response.headers['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>size = len(response.content)<EOL><DEDENT>default_content_type = '<STR_LIT>'<EOL>content_type = response.headers.get('<STR_LIT>')<EOL>if content_type is None or content_type == default_content_type:<EOL><INDENT>content_type = mimetypes.guess_type(filename)[<NUM_LIT:0>] or default_content_type<EOL><DEDENT>with TemporaryUploadedFile(name=filename, size=size, charset='<STR_LIT:utf-8>',<EOL>content_type=content_type) as temp_file:<EOL><INDENT>temp_file.write(response.content)<EOL>temp_file.seek(<NUM_LIT:0>)<EOL>md5_hash = md5_hash_file(temp_file)<EOL>if md5_hash != release_file.md5_digest:<EOL><INDENT>logging.error("<STR_LIT>" % (<EOL>md5_hash, release_file.md5_digest))<EOL>return<EOL><DEDENT>release_file.distribution.save(filename, temp_file)<EOL>release_file.save()<EOL><DEDENT>logging.info("<STR_LIT>")<EOL>
Download the file reference in `models.ReleaseFile` with the given pk.