summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-09-21 23:30:49 +0200
committerhut <hut@lavabit.com>2010-09-21 23:41:42 +0200
commite07d8b03612ede6ae75947d0d8ba71346aa894e1 (patch)
tree57d2a2695f8cf00035a83fce854f1d4c23ef15ae
parentdc0c43951d505307f39c9902cac5b7c53e6964a9 (diff)
downloadranger-e07d8b03612ede6ae75947d0d8ba71346aa894e1.tar.gz
ranger.__init__: improved __init__.py
-rw-r--r--ranger/__init__.py53
-rw-r--r--ranger/defaults/commands.py2
2 files changed, 31 insertions, 24 deletions
diff --git a/ranger/__init__.py b/ranger/__init__.py
index 1f8cc324..f0fab087 100644
--- a/ranger/__init__.py
+++ b/ranger/__init__.py
@@ -15,55 +15,64 @@
 
 """Ranger - file browser for the unix terminal"""
 
-import os
-import sys
+from os import path, environ
+from os.path import join as _join
 from ranger.ext.openstruct import OpenStruct
+from sys import argv
 
+# Information
 __license__ = 'GPL3'
 __version__ = '1.3.0'
-__credits__ = 'Roman Zimbelmann'
-__author__ = 'Roman Zimbelmann'
-__maintainer__ = 'Roman Zimbelmann'
+__author__ = __maintainer__ = 'Roman Zimbelmann'
 __email__ = 'romanz@lavabit.com'
 
-__copyright__ = """
-Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
-"""
-
+# Constants
 USAGE = '%prog [options] [path/filename]'
-if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']:
-	DEFAULT_CONFDIR = os.environ['XDG_CONFIG_HOME'] + '/ranger'
+RANGERDIR = path.dirname(__file__)
+LOGFILE = '/tmp/errorlog'
+if 'XDG_CONFIG_HOME' in environ and environ['XDG_CONFIG_HOME']:
+	DEFAULT_CONFDIR = environ['XDG_CONFIG_HOME'] + '/ranger'
 else:
 	DEFAULT_CONFDIR = '~/.config/ranger'
-RANGERDIR = os.path.dirname(__file__)
-LOGFILE = '/tmp/errorlog'
-arg = OpenStruct(
-		debug=False, clean=False, confdir=DEFAULT_CONFDIR,
+DEBUG = ('-d' in argv or '--debug' in argv) and ('--' not in argv or
+	(('-d' in argv and argv.index('-d') < argv.index('--')) or
+	('--debug' in argv and argv.index('--debug') < argv.index('--'))))
+
+# Get some valid arguments before actually parsing them in main()
+arg = OpenStruct(debug=DEBUG, clean=False, confdir=DEFAULT_CONFDIR,
 		mode=0, flags='', targets=[])
 
-#for python3-only versions, this could be replaced with:
-#def log(*objects, start='ranger:', sep=' ', end='\n'):
-#	print(start, *objects, end=end, sep=sep, file=open(LOGFILE, 'a'))
+# Debugging features.  These will be activated when run with --debug.
+# Example usage in the code:
+# import ranger; ranger.log("hello world")
 def log(*objects, **keywords):
 	"""
 	Writes objects to a logfile (for the purpose of debugging only.)
 	Has the same arguments as print() in python3.
 	"""
-	if LOGFILE is None or arg.clean:
-		return
+	if LOGFILE is None or not arg.debug or arg.clean: return
 	start = 'start' in keywords and keywords['start'] or 'ranger:'
 	sep   =   'sep' in keywords and keywords['sep']   or ' '
 	_file =  'file' in keywords and keywords['file']  or open(LOGFILE, 'a')
 	end   =   'end' in keywords and keywords['end']   or '\n'
 	_file.write(sep.join(map(str, (start, ) + objects)) + end)
 
+def log_traceback():
+	if LOGFILE is None or not arg.debug or arg.clean: return
+	import traceback
+	traceback.print_stack(file=open(LOGFILE, 'a'))
+
+# Handy functions
 def relpath_conf(*paths):
 	"""returns the path relative to rangers configuration directory"""
 	if arg.clean:
 		assert 0, "Should not access relpath_conf in clean mode!"
 	else:
-		return os.path.join(arg.confdir, *paths)
+		return _join(arg.confdir, *paths)
 
 def relpath(*paths):
 	"""returns the path relative to rangers library directory"""
-	return os.path.join(RANGERDIR, *paths)
+	return _join(RANGERDIR, *paths)
+
+# Clean up
+del environ, OpenStruct, argv
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index d3c05023..b61d5a5a 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -308,8 +308,6 @@ class set(Command):
 
 	def tab(self):
 		line = parse(self.line)
-		from ranger import log
-		log(line.parse_setting_line())
 		name, value, name_done = line.parse_setting_line()
 		settings = self.fm.settings
 		if not name:
:02:43 +0100 Moved muc.c' href='/danisanti/profani-tty/commit/src/ui/ui.h?id=2af0d38e3d9b766ec1fd1bd85edd899d01047a2b'>2af0d38e ^
0a57c4de ^
9b177a9e ^
ff9abecd ^
24896a3b ^
5cdd69f4 ^
a2726b6a ^





44d16e91 ^
be90e44d ^
9d94ac5c ^





a2726b6a ^
30180ac8 ^
a2726b6a ^
9d94ac5c ^

a2726b6a ^
9d94ac5c ^


9d94ac5c ^
9d94ac5c ^
1526a001 ^


71236a0d ^
2ce43b63 ^
a2726b6a ^


9d94ac5c ^
a2726b6a ^







9d94ac5c ^

a2726b6a ^








9d94ac5c ^
3561ff4d ^
a2726b6a ^



9d94ac5c ^


a2726b6a ^


9d94ac5c ^
a2726b6a ^



9d94ac5c ^
4c6cfcdc ^
be90e44d ^
a2726b6a ^








9b177a9e ^
a2726b6a ^




be90e44d ^
a2726b6a ^





be90e44d ^
2be3b7d9 ^
a2726b6a ^


















































2be3b7d9 ^
60215cdf ^
a2726b6a ^


150015fa ^
a2726b6a ^
77e819e8 ^
a2726b6a ^




77e819e8 ^
a2726b6a ^




60215cdf ^
771d90c7 ^
a2726b6a ^





60215cdf ^
db4bcd3e ^
a2726b6a ^

db4bcd3e ^
be90e44d ^




a2726b6a ^

9d94ac5c ^

a2726b6a ^

9d94ac5c ^








86acd464 ^
e7be3a60 ^
a2726b6a ^





0920b65d ^
6dd11f0f ^
a2726b6a ^

9d94ac5c ^
a2726b6a ^







8ef35290 ^
a2726b6a ^



ef96bea8 ^
a2726b6a ^
9d94ac5c ^
a2726b6a ^

7b49fbdf ^


a2726b6a ^
9d94ac5c ^

9d94ac5c ^
31c0f2ba ^
9d94ac5c ^

6a8656a0 ^
9d94ac5c ^
4cb1d73a ^
9d94ac5c ^
fc6f2755 ^
9d94ac5c ^





3983ee1d ^
9d94ac5c ^






48f9f3b3 ^
2762f18a ^
9d94ac5c ^
9bc4dc38 ^
9d94ac5c ^


9d94ac5c ^
26a18294 ^
9d94ac5c ^
720dce86 ^
d3cc5bd7 ^
ddf6ada3 ^
4bc82a53 ^
039bf5d0 ^
7b541d0a ^
3c56b289 ^
44fc3f05 ^
06482fda ^
a2726b6a ^

adb470c4 ^
9d94ac5c ^
a2726b6a ^

02f5df5b ^
11d849aa ^




2ea0e1e9 ^


5cdd69f4 ^

a2726b6a ^

5cdd69f4 ^

48ec7b3b ^
9d94ac5c ^
48ec7b3b ^
4dc48b4b ^
a2726b6a ^
028839e3 ^
4dc48b4b ^
5cdd69f4 ^


a2726b6a ^













ce5f07a0 ^
a2726b6a ^


ce5f07a0 ^
a2726b6a ^

bb6540f7 ^
a2726b6a ^

ce5f07a0 ^
a2726b6a ^












5cdd69f4 ^
be90e44d ^
0007e356 ^
9d94ac5c ^
a2726b6a ^


9d94ac5c ^
a2726b6a ^


107fdd35 ^
134e5d17 ^
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