summary refs log tree commit diff stats
path: root/ranger/core/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'ranger/core/helper.py')
-rw-r--r--ranger/core/helper.py102
1 files changed, 55 insertions, 47 deletions
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index ad5541f5..995be7c5 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
+# Copyright (C) 2009, 2010, 2011  Roman Zimbelmann <romanz@lavabit.com>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,11 +20,9 @@ import os.path
 import sys
 from ranger import *
 
-LOGFILE = '/tmp/errorlog'
-
 def parse_arguments():
 	"""Parse the program arguments"""
-	from optparse import OptionParser, SUPPRESS_HELP
+	from optparse import OptionParser
 	from ranger import __version__
 	from ranger.ext.openstruct import OpenStruct
 	from os.path import expanduser
@@ -32,29 +30,17 @@ def parse_arguments():
 	if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']:
 		default_confdir = os.environ['XDG_CONFIG_HOME'] + '/ranger'
 	else:
-		default_confdir = '~/.config/ranger'
-	usage = '%prog [options] [path/filename]'
-
-	minor_version = __version__[2:]  # assumes major version number is <10
-	if '.' in minor_version:
-		minor_version = minor_version[:minor_version.find('.')]
-	version_tag = ' (stable)' if int(minor_version) % 2 == 0 else ' (testing)'
-	if __version__.endswith('.0'):
-		version_string = 'ranger ' + __version__[:-2] + version_tag
-	else:
-		version_string = 'ranger ' + __version__ + version_tag
+		default_confdir = CONFDIR
 
-	parser = OptionParser(usage=usage, version=version_string)
+	parser = OptionParser(usage=USAGE, version='ranger '+__version__)
 
 	parser.add_option('-d', '--debug', action='store_true',
 			help="activate debug mode")
 	parser.add_option('-c', '--clean', action='store_true',
 			help="don't touch/require any config files. ")
-	parser.add_option('--fail-if-run', action='store_true', # COMPAT
-			help=SUPPRESS_HELP)
 	parser.add_option('--copy-config', type='string', metavar='which',
 			help="copy the default configs to the local config directory. "
-			"Possible values: all, apps, commands, keys, options, scope")
+			"Possible values: all, rc, apps, commands, options, scope")
 	parser.add_option('--fail-unless-cd', action='store_true',
 			help="experimental: return the exit code 1 if ranger is" \
 					"used to run a file (with `ranger filename`)")
@@ -73,63 +59,85 @@ def parse_arguments():
 	parser.add_option('--choosedir', type='string', metavar='TARGET',
 			help="Makes ranger act like a directory chooser. When ranger quits"
 			", it will write the name of the last visited directory to TARGET")
+	parser.add_option('--list-unused-keys', action='store_true',
+			help="List common keys which are not bound to any action.")
 
 	options, positional = parser.parse_args()
 	arg = OpenStruct(options.__dict__, targets=positional)
 	arg.confdir = expanduser(arg.confdir)
-	if arg.fail_if_run:
-		arg.fail_unless_cd = arg.fail_if_run
-		del arg['fail_if_run']
 
 	return arg
 
 
 def load_settings(fm, clean):
+	from ranger.core.actions import Actions
 	import ranger.core.shared
 	import ranger.api.commands
-	import ranger.api.keys
+	from ranger.defaults import commands
+
+	# Load default commands
+	fm.commands = ranger.api.commands.CommandContainer()
+	exclude = ['settings']
+	include = [name for name in dir(Actions) if name not in exclude]
+	fm.commands.load_commands_from_object(fm, include)
+	fm.commands.load_commands_from_module(commands)
+
 	if not clean:
 		allow_access_to_confdir(ranger.arg.confdir, True)
 
-		# Load commands
-		comcont = ranger.api.commands.CommandContainer()
-		ranger.api.commands.alias = comcont.alias
+		# Load custom commands
 		try:
 			import commands
-			comcont.load_commands_from_module(commands)
+			fm.commands.load_commands_from_module(commands)
 		except ImportError:
 			pass
-		from ranger.defaults import commands
-		comcont.load_commands_from_module(commands)
-		commands = comcont
 
 		# Load apps
 		try:
 			import apps
 		except ImportError:
 			from ranger.defaults import apps
+		fm.apps = apps.CustomApplications()
+
+		# Load rc.conf
+		custom_conf = fm.confpath('rc.conf')
+		default_conf = fm.relpath('defaults', 'rc.conf')
+		load_default_rc = fm.settings.load_default_rc
 
-		# Load keys
-		keymanager = ranger.core.shared.EnvironmentAware.env.keymanager
-		ranger.api.keys.keymanager = keymanager
-		from ranger.defaults import keys
+		if load_default_rc:
+			fm.source(default_conf)
+		if os.access(custom_conf, os.R_OK):
+			fm.source(custom_conf)
+
+		# XXX Load plugins (experimental)
 		try:
-			import keys
-		except ImportError:
+			plugindir = fm.confpath('plugins')
+			plugins = [p[:-3] for p in os.listdir(plugindir) \
+					if p.endswith('.py') and not p.startswith('_')]
+		except:
 			pass
+		else:
+			if not os.path.exists(fm.confpath('plugins', '__init__.py')):
+				f = open(fm.confpath('plugins', '__init__.py'), 'w')
+				f.close()
+
+			ranger.fm = fm
+			for plugin in sorted(plugins):
+				try:
+					module = __import__('plugins', fromlist=[plugin])
+					fm.log.append("Loaded plugin '%s'." % module)
+				except Exception as e:
+					fm.log.append("Error in plugin '%s'" % plugin)
+					import traceback
+					for line in traceback.format_exception_only(type(e), e):
+						fm.log.append(line)
+			ranger.fm = None
+
 		allow_access_to_confdir(ranger.arg.confdir, False)
 	else:
-		comcont = ranger.api.commands.CommandContainer()
-		ranger.api.commands.alias = comcont.alias
-		from ranger.api import keys
-		keymanager = ranger.core.shared.EnvironmentAware.env.keymanager
-		ranger.api.keys.keymanager = keymanager
-		from ranger.defaults import commands, keys, apps
-		comcont.load_commands_from_module(commands)
-		commands = comcont
-	fm.commands = commands
-	fm.keys = keys
-	fm.apps = apps.CustomApplications()
+		from ranger.defaults import apps
+		fm.apps = apps.CustomApplications()
+		fm.source(fm.relpath('defaults', 'rc.conf'))
 
 
 def load_apps(fm, clean):
-0700 7041' href='/akkartik/mu/commit/021byte_addressing.cc?h=hlt&id=eb45b315b66ab3b08328e2a5f3d99f87c8cf7163'>eb45b315 ^
4a943d4e ^


83c67014 ^
4a943d4e ^


83c67014 ^
4a943d4e ^









6fc975eb ^




c442a5ad ^
6fc975eb ^
5c26afb1 ^
861418f0 ^
c442a5ad ^
9ee351f3 ^
861418f0 ^
c442a5ad ^
6fc975eb ^

861418f0 ^
4a943d4e ^




83c67014 ^
4a943d4e ^











2eb174d6 ^





4a943d4e ^
eb45b315 ^
4a943d4e ^

83c67014 ^
4a943d4e ^


83c67014 ^
4a943d4e ^








2eb174d6 ^




c442a5ad ^
3c81c7db ^
2eb174d6 ^





5c26afb1 ^
9ee351f3 ^
c442a5ad ^
2eb174d6 ^

5c26afb1 ^





4c3a867b ^







5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^






30f844ee ^
5c26afb1 ^

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