summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-03 04:45:45 +0100
committerhut <hut@lavabit.com>2010-01-03 04:45:45 +0100
commitc25ba934d0e5e6118963e3bf75e31f350d652ea9 (patch)
treef901bccb18fe06aaef77cc0b8634963bfdc2f1f6
parentab7bf8b0e87ca12c40ce575e259aeca771328ab3 (diff)
downloadranger-c25ba934d0e5e6118963e3bf75e31f350d652ea9.tar.gz
applications: improved run function, catch errors
-rw-r--r--ranger/actions.py2
-rw-r--r--ranger/applications.py42
2 files changed, 32 insertions, 12 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index d35a2c48..25c8262c 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -152,7 +152,7 @@ class Actions(EnvironmentAware, SettingsAware):
 
 		if not self.env.enter_dir(cf):
 			if sel:
-				if self.execute_file(sel, mode=mode) is None:
+				if self.execute_file(sel, mode=mode) is False:
 					self.open_console(cmode.OPEN_QUICK)
 
 	def history_go(self, relative):
diff --git a/ranger/applications.py b/ranger/applications.py
index 37358e12..210028c9 100644
--- a/ranger/applications.py
+++ b/ranger/applications.py
@@ -158,8 +158,12 @@ class AppContext(object):
 		"""
 		Run the application in the way specified by the options.
 
-		This function ensures that there is an action.
+		Returns False if nothing can be done, None if there was an error,
+		otherwise the process object returned by Popen().
+
+		This function tries to find an action if none is defined.
 		"""
+
 		self.squash_flags()
 		if self.action is None:
 			self.get_action()
@@ -172,7 +176,7 @@ class AppContext(object):
 		kw['args'] = self.action
 
 		if kw['args'] is None:
-			return None
+			return False
 
 		for word in ('shell', 'stdout', 'stdin', 'stderr'):
 			if getattr(self, word) is not None:
@@ -182,26 +186,42 @@ class AppContext(object):
 			kw['stdout'] = kw['stderr'] = kw['stdin'] = devnull
 
 		# --------------------------- run them
+		toggle_ui = True
+		pipe_output = False
+		process = None
+
 		if 'p' in self.flags:
 			kw['stdout'] = PIPE
 			kw['stderr'] = PIPE
-			process1 = Popen(**kw)
-			process2 = run(app='pager', stdin=process1.stdout, fm=self.fm)
-			return process2
+			toggle_ui = False
+			pipe_output = True
+			self.wait = False
 
-		elif 'd' in self.flags:
-			process = Popen(**kw)
-			return process
+		if 'd' in self.flags:
+			toggle_ui = False
+			self.wait = False
 
-		else:
+		if toggle_ui:
 			self._activate_ui(False)
+
+		try:
 			try:
 				process = Popen(**kw)
+			except:
+				if self.fm:
+					self.fm.notify("Failed to run: " + \
+							' '.join(kw['args']), bad=True)
+			else:
 				if self.wait:
 					waitpid_no_intr(process.pid)
-			finally:
+		finally:
+			if toggle_ui:
 				self._activate_ui(True)
-				return process
+			
+			if pipe_output and process:
+				return run(app='pager', stdin=process.stdout, fm=self.fm)
+
+			return process
 
 	def _activate_ui(self, boolean):
 		if self.fm and self.fm.ui:
ranger/commit/test/tc_displayable.py?h=v1.9.0b2&id=1159f9ec182496ddc5324f23fb1d5eae73fe63e3'>1159f9ec ^
f7819821 ^



1159f9ec ^
152823d8 ^
1c72dd08 ^


152823d8 ^

1c72dd08 ^

152823d8 ^

1c72dd08 ^


152823d8 ^









1159f9ec ^
1159f9ec ^


dd4a4145 ^
1159f9ec ^
dd4a4145 ^





1159f9ec ^
dd4a4145 ^


1159f9ec ^
dd4a4145 ^


1159f9ec ^
1159f9ec ^


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