[unpackfs] Rework progress reporting

- Slice overall progress into chunks, with each chunk of equal size
  (as long as we have no overall count information) and place
  the progress of the current chunk into its own slice.
This commit is contained in:
Adriaan de Groot 2020-04-04 23:42:20 +02:00
parent 7e4cb28c1c
commit 9b14bf6826

View File

@ -269,19 +269,27 @@ class UnpackOperation:
"""
progress = float(0)
done = 0
done = 0 # Done and total apply to the entry now-unpacking
total = 0
complete = 0
complete = 0 # This many are already finished
for entry in self.entries:
if entry.total == 0:
# Total 0 hasn't counted yet
continue
total += entry.total
done += entry.copied
if entry.total == entry.copied:
complete += 1
else:
# There is at most *one* entry in-progress
total = entry.total
done = entry.copied
break
if done > 0 and total > 0:
progress = 0.05 + (0.90 * done / total) + (0.05 * complete / len(self.entries))
# Pretend that each entry represents an equal amount of work;
# 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) ) * done / total )
job.setprogress(progress)