[diffoscope] 01/01: Add a graphical progressbar and show by default if STDOUT is a TTY.
Chris Lamb
chris at chris-lamb.co.uk
Mon Sep 26 18:58:34 CEST 2016
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 432e610f171fc44fea00297d34154dc377b68ccd
Author: Chris Lamb <lamby at debian.org>
Date: Mon Sep 26 18:56:14 2016 +0200
Add a graphical progressbar and show by default if STDOUT is a TTY.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
debian/rules | 3 ++-
diffoscope/main.py | 4 ++++
diffoscope/progress.py | 33 +++++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/debian/rules b/debian/rules
index 9eaf836..90e5761 100755
--- a/debian/rules
+++ b/debian/rules
@@ -35,7 +35,8 @@ override_dh_python3:
--recommends=rpm-python \
--recommends=tlsh \
--recommends=guestfs \
- --recommends=argcomplete
+ --recommends=argcomplete \
+ --recommends=progressbar
override_dh_gencontrol:
TOOLS="$$(bin/diffoscope --list-tools=debian | awk -F': ' '/Available-in-Debian-packages/ { print $$2 }' | \
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 357d821..ac5fe10 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -127,6 +127,10 @@ def create_parser():
help='treat absent files as empty')
parser.add_argument('--status-fd', dest='status_fd', metavar='N', type=int,
help='Send machine-readable status to file descriptor N')
+ parser.add_argument('--progress', dest='progress', action='store_const',
+ const=True, help='show an (approximate) progress bar')
+ parser.add_argument('--no-progress', dest='progress', action='store_const',
+ const=False, help='do not show an (approximate) progress bar')
parser.add_argument('--css', metavar='url', dest='css_url',
help='link to an extra CSS for the HTML report')
parser.add_argument('--jquery', metavar='url', dest='jquery_url',
diff --git a/diffoscope/progress.py b/diffoscope/progress.py
index 9882a6d..15a569a 100644
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -18,6 +18,7 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import os
+import sys
class ProgressManager(object):
_singleton = {}
@@ -31,6 +32,17 @@ class ProgressManager(object):
self.observers = []
def setup(self, parsed_args):
+ # Show progress bar if user explicitly asked for it, otherwise show if
+ # STDOUT is a tty.
+ if parsed_args.progress or \
+ (parsed_args.progress is None and sys.stdout.isatty()):
+ try:
+ self.register(ProgressBar())
+ except ImportError:
+ # User asked for bar, so show them the error
+ if parsed_args.progress:
+ raise
+
if parsed_args.status_fd:
self.register(StatusFD(parsed_args.status_fd))
@@ -78,6 +90,27 @@ class Progress(object):
self.current += delta
ProgressManager().step(delta)
+class ProgressBar(object):
+ def __init__(self):
+ import progressbar
+
+ self.bar = progressbar.ProgressBar(widgets=(
+ progressbar.Bar(),
+ ' ',
+ progressbar.Percentage(),
+ ' ',
+ progressbar.ETA(),
+ ))
+ self.bar.start()
+
+ def notify(self, current, total):
+ self.bar.maxval = total
+ self.bar.currval = current
+ self.bar.update()
+
+ def finish(self):
+ self.bar.finish()
+
class StatusFD(object):
def __init__(self, fileno):
self.fileobj = os.fdopen(fileno, 'w')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list