diff options
-rw-r--r-- | ranger/core/filter_stack.py | 5 | ||||
-rw-r--r-- | ranger/core/fm.py | 7 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 6 |
3 files changed, 8 insertions, 10 deletions
diff --git a/ranger/core/filter_stack.py b/ranger/core/filter_stack.py index 58ce1a1c..66ab95c3 100644 --- a/ranger/core/filter_stack.py +++ b/ranger/core/filter_stack.py @@ -6,7 +6,6 @@ from __future__ import (absolute_import, division, print_function) import re -import mimetypes # pylint: disable=invalid-name try: from itertools import izip_longest as zip_longest @@ -59,13 +58,13 @@ class NameFilter(BaseFilter): @stack_filter("mime") -class MimeFilter(BaseFilter): +class MimeFilter(BaseFilter, FileManagerAware): def __init__(self, pattern): self.pattern = pattern self.regex = re.compile(pattern) def __call__(self, fobj): - mimetype, _ = mimetypes.guess_type(fobj.relative_path) + mimetype, _ = self.fm.mimetypes.guess_type(fobj.relative_path) if mimetype is None: return False return self.regex.search(mimetype) diff --git a/ranger/core/fm.py b/ranger/core/fm.py index da8b27c3..52cd83d6 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -73,9 +73,10 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes self.hostname = socket.gethostname() self.home_path = os.path.expanduser('~') - mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types')) - mimetypes.knownfiles.append(self.relpath('data/mime.types')) - self.mimetypes = mimetypes.MimeTypes() + if not mimetypes.inited: + extra_files = [self.relpath('data/mime.types'), os.path.expanduser("~/.mime.types")] + mimetypes.init(mimetypes.knownfiles + extra_files) + self.mimetypes = mimetypes def initialize(self): # pylint: disable=too-many-statements """If ui/bookmarks are None, they will be initialized here.""" diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index e0773324..af75ac41 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -144,7 +144,6 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes self.config_file = config_file self._app_flags = '' self._app_label = None - self._initialized_mimetypes = False self._mimetype = None self._skip = None self.rules = None @@ -252,9 +251,8 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes return self._mimetype import mimetypes - for path in self._mimetype_known_files: - if path not in mimetypes.knownfiles: - mimetypes.knownfiles.append(path) + if not mimetypes.inited: + mimetypes.init(mimetypes.knownfiles + self._mimetype_known_files) self._mimetype, _ = mimetypes.guess_type(fname) if not self._mimetype: |