Commit 2490d82a by willmcgugan

Added a 'makeopendir' method which makes and opens a directory in one. Made FS objects iterable

parent 08428cd2
......@@ -246,6 +246,12 @@ class FS(object):
raise UnsupportedError("check for file")
def __iter__(self):
""" Iterates over paths returned by listdir method with default params. """
for f in self.listdir():
yield f
def listdir(self, path="./",
wildcard=None,
full=False,
......@@ -689,11 +695,26 @@ class FS(object):
return False
def makeopendir(self, path, recursive=False):
"""Makes a directory (if it doesn't exist) and returns an FS object for
the newly created directory.
path -- Path to the new directory
recursive -- If True any intermediate directories will be created
"""
self.makedir(path, allow_recreate=True, recursive=recursive)
dir_fs = self.opendir(path)
return dir_fs
class SubFS(FS):
"""A SubFS represents a sub directory of another filesystem object.
SubFS objects are returned by opendir, which effectively creates a 'sandbox'
SubFS objects are returned by opendir, which effectively creates a
'sandbox' filesystem that can only access files/dirs under a root path
within its 'parent' dir.
"""
......@@ -825,4 +846,3 @@ def flags_to_mode(flags):
else:
mode = "r"
return mode
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