From 37ea434a29e7919e5aca9a13374a6d5d380d4eb5 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 8 Oct 2010 22:11:11 +0200 Subject: ranger.core.loader: allow suppressing errors in CommandLoader --- ranger/core/loader.py | 32 +++++++++++++++++++------------- ranger/fsobject/file.py | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ranger/core/loader.py b/ranger/core/loader.py index c03ecc29..1ea50f4d 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -55,27 +55,33 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware): object is removed from the queue (type ^C in ranger) """ finished = False - def __init__(self, args, descr): + def __init__(self, args, descr, silent=False): SignalDispatcher.__init__(self) Loadable.__init__(self, self.generate(), descr) self.args = args + self.silent = silent def generate(self): self.process = process = Popen(self.args, stdout=PIPE, stderr=PIPE) self.signal_emit('before', process=process) - while process.poll() is None: - try: - rd, _, __ = select.select( - [process.stderr], [], [], 0.05) - if rd: - error = process.stderr.readline().decode('utf-8') - if error: - self.fm.notify(error, bad=True) - except select.error: - pass -# sleep(0.02) - yield + if self.silent: + while process.poll() is None: + yield + sleep(0.02) + else: + while process.poll() is None: + yield + try: + rd, _, __ = select.select( + [process.stderr], [], [], 0.03) + if rd: + error = process.stderr.readline().decode('utf-8') + if error: + self.fm.notify(error, bad=True) + except select.error: + pass + sleep(0.01) self.finished = True self.signal_emit('after', process=process) diff --git a/ranger/fsobject/file.py b/ranger/fsobject/file.py index 2701537c..4076b136 100644 --- a/ranger/fsobject/file.py +++ b/ranger/fsobject/file.py @@ -111,7 +111,7 @@ class File(FileSystemObject): self.preview_loading = True loadable = CommandLoader(args=[self.fm.settings.preview_script, self.path, str(width), str(height)], - descr="Getting preview of %s" % self.path) + silent=True, descr="Getting preview of %s" % self.path) loadable.signal_bind('after', self._update_preview, weak=True) self.fm.loader.add(loadable) return None -- cgit 1.4.1-2-gfad0