def load_resp(self, resp, is_download):
"""
Loads json response from API.
:param resp: Response from API
:type resp: dictionary
:param is_download: Calculates time taken based on 'updated' field in response if upload, and based on stop time if download
:type is_download: boolean
"""
assert isinstance(resp, dict)
setattr(self, 'resp', resp)
setattr(self, 'size', humanize.naturalsize(int(resp['size'])))
if is_download:
updated_at = datetime.now(UTC)
else:
updated_at = UTC.localize(datetime.strptime(resp['updated'], '%Y-%m-%dT%H:%M:%S.%fZ'))
setattr(self, 'time_taken', dict(zip(
('m', 's'),
divmod((updated_at - getattr(self, 'start_time')).seconds if updated_at > getattr(self, 'start_time') else 0, 60)
)))
setattr(self, 'full_path', 'gs://%s/%s' % (resp['bucket'], resp['name']))
评论列表
文章目录