Commit 1cde4462 by willmcgugan

Work in progress

parent 338423c7
...@@ -197,7 +197,7 @@ class FS(object): ...@@ -197,7 +197,7 @@ class FS(object):
raise FSError("NO_SYS_PATH", path) raise FSError("NO_SYS_PATH", path)
def open(self, pathname, mode="r", buffering=-1, **kwargs): def open(self, path, mode="r", buffering=-1, **kwargs):
pass pass
...@@ -407,9 +407,9 @@ class OSFS(FS): ...@@ -407,9 +407,9 @@ class OSFS(FS):
sys_path = self.getsyspath(path) sys_path = self.getsyspath(path)
if recursive: if recursive:
makedirs(sys_path, mode) os.makedirs(sys_path, mode)
else: else:
makedir(sys_path, mode) os.makedir(sys_path, mode)
def remove(self, path): def remove(self, path):
...@@ -421,7 +421,7 @@ class OSFS(FS): ...@@ -421,7 +421,7 @@ class OSFS(FS):
raise FSError("FILE_DELETE_FAILED", path, details=e) raise FSError("FILE_DELETE_FAILED", path, details=e)
def remove_dir(self, path, recursive=False): def removedir(self, path, recursive=False):
sys_path = self.getsyspath(path) sys_path = self.getsyspath(path)
......
#!/usr/bin/env python #!/usr/in/env python
from fs import FS from fs import FS, FSError
class MultiFS(FS): class MultiFS(FS):
...@@ -10,10 +10,17 @@ class MultiFS(FS): ...@@ -10,10 +10,17 @@ class MultiFS(FS):
self.fs_sequence = [] self.fs_sequence = []
self.fs_lookup = {} self.fs_lookup = {}
def __str__(self):
return "<MultiFS: %s>" % ", ".join(str(fs) for fs in self.fs_sequence)
def add_fs(self, name, fs): def add_fs(self, name, fs):
self.fs_sequence.append(name, fs) if name in self.fs_lookup:
raise ValueError("Name already exists.")
self.fs_sequence.append(fs)
self.fs_lookup[name] = fs self.fs_lookup[name] = fs
...@@ -28,8 +35,6 @@ class MultiFS(FS): ...@@ -28,8 +35,6 @@ class MultiFS(FS):
return self.fs_lookup[name] return self.fs_lookup[name]
def __iter__(self): def __iter__(self):
return iter(self.fs_sequence) return iter(self.fs_sequence)
...@@ -41,7 +46,80 @@ class MultiFS(FS): ...@@ -41,7 +46,80 @@ class MultiFS(FS):
return fs return fs
return None return None
def getsyspath(self, path):
fs = self._delegate_search(path)
if fs is not None:
return fs.getsyspath(path)
raise FSError("NO_FILE", path)
def open(self, path, mode="r", buffering=-1, **kwargs):
for fs in self:
if fs.exists(path):
fs_file = fs.open(path, mode, buffering, **kwargs)
return fs_file
raise FSError("NO_FILE", path)
def exists(self, path): def exists(self, path):
return self._delegate_search(path) is not None return self._delegate_search(path) is not None
def isdir(self, path):
fs = self._delegate_search(path)
if fs is not None:
return fs.isdir()
return False
def isfile(self, path):
fs = self._delegate_search(path)
if fs is not None:
return fs.isfile()
return False
def ishidden(self, path):
fs = self._delegate_search(path)
if fs is not None:
return fs.isfile()
return False
def listdir(self, path="./", *args, **kwargs):
paths = []
for fs in self:
try:
paths += fs.listdir(path, *args, **kwargs)
except FSError, e:
pass
return list(set(paths))
def remove(self, path):
for fs in self:
if fs.exist(path):
fs.remove(path)
return
raise FSError("NO_FILE", path)
def removedir(self, path, recursive=False):
for fs in self:
if fs.isdir(path):
fs.removedir(path, recursive)
return
raise FSError("NO_DIR", path)
def getinfo(self, path):
for fs in self:
if fs.exist(path):
return fs.getinfo(path)
raise FSError("NO_FILE", path)
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