summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-16 22:00:53 +0200
committerhut <hut@lavabit.com>2010-04-16 22:02:18 +0200
commitc82e1c27a1033b3d7cbe3dddcfeed126e2632c5f (patch)
tree79d4042bd2324366d436ff9be03b0bd129420cbc
parent70c36ff583d1e114f6553013f9a25c2f1533b585 (diff)
downloadranger-c82e1c27a1033b3d7cbe3dddcfeed126e2632c5f.tar.gz
fsobject: lazy calculation of infostring
-rw-r--r--ranger/core/environment.py4
-rw-r--r--ranger/fsobject/directory.py8
-rw-r--r--ranger/fsobject/fsobject.py47
3 files changed, 34 insertions, 25 deletions
diff --git a/ranger/core/environment.py b/ranger/core/environment.py
index e5deda07..49d92502 100644
--- a/ranger/core/environment.py
+++ b/ranger/core/environment.py
@@ -190,6 +190,10 @@ class Environment(SettingsAware, SignalDispatcher):
 		self.cwd = new_cwd
 
 		self.cwd.load_content_if_outdated()
+		if self.cwd.files:
+			for dir in self.cwd.files:
+				if dir.is_directory and dir.infostring == 'unknown':
+					dir.determine_infostring()
 
 		# build the pathway, a tuple of directory objects which lie
 		# on the path to the current directory.
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 29f0042c..1c8355cd 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -199,9 +199,13 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 
 				self.scroll_offset = 0
 				self.filenames = filenames
-				self.infostring = ' %d' % len(self.filenames) # update the infostring
 				self.files = files
 
+				if self == self.fm.env.cwd:
+					for dir in self.files:
+						if dir.is_directory and dir.infostring == 'unknown':
+							dir.determine_infostring()
+
 				self._clear_marked_items()
 				for item in self.files:
 					if item.path in marked_paths:
@@ -219,8 +223,8 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 			else:
 				self.filenames = None
 				self.files = None
-				self.infostring = BAD_INFO
 
+			self.determine_infostring()
 			self.cycle_list = None
 			self.content_loaded = True
 			self.last_update_time = time()
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index 94729b9a..4ebec3bc 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -156,6 +156,29 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 		"""Called by directory.mark_item() and similar functions"""
 		self.marked = bool(boolean)
 
+	def determine_infostring(self):
+		if self.is_device:
+			self.infostring = 'dev'
+		elif self.is_fifo:
+			self.infostring = 'fifo'
+		elif self.is_socket:
+			self.infostring = 'sock'
+		elif self.is_link:
+			self.infostring = '->'
+		elif self.is_directory:
+			try:
+				self.size = len(os.listdir(self.path))
+				self.infostring = " %d" % self.size
+				self.accessible = True
+				self.runnable = True
+			except OSError:
+				self.size = 0
+				self.infostring = BAD_INFO
+				self.accessible = False
+		elif self.is_file:
+			self.size = self.stat.st_size
+			self.infostring = ' ' + human_readable(self.size)
+
 	def load(self):
 		"""
 		reads useful information about the filesystem-object from the
@@ -188,40 +211,18 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 		if self.accessible and os.access(self.path, os.F_OK):
 			self.exists = True
 			self.accessible = True
-
 			if os.path.isdir(self.path):
 				self.type = T_DIRECTORY
-				try:
-					self.size = len(os.listdir(self.path))
-					self.infostring = ' %d' % self.size
-					self.runnable = True
-				except OSError:
-					self.infostring = BAD_INFO
-					self.runnable = False
-					self.accessible = False
 			elif os.path.isfile(self.path):
 				self.type = T_FILE
-				self.size = self.stat.st_size
-				self.infostring = ' ' + human_readable(self.stat.st_size)
 			else:
 				self.type = T_UNKNOWN
-				if self.is_device:
-					self.infostring = 'dev'
-				elif self.is_fifo:
-					self.infostring = 'fifo'
-				elif self.is_socket:
-					self.infostring = 'sock'
-				else:
-					self.infostring = BAD_INFO
 
 		else:
-			if self.is_link:
-				self.infostring = '->'
-			else:
-				self.infostring = None
 			self.type = T_NONEXISTANT
 			self.exists = False
 			self.runnable = False
+		self.determine_infostring()
 
 	def get_permission_string(self):
 		if self.permissions is not None:
7a947b30fd196520c185d38ae1b03c0'>^
e816b124 ^
a871ad80 ^

93397e45 ^
81190251 ^
93397e45 ^

055a5f71 ^
93397e45 ^
a578419d ^
bcafba2d ^
a578419d ^
a578419d ^

3bb1f124 ^
a871ad80 ^
81190251 ^
a578419d ^
81190251 ^
a578419d ^
a578419d ^

bcafba2d ^
a578419d ^


a578419d ^

3bb1f124 ^
a871ad80 ^


a578419d ^
81190251 ^
a578419d ^
a578419d ^
bcafba2d ^


bcafba2d ^

3bb1f124 ^
a871ad80 ^
81190251 ^
bcafba2d ^
81190251 ^
bcafba2d ^
bcafba2d ^

11c04d9f ^
bcafba2d ^

bcafba2d ^

3bb1f124 ^
a871ad80 ^

bcafba2d ^
81190251 ^
bcafba2d ^
bcafba2d ^
11c04d9f ^


11c04d9f ^

3bb1f124 ^
a871ad80 ^
81190251 ^
11c04d9f ^
81190251 ^
11c04d9f ^
11c04d9f ^



11c04d9f ^

3bb1f124 ^
a871ad80 ^
81190251 ^
11c04d9f ^
81190251 ^
11c04d9f ^
11c04d9f ^



11c04d9f ^

055a5f71 ^
a871ad80 ^
3bb1f124 ^
a871ad80 ^
11c04d9f ^

81190251 ^
11c04d9f ^

055a5f71 ^
11c04d9f ^





11c04d9f ^

055a5f71 ^
11c04d9f ^
055a5f71 ^
11c04d9f ^

3bb1f124 ^
a871ad80 ^




11c04d9f ^

81190251 ^
11c04d9f ^



055a5f71 ^
11c04d9f ^



11c04d9f ^

3bb1f124 ^
a871ad80 ^
81190251 ^
11c04d9f ^
81190251 ^
11c04d9f ^
11c04d9f ^



11c04d9f ^

055a5f71 ^
a871ad80 ^
3bb1f124 ^
a871ad80 ^
11c04d9f ^

81190251 ^
11c04d9f ^

055a5f71 ^
11c04d9f ^




11c04d9f ^

055a5f71 ^
11c04d9f ^
055a5f71 ^
11c04d9f ^

3bb1f124 ^
a871ad80 ^




11c04d9f ^

81190251 ^
11c04d9f ^




055a5f71 ^
11c04d9f ^
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