summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2011-06-02 17:10:29 +0200
committerLaurent Bachelier <laurent@bachelier.name>2011-06-02 17:10:29 +0200
commit07f137a3f2f44b2515f846ffc4860dc5f8ccbd7f (patch)
tree4cd94e1eacd57a687f1d72a123bbefd9fec9fe64
parentStart support for altering values (diff)
downloadffs-07f137a3f2f44b2515f846ffc4860dc5f8ccbd7f.tar.xz
Support deletion of lists
-rw-r--r--ffs.py8
-rw-r--r--test.py7
2 files changed, 13 insertions, 2 deletions
diff --git a/ffs.py b/ffs.py
index 04b97db..8f0a447 100644
--- a/ffs.py
+++ b/ffs.py
@@ -1,6 +1,7 @@
from collections import MutableMapping
import os
from fnmatch import fnmatchcase
+import shutil
class RouterError(Exception):
@@ -55,8 +56,11 @@ class List(MutableMapping):
return cls
def __delitem__(self, key):
- assert self._get_cls(key)
- os.unlink(os.path.join(self.root, key))
+ cls = self._get_cls(key)
+ if isinstance(cls, Router):
+ shutil.rmtree(os.path.join(self.root, key))
+ else:
+ os.unlink(os.path.join(self.root, key))
def __setitem__(self, key, value):
cls = self.router.route(key)
diff --git a/test.py b/test.py
index d7a98ba..56655e9 100644
--- a/test.py
+++ b/test.py
@@ -69,3 +69,10 @@ class FfsTest(TestCase):
lst2['cot'] = "hello2"
assert 'cot' in lst2
assert lst2['cot'] == "hello2"
+
+ def test_listDelete(self):
+ rtr = Router(lol=Router(cat=str, cot=str))
+ lst1 = List(self.root, rtr)
+ assert 'lol' in lst1
+ del lst1['lol']
+ assert 'lol' not in lst1