about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rwxr-xr-xranger.py2
-rw-r--r--ranger/__init__.py74
-rw-r--r--ranger/fm.py25
-rw-r--r--ranger/main.py84
5 files changed, 94 insertions, 93 deletions
diff --git a/TODO b/TODO
index 9c0ec5f5..bd078d54 100644
--- a/TODO
+++ b/TODO
@@ -10,5 +10,5 @@ Console
 General
 
    (X) #5   09/12/06  move code from fm into objects
-   ( ) #6   09/12/06  move main to fm
+   (X) #6   09/12/06  move main to __init__
    ( ) #7   09/12/06  cooler titlebar
diff --git a/ranger.py b/ranger.py
index 7ab00a26..807e28a6 100755
--- a/ranger.py
+++ b/ranger.py
@@ -21,7 +21,7 @@ return 1
 __doc__ = """Ranger - file browser for the unix terminal"""
 
 try:
-	from ranger.main import main
+	from ranger import main
 
 except ImportError as errormessage:
 	if str(errormessage).endswith("main"):
diff --git a/ranger/__init__.py b/ranger/__init__.py
index b26a76cb..553e57f5 100644
--- a/ranger/__init__.py
+++ b/ranger/__init__.py
@@ -18,3 +18,77 @@ CONFDIR = os.path.expanduser('~/.ranger')
 RANGERDIR = os.path.dirname(__file__)
 
 sys.path.append(CONFDIR)
+
+USAGE = '''%s [options] [path/filename]'''
+
+def main():
+	"""initialize objects and run the filemanager"""
+	try:
+		import curses
+	except ImportError as errormessage:
+		print(errormessage)
+		print('ranger requires the python curses module. Aborting.')
+		sys.exit(1)
+
+	from locale import setlocale, LC_ALL
+	from optparse import OptionParser, SUPPRESS_HELP
+
+	from ranger.fm import FM
+	from ranger.environment import Environment
+	from ranger.gui.defaultui import DefaultUI as UI
+	from ranger.fsobject.file import File
+
+	setlocale(LC_ALL, 'en_US.utf8')
+	os.stat_float_times(True)
+
+	# Parse options
+	parser = OptionParser( usage = USAGE,
+			version = 'ranger ' + __version__ )
+
+	# Instead of using this directly, use the embedded
+	# shell script by running ranger with:
+	# source /path/to/ranger /path/to/ranger
+	parser.add_option( '--cd-after-exit',
+			action = 'store_true',
+			dest = 'cd_after_exit',
+			help = SUPPRESS_HELP )
+
+	args, rest = parser.parse_args()
+
+	if args.cd_after_exit:
+		sys.stderr = sys.__stdout__
+		if rest[0] == sys.argv[0]:
+			del rest[0]
+	
+	# Initialize objects
+	target = ' '.join(rest)
+	if target:
+		if not os.access(target, os.F_OK):
+			print("File or directory doesn't exist: %s" % target)
+			sys.exit(1)
+		elif os.path.isfile(target):
+			thefile = File(target)
+			FM().execute_file(thefile)
+			sys.exit(0)
+		else:
+			path = target
+	else:
+		path = '.'
+
+	Environment(path)
+
+	try:
+		my_ui = UI()
+		my_fm = FM(ui = my_ui)
+
+		# Run the file manager
+		my_fm.initialize()
+		my_ui.initialize()
+		my_fm.loop()
+	finally:
+		# Finish, clean up
+		if 'my_ui' in vars():
+			my_ui.destroy()
+		if args.cd_after_exit:
+			try: sys.__stderr__.write(my_fm.env.pwd.path)
+			except: pass
diff --git a/ranger/fm.py b/ranger/fm.py
index 5abb2a8e..43319836 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -2,16 +2,24 @@ from ranger.actions import Actions
 from ranger.container import Bookmarks
 from ranger import __version__
 
-USAGE = '''%s [options] [path/filename]'''
 CTRL_C = 3
+TICKS_BEFORE_COLLECTING_GARBAGE = 100
 
 class FM(Actions):
 	def __init__(self, ui = None, bookmarks = None):
+		"""Initialize FM."""
 		Actions.__init__(self)
 		self.ui = ui
+		self.bookmarks = bookmarks
 		self.apps = self.settings.apps.CustomApplications()
 
-		if bookmarks is None:
+		from ranger.shared import FileManagerAware
+		FileManagerAware.fm = self
+
+	def initialize(self):
+		"""If ui/bookmarks are None, they will be initialized here."""
+
+		if self.bookmarks is None:
 			self.bookmarks = Bookmarks()
 			self.bookmarks.load()
 
@@ -19,15 +27,18 @@ class FM(Actions):
 			self.bookmarks = bookmarks
 		self.bookmarks.enter_dir_function = self.enter_dir
 
-		from ranger.shared import FileManagerAware
-		FileManagerAware.fm = self
-
-	def loop(self):
 		if self.ui is None:
 			from ranger.gui.defaultui import DefaultUI
 			self.ui = DefaultUI()
 			self.ui.initialize()
 
+	def loop(self):
+		"""The main loop consists of:
+1. reloading bookmarks if outdated
+2. drawing and finalizing ui
+3. reading and handling user input
+4. after X loops: collecting unused directory objects"""
+
 		self.env.enter_dir(self.env.path)
 
 		gc_tick = 0
@@ -42,7 +53,7 @@ class FM(Actions):
 				self.ui.handle_key(key)
 
 				gc_tick += 1
-				if gc_tick > 10:
+				if gc_tick > TICKS_BEFORE_COLLECTING_GARBAGE:
 					gc_tick = 0
 					self.env.garbage_collect()
 
diff --git a/ranger/main.py b/ranger/main.py
deleted file mode 100644
index d2a931fd..00000000
--- a/ranger/main.py
+++ /dev/null
@@ -1,84 +0,0 @@
-import sys
-import os
-from locale import setlocale, LC_ALL
-from optparse import OptionParser, SUPPRESS_HELP
-
-from ranger.fm import FM
-from ranger.environment import Environment
-from ranger.gui.defaultui import DefaultUI as UI
-from ranger.fsobject.file import File
-
-VERSION = '1.0.0'
-
-USAGE = '''%s [options] [path/filename]'''
-
-def main():
-	"""initialize objects and run the filemanager"""
-	try:
-		import curses
-	except ImportError as errormessage:
-		print(errormessage)
-		print('ranger requires the python curses module. Aborting.')
-		sys.exit(1)
-
-	setlocale(LC_ALL, 'en_US.utf8')
-	os.stat_float_times(True)
-
-	# Parse options
-	parser = OptionParser(
-			usage = USAGE,
-			version = 'ranger ' + VERSION )
-
-	# Instead of using this directly, use the embedded
-	# shell script by running ranger with:
-	# source /path/to/ranger /path/to/ranger
-	parser.add_option( '--cd-after-exit',
-			action = 'store_true',
-			dest = 'cd_after_exit',
-			help = SUPPRESS_HELP )
-
-	args, rest = parser.parse_args()
-
-	if args.cd_after_exit:
-		sys.stderr = sys.__stdout__
-		if rest[0] == sys.argv[0]:
-			del rest[0]
-	
-	# Initialize objects
-	target = ' '.join(rest)
-	if target:
-		if not os.access(target, os.F_OK):
-			print("File or directory doesn't exist: %s" % target)
-			sys.exit(1)
-		elif os.path.isfile(target):
-			thefile = File(target)
-			FM().execute_file(thefile)
-			sys.exit(0)
-		else:
-			path = target
-
-	else:
-		path = '.'
-
-	Environment(path)
-
-	try:
-		my_ui = UI()
-		my_fm = FM(ui = my_ui)
-
-		# Run the file manager
-		my_ui.initialize()
-		my_fm.loop()
-	
-#	except:
-#		from ranger import log
-#		log(str(sys.exc_info()))
-
-	finally:
-		# Finish, clean up
-		if 'my_ui' in vars():
-			my_ui.destroy()
-
-		if args.cd_after_exit:
-			try: sys.__stderr__.write(my_fm.env.pwd.path)
-			except: pass
21b0ac43a2c923962dac'>07147a67 ^
129a9f71 ^
07147a67 ^








129a9f71 ^
07147a67 ^









129a9f71 ^
07147a67 ^








129a9f71 ^
07147a67 ^


















07147a67 ^
129a9f71 ^
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