[unpackfs] Re-vamp progress reporting
- simplify calculation of progress
This commit is contained in:
parent
8173b68a71
commit
bc591f9bc1
@ -262,6 +262,7 @@ class UnpackOperation:
|
|||||||
def __init__(self, entries):
|
def __init__(self, entries):
|
||||||
self.entries = entries
|
self.entries = entries
|
||||||
self.entry_for_source = dict((x.source, x) for x in self.entries)
|
self.entry_for_source = dict((x.source, x) for x in self.entries)
|
||||||
|
self.total_weight = entries[-1].accumulated_weight + entries[-1].weight
|
||||||
|
|
||||||
def report_progress(self):
|
def report_progress(self):
|
||||||
"""
|
"""
|
||||||
@ -269,30 +270,29 @@ class UnpackOperation:
|
|||||||
"""
|
"""
|
||||||
progress = float(0)
|
progress = float(0)
|
||||||
|
|
||||||
done = 0 # Done and total apply to the entry now-unpacking
|
current_total = 0
|
||||||
total = 0
|
current_done = 0 # Files count in the current entry
|
||||||
complete = 0 # This many are already finished
|
complete_count = 0
|
||||||
|
complete_weight = 0 # This much weight already finished
|
||||||
for entry in self.entries:
|
for entry in self.entries:
|
||||||
if entry.total == 0:
|
if entry.total == 0:
|
||||||
# Total 0 hasn't counted yet
|
# Total 0 hasn't counted yet
|
||||||
continue
|
continue
|
||||||
if entry.total == entry.copied:
|
if entry.total == entry.copied:
|
||||||
complete += 1
|
complete_weight += entry.weight
|
||||||
|
complete_count += 1
|
||||||
else:
|
else:
|
||||||
# There is at most *one* entry in-progress
|
# There is at most *one* entry in-progress
|
||||||
total = entry.total
|
current_total = entry.total
|
||||||
done = entry.copied
|
current_done = entry.copied
|
||||||
|
complete_weight += ( 1.0 * current_done ) / current_total
|
||||||
break
|
break
|
||||||
|
|
||||||
if total > 0:
|
if current_total > 0:
|
||||||
# Pretend that each entry represents an equal amount of work;
|
progress = ( 1.0 * complete_weight ) / self.total_weight
|
||||||
# the complete ones count as 100% of their own fraction
|
|
||||||
# (and have *not* been counted in total or done), while
|
|
||||||
# total/done represents the fraction of the current fraction.
|
|
||||||
progress = ( ( 1.0 * complete ) / len(self.entries) ) + ( ( 1.0 / len(self.entries) ) * ( 1.0 * done / total ) )
|
|
||||||
|
|
||||||
global status
|
global status
|
||||||
status = _("Unpacking image {}/{}, file {}/{}").format((complete+1),len(self.entries),done, total)
|
status = _("Unpacking image {}/{}, file {}/{}").format((complete_count+1), len(self.entries), current_done, current_total)
|
||||||
job.setprogress(progress)
|
job.setprogress(progress)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user