summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-05-06 01:04:01 +0200
committerhut <hut@lavabit.com>2010-05-06 01:04:01 +0200
commit4ffef98ccdc5abb1352697bc92cd507d17d7946f (patch)
treefdd06da1ce2611edb5937c2f20ca2addee2c6f98 /ranger
parent4de6abaf0ba5431395d2a627cddebdd86f10975f (diff)
downloadranger-4ffef98ccdc5abb1352697bc92cd507d17d7946f.tar.gz
fsobject.fsobject: lazily load mimetype
Diffstat (limited to 'ranger')
-rw-r--r--ranger/fsobject/fsobject.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index 6b071fed..ef52eb88 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -88,7 +88,6 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 		except ValueError:
 			self.extension = None
 
-		self.set_mimetype()
 		self.use()
 
 	def __repr__(self):
@@ -131,24 +130,40 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 
 	def set_mimetype(self):
 		"""assign attributes such as self.video according to the mimetype"""
-		self.mimetype = self.mimetypes.guess_type(self.basename, False)[0]
-		if self.mimetype is None:
-			self.mimetype = ''
+		self._mimetype = self.mimetypes.guess_type(self.basename, False)[0]
+		if self._mimetype is None:
+			self._mimetype = ''
 
-		self.video = self.mimetype.startswith('video')
-		self.image = self.mimetype.startswith('image')
-		self.audio = self.mimetype.startswith('audio')
+		self.video = self._mimetype.startswith('video')
+		self.image = self._mimetype.startswith('image')
+		self.audio = self._mimetype.startswith('audio')
 		self.media = self.video or self.image or self.audio
-		self.document = self.mimetype.startswith('text') \
+		self.document = self._mimetype.startswith('text') \
 				or (self.extension in DOCUMENT_EXTENSIONS) \
 				or (self.basename in DOCUMENT_BASENAMES)
 		self.container = self.extension in CONTAINER_EXTENSIONS
 
 		keys = ('video', 'audio', 'image', 'media', 'document', 'container')
-		self.mimetype_tuple = tuple(key for key in keys if getattr(self, key))
+		self._mimetype_tuple = tuple(key for key in keys if getattr(self, key))
 
-		if self.mimetype == '':
-			self.mimetype = None
+		if self._mimetype == '':
+			self._mimetype = None
+
+	@property
+	def mimetype(self):
+		try:
+			return self._mimetype
+		except:
+			self.set_mimetype()
+			return self._mimetype
+
+	@property
+	def mimetype_tuple(self):
+		try:
+			return self._mimetype_tuple
+		except:
+			self.set_mimetype()
+			return self._mimetype_tuple
 
 	def mark(self, boolean):
 		directory = self.env.get_directory(self.dirname)
revision' href='/akspecs/aerc/blame/ui/grid.go?h=0.1.0&id=7f67162f43374188f619e571c6d614626a24127a'>^
1892d73 ^



f0791d4 ^
1892d73 ^

8c8c21f ^


1892d73 ^



8c8c21f ^
335db04 ^
8c8c21f ^

60b351b ^















f0791d4 ^









a0c2b1c ^
5feb7de ^


a0c2b1c ^






1892d73 ^




5feb7de ^



4675648 ^
335db04 ^

1892d73 ^

60b351b ^

1892d73 ^



1892d73 ^
60b351b ^



1892d73 ^








f0791d4 ^
1892d73 ^

60b351b ^
f0791d4 ^



60b351b ^
f0791d4 ^
1892d73 ^


f0791d4 ^





60b351b ^

1892d73 ^
60b351b ^
1892d73 ^


f0791d4 ^

1892d73 ^


60b351b ^
1892d73 ^
5685a17 ^
60b351b ^



5feb7de ^
4675648 ^
60b351b ^

5feb7de ^
8c8c21f ^

60b351b ^




60b351b ^
5feb7de ^
4675648 ^
5feb7de ^
8c8c21f ^
335db04 ^
60b351b ^

8c8c21f ^

bb46b2b ^
5feb7de ^
bb46b2b ^

4675648 ^
8c8c21f ^


5feb7de ^
60b351b ^
8c8c21f ^



5feb7de ^
4675648 ^
8c8c21f ^




5feb7de ^
8c8c21f ^


335db04 ^
5685a17 ^
8c8c21f ^
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