summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-27 03:33:24 +0200
committerhut <hut@lavabit.com>2010-04-27 03:33:24 +0200
commit4db79381d4874318c76c605cf990c630c9d70115 (patch)
tree7e15fc295a69672b3b06828694953b375612f38a
parent2e631f441dc2cc89cbdf8744ee31b98112b2395d (diff)
parentbea16f4e5d56edb1dcfa3e19c8e1fbc2cde587a3 (diff)
downloadranger-4db79381d4874318c76c605cf990c630c9d70115.tar.gz
Merge branch 'generic'
-rw-r--r--ranger/api/apps.py24
-rw-r--r--ranger/defaults/apps.py81
2 files changed, 41 insertions, 64 deletions
diff --git a/ranger/api/apps.py b/ranger/api/apps.py
index 90162e0b..d2e9ac4f 100644
--- a/ranger/api/apps.py
+++ b/ranger/api/apps.py
@@ -76,7 +76,7 @@ class Applications(FileManagerAware):
 				application_handler = getattr(self, 'app_' + app)
 			except AttributeError:
 				if app in get_executables():
-					return tup(app, *context)
+					return _generic_app(app, context)
 				continue
 			if self._meets_dependencies(application_handler):
 				return application_handler(context)
@@ -99,7 +99,7 @@ class Applications(FileManagerAware):
 			handler = getattr(self, 'app_' + app)
 		except AttributeError:
 			if app in get_executables():
-				return tup(app, *context)  # generic app
+				return _generic_app(app, context)
 			handler = self.app_default
 		return handler(context)
 
@@ -116,6 +116,13 @@ class Applications(FileManagerAware):
 			result |= set(m[4:] for m in cls.__dict__ if m.startswith('app_'))
 		return sorted(result)
 
+	@classmethod
+	def generic(cls, *args, **keywords):
+		flags = 'flags' in keywords and keywords['flags'] or ""
+		for name in args:
+			assert isinstance(name, str)
+			setattr(cls, "app_" + name, _generic_wrapper(name, flags=flags))
+
 
 def tup(*args):
 	"""
@@ -134,3 +141,16 @@ def depends_on(*args):
 		fnc.dependencies = args
 		return fnc
 	return decorator
+
+
+def _generic_app(name, context, flags=''):
+	"""Use this function when no other information is given"""
+	context.flags += flags
+	return tup(name, *context)
+
+
+def _generic_wrapper(name, flags=''):
+	"""Wraps _generic_app into a method for Applications"""
+	assert isinstance(name, str)
+	return depends_on(name)(lambda self, context:
+			_generic_app(name, context, flags))
diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py
index 6c09298a..4dd3bde5 100644
--- a/ranger/defaults/apps.py
+++ b/ranger/defaults/apps.py
@@ -92,13 +92,10 @@ class CustomApplications(Applications):
 
 
 	# ----------------------------------------- application definitions
+	# Note: Trivial applications are defined at the bottom
 	def app_pager(self, c):
 		return tup('less', *c)
 
-	@depends_on('vim')
-	def app_vim(self, c):
-		return tup('vim', *c)
-
 	def app_editor(self, c):
 		try:
 			default_editor = os.environ['EDITOR']
@@ -135,16 +132,6 @@ class CustomApplications(Applications):
 		else:
 			return tup('mplayer', *c)
 
-	@depends_on("eog")
-	def app_eye_of_gnome(self, c):
-		c.flags += 'd'
-		return tup('eog', *c)
-
-	@depends_on('mirage')
-	def app_mirage(self, c):
-		c.flags += 'd'
-		return tup('mirage', *c)
-
 	@depends_on('feh')
 	def app_feh(self, c):
 		arg = {1: '--bg-scale', 2: '--bg-tile', 3: '--bg-center'}
@@ -171,10 +158,6 @@ class CustomApplications(Applications):
 		except:
 			return tup('feh', *c)
 
-	@depends_on("gimp")
-	def app_gimp(self, c):
-		return tup('gimp', *c)
-
 	@depends_on('aunpack')
 	def app_aunpack(self, c):
 		if c.mode is 0:
@@ -182,15 +165,6 @@ class CustomApplications(Applications):
 			return tup('aunpack', '-l', c.file.path)
 		return tup('aunpack', c.file.path)
 
-	@depends_on('fceux')
-	def app_fceux(self, c):
-		return tup('fceux', *c)
-
-	@depends_on('apvlv')
-	def app_apvlv(self, c):
-		c.flags += 'd'
-		return tup('apvlv', *c)
-
 	@depends_on('make')
 	def app_make(self, c):
 		if c.mode is 0:
@@ -200,25 +174,6 @@ class CustomApplications(Applications):
 		if c.mode is 2:
 			return tup("make", "clear")
 
-	@depends_on('elinks')
-	def app_elinks(self, c):
-		c.flags += 'D'
-		return tup('elinks', *c)
-
-	@depends_on('opera')
-	def app_opera(self, c):
-		c.flags += 'd'
-		return tup('opera', *c)
-
-	@depends_on('firefox')
-	def app_firefox(self, c):
-		c.flags += 'd'
-		return tup("firefox", *c)
-
-	@depends_on('javac')
-	def app_javac(self, c):
-		return tup("javac", *c)
-
 	@depends_on('java')
 	def app_java(self, c):
 		def strip_extensions(file):
@@ -228,22 +183,6 @@ class CustomApplications(Applications):
 		files_without_extensions = map(strip_extensions, c.files)
 		return tup("java", files_without_extensions)
 
-	@depends_on('zsnes')
-	def app_zsnes(self, c):
-		return tup("zsnes", c.file.path)
-
-	@depends_on('evince')
-	def app_evince(self, c):
-		return tup("evince", *c)
-
-	@depends_on('zathura')
-	def app_zathura(self, c):
-		return tup("zathura", *c)
-
-	@depends_on('wine')
-	def app_wine(self, c):
-		return tup("wine", c.file.path)
-
 	@depends_on('totem')
 	def app_totem(self, c):
 		if c.mode is 0:
@@ -251,6 +190,24 @@ class CustomApplications(Applications):
 		if c.mode is 1:
 			return tup("totem", "--fullscreen", *c)
 
+
+# Often a programs invocation is trivial.  For example:
+#    vim test.py readme.txt [...]
+# This could be implemented like:
+#    @depends_on("vim")
+#    def app_vim(self, c):
+#        return tup("vim", *c.files)
+# Instead of creating such a generic function for each program, just add
+# its name here and it will be automatically done for you.
+CustomApplications.generic('vim', 'fceux', 'elinks', 'wine',
+		'zsnes', 'javac')
+
+# By setting flags='d', this programs will not block ranger's terminal:
+CustomApplications.generic('opera', 'firefox', 'apvlv', 'evince',
+		'zathura', 'gimp', 'mirage', 'eog', flags='d')
+
+# What filetypes are recognized as scripts for interpreted languages?
+# This regular expression is used in app_default()
 INTERPRETED_LANGUAGES = re.compile(r'''
 	^(text|application)/x-(
 		haskell|perl|python|ruby|sh
id=d5c86dfd8706e6b3ceee7843464797e6fcad4259'>^
a90faae9 ^
4a48bedc ^
2d91279b ^

3d8b137c ^
8195ed4e ^


dd660682 ^

a90faae9 ^


d803b687 ^
a90faae9 ^





3d8b137c ^
7bf9212f ^
a90faae9 ^


3d8b137c ^
7bf9212f ^
a90faae9 ^



3d8b137c ^
7bf9212f ^
a90faae9 ^

3d8b137c ^

ada5eb55 ^
3d8b137c ^

a90faae9 ^


f0f07766 ^

ea5e7fd4 ^

ada5eb55 ^
a90faae9 ^



3d8b137c ^
7bf9212f ^
2222dae5 ^

ada5eb55 ^
a90faae9 ^


3d8b137c ^
a90faae9 ^
ea5e7fd4 ^
c76b0066 ^
53251357 ^
a90faae9 ^

ea5e7fd4 ^
c76b0066 ^
53251357 ^
8195ed4e ^
8195ed4e ^


53251357 ^

dd660682 ^
53251357 ^



dd660682 ^
53251357 ^

a90faae9 ^
dc0e767c ^
a90faae9 ^




2d91279b ^
a90faae9 ^
4a48bedc ^
a90faae9 ^
3d8b137c ^

a90faae9 ^
2d91279b ^
3d8b137c ^
ea5e7fd4 ^
a90faae9 ^
ea5e7fd4 ^

a90faae9 ^
2d91279b ^
3d8b137c ^
ea5e7fd4 ^
3d8b137c ^
ea5e7fd4 ^
a90faae9 ^
ea5e7fd4 ^

a90faae9 ^

6ac59c62 ^


2d91279b ^
6ac59c62 ^
4a48bedc ^
06ef635e ^
3d8b137c ^




6ac59c62 ^
3d8b137c ^


6ac59c62 ^
3d8b137c ^
6ac59c62 ^



3d8b137c ^
6ac59c62 ^




3d8b137c ^
6ac59c62 ^

2d91279b ^
6ac59c62 ^

3d8b137c ^
6ac59c62 ^




3d8b137c ^
6ac59c62 ^


3d8b137c ^
6ac59c62 ^








ada5eb55 ^
6ac59c62 ^



3d8b137c ^
6ac59c62 ^

3d8b137c ^
6ac59c62 ^




ada5eb55 ^
6ac59c62 ^









06ef635e ^
6ac59c62 ^

a90faae9 ^
6f65d591 ^
e00d4854 ^
a90faae9 ^

294b2ab3 ^





a90faae9 ^






294b2ab3 ^
6f65d591 ^



a90faae9 ^







6f65d591 ^
e00d4854 ^
a90faae9 ^

294b2ab3 ^





6f65d591 ^
a90faae9 ^







294b2ab3 ^
6f65d591 ^



a90faae9 ^


71056d61 ^
294b2ab3 ^

71056d61 ^
a90faae9 ^






6f65d591 ^
55479bc2 ^
a90faae9 ^


71056d61 ^
294b2ab3 ^

71056d61 ^
a90faae9 ^


a90faae9 ^
6f65d591 ^
e00d4854 ^
a90faae9 ^
294b2ab3 ^





6f65d591 ^
a90faae9 ^


294b2ab3 ^
6f65d591 ^
55479bc2 ^
a90faae9 ^



71056d61 ^
294b2ab3 ^

71056d61 ^
a90faae9 ^





294b2ab3 ^
6f65d591 ^
55479bc2 ^
a90faae9 ^



71056d61 ^
294b2ab3 ^

71056d61 ^
a90faae9 ^



6f65d591 ^

a90faae9 ^
294b2ab3 ^

a90faae9 ^
294b2ab3 ^
a90faae9 ^
294b2ab3 ^
6f65d591 ^
a90faae9 ^

71056d61 ^

ceeb92d4 ^
71056d61 ^
a90faae9 ^






294b2ab3 ^
6f65d591 ^
55479bc2 ^
a90faae9 ^



71056d61 ^
ceeb92d4 ^
71056d61 ^
a90faae9 ^


d2e606f4 ^


a90faae9 ^
4a48bedc ^
a90faae9 ^
a90faae9 ^

3d8b137c ^
a90faae9 ^
3d8b137c ^

a90faae9 ^

44bab2e4 ^
a90faae9 ^

3d8b137c ^

71056d61 ^
a90faae9 ^
4e7186fa ^

736b26a7 ^
a90faae9 ^
2d91279b ^

3d8b137c ^
aaf61a53 ^
a90faae9 ^

d2e606f4 ^
a90faae9 ^
4a48bedc ^
a90faae9 ^
a4020a80 ^
2d91279b ^
a90faae9 ^
3d8b137c ^


736b26a7 ^
a90faae9 ^
71056d61 ^
a90faae9 ^

a4020a80 ^

a90faae9 ^

ae244ebd ^
d2e606f4 ^
ae244ebd ^
4a48bedc ^
6d12a8c4 ^
a4020a80 ^
2d91279b ^
3d8b137c ^


7169c636 ^
ceeb92d4 ^
ae244ebd ^

a4020a80 ^

ae244ebd ^

2d91279b ^
a90faae9 ^
4a48bedc ^
aaf61a53 ^
a90faae9 ^

3d8b137c ^

a90faae9 ^


3d8b137c ^

a90faae9 ^

a90faae9 ^

a90faae9 ^




3d8b137c ^
a90faae9 ^
3d8b137c ^
ea5e7fd4 ^


ada5eb55 ^
a90faae9 ^


a90faae9 ^

3d8b137c ^
a90faae9 ^
4a48bedc ^

a90faae9 ^



4a48bedc ^
a90faae9 ^





3d8b137c ^
a90faae9 ^

136412d2 ^
a90faae9 ^



60679557 ^
























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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549