diff options
author | toonn <toonn@toonn.io> | 2020-12-31 22:56:37 +0100 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2020-12-31 22:56:37 +0100 |
commit | 42cb5a521bf9b24eaaf47daed2b45763e704c347 (patch) | |
tree | a9da57999588af85ccb6d7ffa4bc9255da5f9c45 | |
parent | 92d7079f523bb62b4fa28cd79077c0df99829025 (diff) | |
parent | a06ec2dce53d16dcab3e5a817d4c67c8568fe1b4 (diff) | |
download | ranger-42cb5a521bf9b24eaaf47daed2b45763e704c347.tar.gz |
Merge branch 'tags-errors'
-rw-r--r-- | ranger/container/tags.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/ranger/container/tags.py b/ranger/container/tags.py index 50d5ff72..50525848 100644 --- a/ranger/container/tags.py +++ b/ranger/container/tags.py @@ -5,30 +5,34 @@ from __future__ import (absolute_import, division, print_function) -from os.path import isdir, exists, dirname, abspath, realpath, expanduser, sep +from os.path import exists, abspath, realpath, expanduser, sep import string from ranger import PY3 +from ranger.core.shared import FileManagerAware ALLOWED_KEYS = string.ascii_letters + string.digits + string.punctuation -class Tags(object): +class Tags(FileManagerAware): default_tag = '*' def __init__(self, filename): + # COMPAT: The intent is to get abspath/normpath's behavior of + # collapsing `symlink/..`, abspath is retained for historical reasons + # because the documentation states its behavior isn't necessarily in + # line with normpath's. self._filename = realpath(abspath(expanduser(filename))) - if isdir(dirname(self._filename)) and not exists(self._filename): - open(self._filename, 'w') - self.sync() def __contains__(self, item): return item in self.tags def add(self, *items, **others): + if len(*items) == 0: + return tag = others.get('tag', self.default_tag) self.sync() for item in items: @@ -36,6 +40,8 @@ class Tags(object): self.dump() def remove(self, *items): + if len(*items) == 0: + return self.sync() for item in items: try: @@ -45,6 +51,8 @@ class Tags(object): self.dump() def toggle(self, *items, **others): + if len(*items) == 0: + return tag = others.get('tag', self.default_tag) tag = str(tag) if tag not in ALLOWED_KEYS: @@ -71,8 +79,11 @@ class Tags(object): fobj = open(self._filename, 'r', errors='replace') else: fobj = open(self._filename, 'r') - except OSError: - pass + except OSError as err: + if exists(self._filename): + self.fm.notify(err, bad=True) + else: + self.tags = dict() else: self.tags = self._parse(fobj) fobj.close() @@ -80,8 +91,8 @@ class Tags(object): def dump(self): try: fobj = open(self._filename, 'w') - except OSError: - pass + except OSError as err: + self.fm.notify(err, bad=True) else: self._compile(fobj) fobj.close() |