本文整理汇总了Python中pyupdater.client.downloader.FileDownloader类的典型用法代码示例。如果您正苦于以下问题:Python FileDownloader类的具体用法?Python FileDownloader怎么用?Python FileDownloader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileDownloader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cb
def test_cb(self):
def cb(status):
pass
fd = FileDownloader(FILENAME, URLS, hexdigest=FILE_HASH,
progress_hooks=[cb], verify=True)
binary_data = fd.download_verify_return()
assert binary_data is not None
示例2: _download_verify_patches
def _download_verify_patches(self):
# Downloads & verifies all patches
log.debug('Downloading patches')
downloaded = 0
total = len(self.patch_data)
for p in self.patch_data:
# Initialize downloader
fd = FileDownloader(p['patch_name'], p['patch_urls'],
p['patch_hash'], self.verify)
# Attempt to download resource
data = fd.download_verify_return()
if data is not None:
self.patch_binary_data.append(data)
downloaded += 1
status = {'total': total,
'downloaed': downloaded,
'status': 'downloading'}
self._call_progress_hooks(status)
else:
# Since patches are applied sequentially
# we cannot continue successfully
status = {'total': total,
'downloaded': downloaded,
'status': 'failed to download all patches'}
self._call_progress_hooks(status)
return False
status = {'total': total,
'downloaed': downloaded,
'status': 'finished'}
self._call_progress_hooks(status)
return True
示例3: test_basic_auth
def test_basic_auth(self):
headers = {'basic_auth': 'user:pass'}
fd = FileDownloader('test', ['test'], urllb3_headers=headers)
http = fd._get_http_pool(secure=True)
sc = http.request('GET',
'https://httpbin.org/basic-auth/user/pass').status
assert sc == 200
示例4: test_bad_content_length
def test_bad_content_length(self):
class FakeHeaders(object):
headers = {}
fd = FileDownloader(FILENAME, URLS, hexdigest=FILE_HASH, verify=True)
data = FakeHeaders()
assert fd._get_content_length(data) is None
示例5: _full_update
def _full_update(self):
log.debug('Starting full update')
file_hash = self._get_file_hash_from_manifest()
with dsdev_utils.paths.ChDir(self.update_folder):
log.debug('Downloading update...')
fd = FileDownloader(self.filename, self.update_urls,
hexdigest=file_hash, verify=self.verify,
progress_hooks=self.progress_hooks)
result = fd.download_verify_write()
if result:
log.debug('Download Complete')
return True
else: # pragma: no cover
log.debug('Failed To Download Latest Version')
return False
示例6: _download_verify_patches
def _download_verify_patches(self):
# Downloads & verifies all patches
log.debug('Downloading patches')
downloaded = 0
percent = 0
total = len(self.patch_data)
temp_dir = tempfile.gettempdir()
for p in self.patch_data:
# Don't write temp files to cwd
with ChDir(temp_dir):
fd = FileDownloader(p['patch_name'], p['patch_urls'],
hexdigest=p['patch_hash'], verify=self.verify,
max_download_retries=self.max_download_retries,
urllb3_headers=self.urllib3_headers)
# Attempt to download resource
data = fd.download_verify_return()
percent = int((float(downloaded + 1) / float(total)) * 100)
percent = '{0:.1f}'.format(percent)
if data is not None:
self.patch_binary_data.append(data)
downloaded += 1
status = {'total': total,
'downloaded': downloaded,
'percent_complete': percent,
'status': 'downloading'}
self._call_progress_hooks(status)
else:
# Since patches are applied sequentially
# we cannot continue successfully
status = {'total': total,
'downloaded': downloaded,
'percent_complete': percent,
'status': 'failed to download all patches'}
self._call_progress_hooks(status)
return False
status = {'total': total,
'downloaded': downloaded,
'percent_complete': percent,
'status': 'finished'}
self._call_progress_hooks(status)
return True
示例7: _download_manifest
def _download_manifest(self):
log.info('Downloading online version file')
try:
fd = FileDownloader(self.version_file, self.update_urls,
verify=self.verify)
data = fd.download_verify_return()
try:
decompressed_data = gzip_decompress(data)
except IOError:
log.error('Failed to decompress gzip file')
# Will be caught down below. Just logging the error
raise
log.info('Version file download successful')
# Writing version file to application data directory
self._write_manifest_2_filesystem(decompressed_data)
return decompressed_data
except Exception as err:
log.error('Version file download failed')
log.debug(str(err), exc_info=True)
return None
示例8: _full_update
def _full_update(self, name):
log.info('Starting full update')
latest = get_highest_version(name, self.platform, self.easy_data)
filename = get_filename(name, latest, self.platform, self.easy_data)
hash_key = '{}*{}*{}*{}*{}'.format(self.updates_key, name,
latest, self.platform,
'file_hash')
file_hash = self.easy_data.get(hash_key)
with jms_utils.paths.ChDir(self.update_folder):
log.info('Downloading update...')
fd = FileDownloader(filename, self.update_urls,
file_hash, self.verify, self.progress_hooks)
result = fd.download_verify_write()
if result:
log.info('Download Complete')
return True
else: # pragma: no cover
log.error('Failed To Download Latest Version')
return False
示例9: test_good_conent_length
def test_good_conent_length(self):
fd = FileDownloader(FILENAME, URLS, hexdigest=FILE_HASH, verify=True)
fd.download_verify_return()
assert fd.content_length == 2387
示例10: test_bad_url
def test_bad_url(self):
fd = FileDownloader(FILENAME, ['bad url'], hexdigest='bad hash',
verify=True)
binary_data = fd.download_verify_return()
assert binary_data is None
示例11: test_url_with_spaces
def test_url_with_spaces(self):
fd = FileDownloader(FILENAME_WITH_SPACES, URLS,
hexdigest=FILE_HASH, verify=True)
binary_data = fd.download_verify_return()
assert binary_data is not None
示例12: test_return_fail
def test_return_fail(self):
fd = FileDownloader(FILENAME, URLS,
'JKFEIFJILEFJ983NKFNKL', verify=True)
binary_data = fd.download_verify_return()
assert binary_data is None
示例13: test_return
def test_return(self):
fd = FileDownloader(FILENAME, URLS, FILE_HASH, verify=True)
binary_data = fd.download_verify_return()
assert binary_data is not None
示例14: test_good_conent_length
def test_good_conent_length(self):
fd = FileDownloader(FILENAME, URL, FILE_HASH, verify=False)
fd.download_verify_return()
assert fd.content_length == 60000
示例15: test_bad_content_length
def test_bad_content_length(self):
class FakeHeaders(object):
headers = {}
fd = FileDownloader(FILENAME, URL, FILE_HASH, verify=False)
data = FakeHeaders()
assert fd._get_content_length(data) == 100001