about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2015-04-13 13:30:13 +0200
committerhut <hut@lepus.uberspace.de>2015-04-13 13:30:13 +0200
commit489a446cee990cdded2c69687fe44e1426710465 (patch)
tree6757f79645e7bd62b5171f4e449f3b610ce58cbf
parent3212bd8b3a154b8b11296cd581c9edc9ce741175 (diff)
downloadranger-489a446cee990cdded2c69687fe44e1426710465.tar.gz
container.tags: added TagsDummy class for use with --clean
-rw-r--r--ranger/container/tags.py37
-rw-r--r--ranger/core/fm.py4
2 files changed, 40 insertions, 1 deletions
diff --git a/ranger/container/tags.py b/ranger/container/tags.py
index 7ecef603..098ae9e3 100644
--- a/ranger/container/tags.py
+++ b/ranger/container/tags.py
@@ -109,3 +109,40 @@ class Tags(object):
     def __nonzero__(self):
         return True
     __bool__ = __nonzero__
+
+
+class TagsDummy(Tags):
+    """A dummy Tags class for use with `ranger --clean`.
+
+    It acts like there are no tags and avoids writing any changes.
+    """
+
+    def __init__(self, filename):
+        self.tags = dict()
+
+    def __contains__(self, item):
+        return False
+
+    def add(self, *items, **others):
+        pass
+
+    def remove(self, *items, **others):
+        pass
+
+    def toggle(self, *items, **others):
+        pass
+
+    def marker(self, item):
+        return self.default_tag
+
+    def sync(self):
+        pass
+
+    def dump(self):
+        pass
+
+    def _compile(self, f):
+        pass
+
+    def _parse(self, f):
+        pass
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 8ae1e753..6c9513c3 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -15,7 +15,7 @@ import sys
 import ranger.api
 from ranger.core.actions import Actions
 from ranger.core.tab import Tab
-from ranger.container.tags import Tags
+from ranger.container.tags import Tags, TagsDummy
 from ranger.gui.ui import UI
 from ranger.container.bookmarks import Bookmarks
 from ranger.core.runner import Runner
@@ -100,6 +100,8 @@ class FM(Actions, SignalDispatcher):
 
         if not ranger.arg.clean and self.tags is None:
             self.tags = Tags(self.confpath('tagged'))
+        elif ranger.arg.clean:
+            self.tags = TagsDummy("")
 
         if self.bookmarks is None:
             if ranger.arg.clean: