improved progressbar
This commit is contained in:
parent
5f735c25de
commit
afc3c859b0
@ -46,18 +46,18 @@ class Target(DatabaseObject):
|
|||||||
@property
|
@property
|
||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
return [('filepath', self.file_path)]
|
return [('filepath', self.file_path)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def exists(self) -> bool:
|
def exists(self) -> bool:
|
||||||
return self.file_path.is_file()
|
return self.file_path.is_file()
|
||||||
|
|
||||||
def create_path(self):
|
def create_path(self):
|
||||||
self._path.mkdir(parents=True, exist_ok=True)
|
self._path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
def copy_content(self, copy_to: "Target"):
|
def copy_content(self, copy_to: "Target"):
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(self.file_path, "rb") as read_from:
|
with open(self.file_path, "rb") as read_from:
|
||||||
copy_to.create_path()
|
copy_to.create_path()
|
||||||
with open(copy_to.file_path, "wb") as write_to:
|
with open(copy_to.file_path, "wb") as write_to:
|
||||||
@ -66,28 +66,28 @@ class Target(DatabaseObject):
|
|||||||
def stream_into(self, r: requests.Response) -> bool:
|
def stream_into(self, r: requests.Response) -> bool:
|
||||||
if r is None:
|
if r is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.create_path()
|
self.create_path()
|
||||||
|
|
||||||
chunk_size = 1024
|
chunk_size = 1024
|
||||||
|
|
||||||
total_size = int(r.headers.get('content-length'))
|
total_size = int(r.headers.get('content-length'))
|
||||||
print(total_size)
|
|
||||||
initial_pos = 0
|
with open(self.file_path, 'wb') as f:
|
||||||
|
|
||||||
|
|
||||||
with open(self.file_path,'wb') as f:
|
|
||||||
try:
|
try:
|
||||||
"""
|
"""
|
||||||
https://en.wikipedia.org/wiki/Kilobyte
|
https://en.wikipedia.org/wiki/Kilobyte
|
||||||
> The internationally recommended unit symbol for the kilobyte is kB.
|
> The internationally recommended unit symbol for the kilobyte is kB.
|
||||||
"""
|
"""
|
||||||
for chunk in tqdm(r.iter_content(chunk_size=chunk_size), unit_scale=True, unit="B", total=total_size):
|
with tqdm(total=total_size, unit='B', unit_scale=True, unit_divisor=1024) as t:
|
||||||
size = f.write(chunk)
|
for chunk in r.iter_content(chunk_size=chunk_size):
|
||||||
|
size = f.write(chunk)
|
||||||
|
t.update(size)
|
||||||
|
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
shared.DOWNLOAD_LOGGER.error("Stream timed out.")
|
shared.DOWNLOAD_LOGGER.error("Stream timed out.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# doesn't work yet due to
|
# doesn't work yet due to
|
||||||
# https://github.com/tqdm/tqdm/issues/261
|
# https://github.com/tqdm/tqdm/issues/261
|
||||||
@ -99,5 +99,5 @@ class Target(DatabaseObject):
|
|||||||
size = f.write(chunk)
|
size = f.write(chunk)
|
||||||
pbar.update(size)
|
pbar.update(size)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user