[diffoscope] 01/01: Show filename(s) etc in progressbar.
Chris Lamb
chris at chris-lamb.co.uk
Wed Dec 28 17:21:05 CET 2016
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 5ea56d8b57a3a6a46a216a0da12bc7b2f019d1cf
Author: Chris Lamb <lamby at debian.org>
Date: Wed Dec 28 16:13:31 2016 +0000
Show filename(s) etc in progressbar.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/directory.py | 2 +-
diffoscope/comparators/utils/container.py | 8 +++----
diffoscope/progress.py | 37 +++++++++++++++++++++++--------
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index f6843a1..6a4cee1 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -177,7 +177,7 @@ class FilesystemDirectory(object):
if inner_difference:
inner_difference.add_details(meta_differences)
differences.append(inner_difference)
- p.step()
+ p.step(msg=name)
if not differences:
return None
difference = Difference(None, self.path, other.path, source)
diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index 93b30cd..d15028b 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -95,21 +95,21 @@ class Container(object, metaclass=abc.ABCMeta):
my_member_name, my_member = my_members.popitem(last=False)
if my_member_name in other_members:
yield my_member, other_members.pop(my_member_name), NO_COMMENT
- p.step()
+ p.step(msg=my_member.name)
else:
my_reminders[my_member_name] = my_member
my_members = my_reminders
for my_name, other_name, score in perform_fuzzy_matching(my_members, other_members):
comment = 'Files similar despite different names (difference score: %d)' % score
yield my_members.pop(my_name), other_members.pop(other_name), comment
- p.step(2)
+ p.step(2, msg=my_name)
if Config().new_file:
for my_member in my_members.values():
yield my_member, MissingFile('/dev/null', my_member), NO_COMMENT
- p.step()
+ p.step(msg="bar")
for other_member in other_members.values():
yield MissingFile('/dev/null', other_member), other_member, NO_COMMENT
- p.step()
+ p.step(msg=other_member)
def compare(self, other, source=None):
from .compare import compare_commented_files
diff --git a/diffoscope/progress.py b/diffoscope/progress.py
index 4ce43bc..08c8e05 100644
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -51,19 +51,19 @@ class ProgressManager(object):
def register(self, observer):
self.observers.append(observer)
- def step(self, delta=1):
+ def step(self, delta=1, msg=""):
delta = min(self.total - self.current, delta) # clamp
if not delta:
return
self.current += delta
for x in self.observers:
- x.notify(self.current, self.total)
+ x.notify(self.current, self.total, msg)
- def new_total(self, delta):
+ def new_total(self, delta, msg):
self.total += delta
for x in self.observers:
- x.notify(self.current, self.total)
+ x.notify(self.current, self.total, msg)
def finish(self):
for x in self.observers:
@@ -74,7 +74,7 @@ class Progress(object):
self.current = 0
self.total = total
- ProgressManager().new_total(total)
+ ProgressManager().new_total(total, "")
def __enter__(self):
return self
@@ -82,28 +82,47 @@ class Progress(object):
def __exit__(self, exc_type, exc_value, exc_traceback):
self.step(self.total - self.current)
- def step(self, delta=1):
+ def step(self, delta=1, msg=""):
delta = min(self.total - self.current, delta) # clamp
if not delta:
return
self.current += delta
- ProgressManager().step(delta)
+ ProgressManager().step(delta, msg)
class ProgressBar(object):
def __init__(self):
import progressbar
+ self.msg = ""
+
+ class Message(progressbar.Widget):
+ def update(self, pbar, _observer=self):
+ msg = _observer.msg
+ width = 20
+
+ if len(msg) <= width:
+ return msg.ljust(width)
+
+ # Print the last `width` characters with an ellipsis.
+ return '…{}'.format(msg[-width + 1:])
+
self.bar = progressbar.ProgressBar(widgets=(
+ ' ',
progressbar.Bar(),
' ',
progressbar.Percentage(),
' ',
+ Message(),
+ ' ',
progressbar.ETA(),
+ ' ',
))
self.bar.start()
- def notify(self, current, total):
+ def notify(self, current, total, msg):
+ self.msg = msg
+
self.bar.maxval = total
self.bar.currval = current
self.bar.update()
@@ -115,7 +134,7 @@ class StatusFD(object):
def __init__(self, fileno):
self.fileobj = os.fdopen(fileno, 'w')
- def notify(self, current, total):
+ def notify(self, current, total, msg):
print('{}\t{}'.format(current, total), file=self.fileobj)
def finish(self):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list