diff options
author | hut <hut@lavabit.com> | 2010-05-06 01:04:01 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-05-06 01:04:01 +0200 |
commit | 4ffef98ccdc5abb1352697bc92cd507d17d7946f (patch) | |
tree | fdd06da1ce2611edb5937c2f20ca2addee2c6f98 /ranger | |
parent | 4de6abaf0ba5431395d2a627cddebdd86f10975f (diff) | |
download | ranger-4ffef98ccdc5abb1352697bc92cd507d17d7946f.tar.gz |
fsobject.fsobject: lazily load mimetype
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/fsobject/fsobject.py | 37 |
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) |