Commit 1cde4462 by willmcgugan

Work in progress

parent 338423c7
......@@ -194,10 +194,10 @@ class FS(object):
return pathname
def getsyspath(self, 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
......@@ -265,17 +265,17 @@ class FS(object):
yield path
def walk(self, path="/", wildcard=None, dir_wildcard=None):
dirs = [path]
while dirs:
current_path = dirs.pop()
paths = []
for path in self.listdir(current_path, full=True):
if self.isdir(path):
if dir_wildcard is not None:
if fnmatch.fnmatch(path, dir_wilcard):
......@@ -288,7 +288,7 @@ class FS(object):
paths.append(path)
else:
paths.append(path)
yield (current_path, paths)
......@@ -320,7 +320,7 @@ class SubFS(FS):
def open(self, pathname, mode="r", buffering=-1, **kwargs):
return self.parent.open(self._delegate(pathname), mode, buffering)
def open_dir(self, path):
if not self.exists(dirname):
......@@ -407,9 +407,9 @@ class OSFS(FS):
sys_path = self.getsyspath(path)
if recursive:
makedirs(sys_path, mode)
os.makedirs(sys_path, mode)
else:
makedir(sys_path, mode)
os.makedir(sys_path, mode)
def remove(self, path):
......@@ -421,7 +421,7 @@ class OSFS(FS):
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)
......
#!/usr/bin/env python
#!/usr/in/env python
from fs import FS
from fs import FS, FSError
class MultiFS(FS):
def __init__(self):
FS.__init__(self)
self.fs_sequence = []
self.fs_lookup = {}
def __str__(self):
return "<MultiFS: %s>" % ", ".join(str(fs) for fs in self.fs_sequence)
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
def remove_fs(self, name):
fs = self.fs_lookup[name]
self.fs_sequence.remove(fs)
del self.fs_lookup[name]
def __getitem__(self, name):
return self.fs_lookup[name]
def __iter__(self):
return iter(self.fs_sequence)
def _delegate_search(self, path):
for fs in self:
if self.exists(path):
return fs
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):
return self._delegate_search(path) is not None
\ No newline at end of file
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