Commit 274827b9 by willmcgugan

Refactor and ehancements to mountfs

parent fe9f7194
...@@ -119,5 +119,6 @@ def browse(fs): ...@@ -119,5 +119,6 @@ def browse(fs):
if __name__ == "__main__": if __name__ == "__main__":
home_fs = fs.OSFS("~/") from osfs import OSFS
home_fs = OSFS("~/")
browse(home_fs) browse(home_fs)
...@@ -321,6 +321,9 @@ class MemoryFS(FS): ...@@ -321,6 +321,9 @@ class MemoryFS(FS):
def getinfo(self, path): def getinfo(self, path):
dir_entry = self._get_dir_entry(path) dir_entry = self._get_dir_entry(path)
if dir_entry is None:
raise ResourceNotFoundError("NO_RESOURCE", path)
info = {} info = {}
info['created_time'] = dir_entry.created_time info['created_time'] = dir_entry.created_time
......
...@@ -12,23 +12,26 @@ class ObjectTree(object): ...@@ -12,23 +12,26 @@ class ObjectTree(object):
def __init__(self): def __init__(self):
self.root = _ObjectDict() self.root = _ObjectDict()
def _splitpath(self, path):
return [p for p in path.split('/') if p]
def _locate(self, path): def _locate(self, path):
current = self.root current = self.root
for path_component in path.split('/'): for path_component in self._splitpath(path):
if type(current) is not _ObjectDict: if type(current) is not _ObjectDict:
return None return None
node = current.get(path_component, None) node = current.get(path_component, None)
if node is None: if node is None:
return None return None
current = node current = node
return node return current
def __setitem__(self, path, object): def __setitem__(self, path, object):
if not path: if not path:
raise IndexError("No path supplied") raise IndexError("No path supplied")
current = self.root current = self.root
path, name = path.rsplit('/', 1) path, name = path.rsplit('/', 1)
for path_component in path.split('/'): for path_component in self._splitpath(path):
node = current.get(path_component, None) node = current.get(path_component, None)
if type(node) is not _ObjectDict: if type(node) is not _ObjectDict:
new_dict = _ObjectDict() new_dict = _ObjectDict()
...@@ -57,6 +60,21 @@ class ObjectTree(object): ...@@ -57,6 +60,21 @@ class ObjectTree(object):
return default return default
return node return node
def partialget(self, path, default=None):
current = self.root
partial_path = []
remaining_path = self._splitpath(path)
for path_component in remaining_path[:]:
if type(current) is not _ObjectDict:
return "/".join(partial_path), current, "/".join(remaining_path)
partial_path.append(path_component)
remaining_path.pop(0)
node = current.get(path_component, None)
if node is None:
return None, default, None
current = node
return path, current, ""
def isobject(self, path): def isobject(self, path):
node = self._locate(path) node = self._locate(path)
return type(node) is not _ObjectDict return type(node) is not _ObjectDict
...@@ -87,6 +105,8 @@ if __name__ == "__main__": ...@@ -87,6 +105,8 @@ if __name__ == "__main__":
print ot['a/b/c'] print ot['a/b/c']
print ot.partialget("/a/b/c/d/e/f")
ot['a/b/c/d'] = "?" ot['a/b/c/d'] = "?"
print ot['a/b/c'].keys() print ot['a/b/c'].keys()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment