[diffoscope] 03/03: Make the progress bar play nicely with --debug
Ximin Luo
infinity0 at debian.org
Wed May 24 19:23:29 CEST 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch experimental
in repository diffoscope.
commit 6c6d0b8f5a45bbc62949c4ebc2f1d9caf38d5885
Author: Ximin Luo <infinity0 at debian.org>
Date: Wed May 24 19:23:16 2017 +0200
Make the progress bar play nicely with --debug
---
diffoscope/logging.py | 4 ++--
diffoscope/main.py | 4 ++--
diffoscope/progress.py | 25 +++++++++++++++++++++----
3 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/diffoscope/logging.py b/diffoscope/logging.py
index f8d6d6b..38bb9bf 100644
--- a/diffoscope/logging.py
+++ b/diffoscope/logging.py
@@ -20,11 +20,11 @@
import logging
-def setup_logging(debug):
+def setup_logging(debug, log_handler):
logger = logging.getLogger()
logger.setLevel(logging.DEBUG if debug else logging.WARNING)
- ch = logging.StreamHandler()
+ ch = log_handler or logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 60f8771..baa9448 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -267,7 +267,8 @@ def maybe_set_limit(config, parsed_args, key):
def run_diffoscope(parsed_args):
- setup_logging(parsed_args.debug)
+ log_handler = ProgressManager().setup(parsed_args)
+ setup_logging(parsed_args.debug, log_handler)
ProfileManager().setup(parsed_args)
PresenterManager().configure(parsed_args)
logger.debug("Starting diffoscope %s", VERSION)
@@ -289,7 +290,6 @@ def run_diffoscope(parsed_args):
set_path()
set_locale()
logger.debug('Starting comparison')
- ProgressManager().setup(parsed_args)
with Progress(1, parsed_args.path1):
with profile('main', 'outputs'):
difference = compare_root_paths(
diff --git a/diffoscope/progress.py b/diffoscope/progress.py
index 0cfb0c1..49a36f6 100644
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -25,6 +25,20 @@ import logging
logger = logging.getLogger(__name__)
+class ProgressLoggingHandler(logging.StreamHandler):
+
+ def __init__(self, progressbar):
+ self.progressbar = progressbar
+ logging.StreamHandler.__init__(self)
+
+ def emit(self, record):
+ # delete the current line (i.e. the progress bar)
+ self.stream.write("\r\033[K")
+ self.flush()
+ logging.StreamHandler.emit(self, record)
+ if not self.progressbar.bar.finished:
+ self.progressbar.bar.update()
+
class ProgressManager(object):
_singleton = {}
@@ -45,15 +59,18 @@ class ProgressManager(object):
if parsed_args.progress:
return True
- # ... otherwise show it if STDOUT is a tty and debug is not set
+ # ... otherwise show it if STDOUT is a tty
if parsed_args.progress is None:
- return sys.stdout.isatty() and not parsed_args.debug
+ return sys.stdout.isatty()
return False
+ log_handler = None
if show_progressbar():
try:
- self.register(ProgressBar())
+ bar = ProgressBar()
+ self.register(bar)
+ log_handler = ProgressLoggingHandler(bar)
except ImportError:
# User asked for bar, so show them the error
if parsed_args.progress:
@@ -62,7 +79,7 @@ class ProgressManager(object):
if parsed_args.status_fd:
self.register(StatusFD(os.fdopen(parsed_args.status_fd, 'w')))
- ##
+ return log_handler
def register(self, observer):
logger.debug("Registering %s as a progress observer", observer)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list