[diffoscope] 01/02: Tidy diffoscope.progress a little.
Chris Lamb
chris at chris-lamb.co.uk
Fri Aug 25 08:37:19 CEST 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 355ea40e2d508525ec4cf7eaf3f420cb4f998d99
Author: Chris Lamb <lamby at debian.org>
Date: Fri Aug 25 07:31:26 2017 +0100
Tidy diffoscope.progress a little.
---
diffoscope/progress.py | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/diffoscope/progress.py b/diffoscope/progress.py
index 20ae769..76f0cd1 100644
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -24,26 +24,26 @@ import logging
logger = logging.getLogger(__name__)
-class ProgressLoggingHandler(logging.StreamHandler):
+class ProgressLoggingHandler(logging.StreamHandler):
def __init__(self, progressbar):
self.progressbar = progressbar
super().__init__()
def emit(self, record):
try:
- # delete the current line (i.e. the progress bar)
+ # Delete the current line (i.e. the progress bar)
self.stream.write("\r\033[K")
self.flush()
super().emit(record)
if not self.progressbar.bar.finished:
self.progressbar.bar.update()
except Exception:
- # have to do this try-except wrapping otherwise tests fail
- # due to test_progress.py running main() several times.
- # this mirrors the super() implementation.
+ # Wrap otherwise tests fail due to test_progress.py call main()
+ # several times. This mirrors the super() implementation.
self.handleError(record)
+
class ProgressManager(object):
_singleton = {}
@@ -115,6 +115,7 @@ class ProgressManager(object):
for x in self.observers:
x.finish()
+
class Progress(object):
def __init__(self, total=None):
self.done = []
@@ -141,17 +142,20 @@ class Progress(object):
if self.current_steps:
if self.current_child_steps_done or cur_child_estimate:
- # something is in-progress, the calculation is slightly more complex
+ # Something is in-progress, the calculation is slightly more
+ # complex
cur_child_done, cur_child_total = cur_child_estimate or (0, 0)
own_done += self.current_steps
- all_done += self.current_steps + self.current_child_steps_done + cur_child_done
- # cost of what we expect will have been done, once the current in-progress
- # step plus all of its children, have completed
- expected_all_done = all_done + (cur_child_total - cur_child_done)
- assert own_done # non-zero
- return all_done, int(float(self.total) / own_done * expected_all_done)
- else:
- pass # nothing in progress
+ all_done += self.current_steps + \
+ self.current_child_steps_done + \
+ cur_child_done
+ # Cost of what we expect will have been done, once the current
+ # in-progress step plus all of its children, have completed
+ expected_all_done = all_done + \
+ (cur_child_total - cur_child_done)
+ assert own_done # non-zero
+ return all_done, int(float(self.total) / own_done \
+ * expected_all_done)
else:
# nothing in progress
assert not cur_child_estimate
@@ -182,6 +186,7 @@ class Progress(object):
def child_done(self, total):
self.current_child_steps_done += total
+
class ProgressBar(object):
def __init__(self):
import progressbar
@@ -202,7 +207,7 @@ class ProgressBar(object):
class OurProgressBar(progressbar.ProgressBar):
def __init__(self, *args, **kwargs):
# Remove after https://github.com/niltonvolpato/python-progressbar/pull/57 is fixed.
- kwargs.setdefault("fd", sys.stderr)
+ kwargs.setdefault('fd', sys.stderr)
super().__init__(*args, **kwargs)
def _need_update(self):
@@ -231,6 +236,7 @@ class ProgressBar(object):
def finish(self):
self.bar.finish()
+
class StatusFD(object):
def __init__(self, fileobj):
self.fileobj = fileobj
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list