diff options
author | hut <hut@lavabit.com> | 2010-10-08 20:28:56 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-10-08 20:28:56 +0200 |
commit | 085934209cdfe195b7621a6e722c5688da3d7c1c (patch) | |
tree | 2de03a65d7719aa5d06322df893f47a8c9d5b1ac /ranger | |
parent | c9c0a362c86f630bd5f8bf6848659584fa1576fa (diff) | |
download | ranger-085934209cdfe195b7621a6e722c5688da3d7c1c.tar.gz |
core.loader: use signals with CommandLoader
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/core/actions.py | 7 | ||||
-rw-r--r-- | ranger/core/loader.py | 17 |
2 files changed, 11 insertions, 13 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 1dc51502..e290db58 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -695,8 +695,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): descr = "moving files from: " + one_file.dirname obj = CommandLoader(args=['mv', '--backup=existing', '--suffix=_', '-ft', self.env.cwd.path] + \ - [f.path for f in copied_files], - descr=descr, end_hook=refresh) + [f.path for f in copied_files], descr=descr) else: if len(copied_files) == 1: descr = "copying: " + one_file.path @@ -704,9 +703,9 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): descr = "copying files from: " + one_file.dirname obj = CommandLoader(args=['cp', '--backup=existing', '--archive', '--suffix=_', '-frt', self.env.cwd.path] + \ - [f.path for f in self.env.copy], - descr=descr, end_hook=refresh) + [f.path for f in self.env.copy], descr=descr) + obj.signal_bind('after', refresh) self.loader.add(obj) def delete(self): diff --git a/ranger/core/loader.py b/ranger/core/loader.py index 42136011..54d5a279 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -18,6 +18,7 @@ from time import time, sleep from subprocess import Popen, PIPE from time import time from ranger.core.shared import FileManagerAware +from ranger.ext.signal_dispatcher import SignalDispatcher import math import os import select @@ -45,7 +46,7 @@ class Loadable(object): pass -class CommandLoader(Loadable, FileManagerAware): +class CommandLoader(Loadable, SignalDispatcher, FileManagerAware): """ Run an external command with the loader. @@ -54,32 +55,30 @@ class CommandLoader(Loadable, FileManagerAware): object is removed from the queue (type ^C in ranger) """ finished = False - def __init__(self, args, descr, begin_hook=None, end_hook=None): + def __init__(self, args, descr): + SignalDispatcher.__init__(self) Loadable.__init__(self, self.generate(), descr) self.args = args - self.begin_hook = begin_hook - self.end_hook = end_hook def generate(self): self.process = process = Popen(self.args, stdout=open(os.devnull, 'w'), stderr=PIPE) - if self.begin_hook: - self.begin_hook(process) + 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') - self.fm.notify(error, bad=True) + if error: + self.fm.notify(error, bad=True) except select.error: pass sleep(0.02) yield self.finished = True - if self.end_hook: - self.end_hook(process) + self.signal_emit('after', process=process) def pause(self): if not self.finished and not self.paused: |