summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-20 15:45:10 +0200
committerhut <hut@lavabit.com>2010-04-20 18:58:29 +0200
commit996d96d15f58fc796b60bd4be701973f757ca164 (patch)
tree2021d0e99cd7fa222ef286dab60ca0fc60666eed
parent456e2e5353de6e6defb8379b6d105eef5b5f65cc (diff)
downloadranger-996d96d15f58fc796b60bd4be701973f757ca164.tar.gz
core.loader: added CommandLoader
-rw-r--r--ranger/core/actions.py44
-rw-r--r--ranger/core/loader.py21
2 files changed, 34 insertions, 31 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 47b15fa6..083f0c80 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -30,7 +30,7 @@ from ranger.shared import FileManagerAware, EnvironmentAware, SettingsAware
 from ranger.gui.widgets import console_mode as cmode
 from ranger.fsobject import File
 from ranger.ext import shutil_generatorized as shutil_g
-from ranger.core.loader import LoadableObject
+from ranger.core.loader import CommandLoader
 
 class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	search_method = 'ctime'
@@ -567,6 +567,10 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 		if not copied_files:
 			return
 
+		def refresh(_):
+			cwd = self.env.get_directory(original_path)
+			cwd.load_content()
+
 		original_path = self.env.cwd.path
 		try:
 			one_file = copied_files[0]
@@ -580,41 +584,19 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 				descr = "moving: " + one_file.path
 			else:
 				descr = "moving files from: " + one_file.dirname
-			def generate():
-				null = open(os.devnull, 'w')
-				process = Popen(['mv', '--backup=existing',
-					'-t', self.env.cwd.path] + \
-							[f.path for f in copied_files],
-					stdout=null, stderr=PIPE)
-				while process.poll() is None:
-					rd, _, __ = select.select(
-							[process.stderr], [], [], 0.05)
-					if rd:
-						self.notify(process.stderr.readline(), bad=True)
-					yield
-				cwd = self.env.get_directory(original_path)
-				cwd.load_content()
+			obj = CommandLoader(args=['mv', '--backup=existing',
+					'-t', self.env.cwd.path] + [f.path for f in copied_files],
+					descr=descr, end_hook=refresh)
 		else:
 			if len(copied_files) == 1:
 				descr = "copying: " + one_file.path
 			else:
 				descr = "copying files from: " + one_file.dirname
-			def generate():
-				null = open(os.devnull, 'w')
-				process = Popen(['cp', '--backup=existing', '--archive',
-					'-t', self.env.cwd.path] + \
-							[f.path for f in self.env.copy],
-					stdout=null, stderr=PIPE)
-				while process.poll() is None:
-					rd, _, __ = select.select(
-							[process.stderr], [], [], 0.05)
-					if rd:
-						self.notify(process.stderr.readline(), bad=True)
-					yield
-				cwd = self.env.get_directory(original_path)
-				cwd.load_content()
-
-		self.loader.add(LoadableObject(generate(), descr))
+			obj = CommandLoader(args=['cp', '--backup=existing', '--archive',
+					'-t', self.env.cwd.path] + [f.path for f in self.env.copy],
+					descr=descr, end_hook=refresh)
+
+		self.loader.add(obj)
 
 	def delete(self):
 		self.notify("Deleting!", duration=1)
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index 4f4424e4..e4bc2d95 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -35,6 +35,27 @@ class LoadableObject(object):
 		return self.description
 
 
+class CommandLoader(LoadableObject):
+	def __init__(self, args, descr, begin_hook=None, end_hook=None):
+		self.description = descr
+		self.args = args
+		self.begin_hook = begin_hook
+		self.end_hook = end_hook
+
+	def load_generator(self):
+		process = Popen(self.args, stdout=open(os.devnull, 'w'), stderr=PIPE)
+		if self.begin_hook:
+			self.begin_hook(process)
+		while process.poll() is None:
+			rd, _, __ = select.select(
+					[process.stderr], [], [], 0.05)
+			if rd:
+				self.notify(process.stderr.readline(), bad=True)
+			yield
+		if self.end_hook(process):
+			self.end_hook(process)
+
+
 class Loader(FileManagerAware):
 	seconds_of_work_time = 0.03