summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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)
' href='#n156'>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