Commit 8e09feed by Őry Máté

refactor percent counting in Disk.download

parent 6462577a
...@@ -120,9 +120,6 @@ class Disk(object): ...@@ -120,9 +120,6 @@ class Disk(object):
pass pass
if parent_id is None: if parent_id is None:
parent_id = task.request.id parent_id = task.request.id
percent_size = float(r.headers['content-length']) / 100
percent = 0
actual_size = 0
chunk_size = 256 * 1024 chunk_size = 256 * 1024
ext = url.split('.')[-1].lower() ext = url.split('.')[-1].lower()
if ext == 'gz': if ext == 'gz':
...@@ -139,16 +136,15 @@ class Disk(object): ...@@ -139,16 +136,15 @@ class Disk(object):
raise AbortException() raise AbortException()
if ext in ('gz', 'bz'): if ext in ('gz', 'bz'):
chunk = decompressor.decompress(chunk) chunk = decompressor.decompress(chunk)
if chunk: f.write(chunk)
f.write(chunk) actsize = f.tell()
actual_size += chunk_size new_percent = min(100, round(actsize * 100.0 / clen))
if actual_size > (percent_size * percent): if new_percent > percent:
percent += 1 percent = new_percent
task.update_state( task.update_state(
task_id=parent_id, task_id=parent_id,
state=task.AsyncResult(parent_id).state, state=task.AsyncResult(parent_id).state,
meta={'size': actual_size, meta={'size': actsize, 'percent': percent})
'percent': percent})
if ext == 'gz': if ext == 'gz':
f.write(decompressor.flush()) f.write(decompressor.flush())
f.flush() f.flush()
...@@ -170,7 +166,7 @@ class Disk(object): ...@@ -170,7 +166,7 @@ class Disk(object):
task.update_state( task.update_state(
task_id=parent_id, task_id=parent_id,
state=task.AsyncResult(parent_id).state, state=task.AsyncResult(parent_id).state,
meta={'size': actual_size, 'extracting': 'zip', meta={'size': actsize, 'extracting': 'zip',
'percent': 99}) 'percent': 99})
self.extract_iso_from_zip(disk_path) self.extract_iso_from_zip(disk_path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment