summary refs log tree commit diff stats
path: root/ranger
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 /ranger
parent456e2e5353de6e6defb8379b6d105eef5b5f65cc (diff)
downloadranger-996d96d15f58fc796b60bd4be701973f757ca164.tar.gz
core.loader: added CommandLoader
Diffstat (limited to 'ranger')
-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
 
12:04:30 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-10-29 12:04:30 -0700 2312' href='/akkartik/mu/commit/046closure_name.cc?h=main&id=d9025124a102fb7b421699e4e0463a3c62b261cb'>d9025124 ^
23d3a022 ^
82ac0b7e ^

436b2b2e ^
2199940a ^
82ac0b7e ^
2caaa7f1 ^


82ac0b7e ^
2caaa7f1 ^
b2e4056d ^
82ac0b7e ^

363be37f ^
795f5244 ^
6c96a437 ^
795f5244 ^
82ac0b7e ^
6c96a437 ^
ab6ed192 ^
0487a30e ^
aae198a9 ^
0f2781f8 ^
82ac0b7e ^

ae256ea1 ^

9dcbec39 ^
35064671 ^

af023b32 ^
ae256ea1 ^
3e5f4358 ^
9dcbec39 ^
3e5f4358 ^

f3760b0f ^
f22250a1 ^
9dcbec39 ^
82ac0b7e ^

795f5244 ^
57d01f21 ^
9dcbec39 ^
57d01f21 ^

f22250a1 ^
82ac0b7e ^



82ac0b7e ^


b24eb476 ^

82ac0b7e ^
1b76245c ^
82ac0b7e ^

ae256ea1 ^
af023b32 ^
b24eb476 ^
82ac0b7e ^
363be37f ^
1e38eee5 ^
363be37f ^

82ac0b7e ^




b24eb476 ^
82ac0b7e ^
f3760b0f ^
9dcbec39 ^
6c96a437 ^
1b76245c ^
82ac0b7e ^
1b76245c ^
1e38eee5 ^
82ac0b7e ^







b24eb476 ^
82ac0b7e ^
f3760b0f ^
9dcbec39 ^
1e38eee5 ^
82ac0b7e ^
f22250a1 ^

82ac0b7e ^

5f98a10c ^
b24eb476 ^

82ac0b7e ^
ae256ea1 ^
af023b32 ^
9dcbec39 ^
e4630643 ^

ae256ea1 ^
82ac0b7e ^
f3760b0f ^
82ac0b7e ^
1e38eee5 ^


1ead3562 ^
1e38eee5 ^
192d59d3 ^
1e38eee5 ^
9dcbec39 ^

2655ae72 ^



514f0e34 ^
760f683f ^

897ae8c1 ^
2655ae72 ^


aae198a9 ^
897ae8c1 ^
760f683f ^
2655ae72 ^

897ae8c1 ^
23d3a022 ^
2655ae72 ^
23d3a022 ^
b0631dec ^




a519b78c ^
b0631dec ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185