Commit dc82b110 by willmcgugan

Work in progress

parent 1865b55d
...@@ -58,7 +58,7 @@ class FSError(Exception): ...@@ -58,7 +58,7 @@ class FSError(Exception):
"""A catch all exception for FS objects.""" """A catch all exception for FS objects."""
def __init__(self, code, path=None, path2=None, msg=None, details=None): def __init__(self, code, path=None, path2=None, msg=None, details=None):
""" """A unified exception class that represents Filesystem errors.
code -- A short identifier for the error code -- A short identifier for the error
path -- A path associated with the error path -- A path associated with the error
...@@ -269,7 +269,7 @@ def _iteratepath(path, numsplits=None): ...@@ -269,7 +269,7 @@ def _iteratepath(path, numsplits=None):
return filter(lambda p:bool(p), path.split('/', numsplits)) return filter(lambda p:bool(p), path.split('/', numsplits))
def print_fs(fs, path="/", max_levels=None, indent=' '*2): def print_fs(fs, path="/", max_levels=2, indent=' '*2):
"""Prints a filesystem listing to stdout (including sub dirs). Useful as a debugging aid. """Prints a filesystem listing to stdout (including sub dirs). Useful as a debugging aid.
Be careful about printing a OSFS, or any other large filesystem. Be careful about printing a OSFS, or any other large filesystem.
Without max_levels set, this function will traverse the entire directory tree. Without max_levels set, this function will traverse the entire directory tree.
...@@ -295,6 +295,9 @@ def print_fs(fs, path="/", max_levels=None, indent=' '*2): ...@@ -295,6 +295,9 @@ def print_fs(fs, path="/", max_levels=None, indent=' '*2):
print indent*level + '[%s]' % item print indent*level + '[%s]' % item
if max_levels is None or level < max_levels: if max_levels is None or level < max_levels:
print_dir(fs, pathjoin(path, item), level+1) print_dir(fs, pathjoin(path, item), level+1)
if max_levels is not None:
if level >= max_levels:
print indent*(level+1) + "[...]"
else: else:
print indent*level + '%s' % item print indent*level + '%s' % item
print_dir(fs, path, 0) print_dir(fs, path, 0)
...@@ -555,6 +558,17 @@ class FS(object): ...@@ -555,6 +558,17 @@ class FS(object):
def copyfile(self, src, dst, overwrite=False, chunk_size=1024*16384): def copyfile(self, src, dst, overwrite=False, chunk_size=1024*16384):
"""Copies a file from src to dst.
src -- The source path
dst -- The destination path
overwrite -- If True, then the destination may be overwritten
(if a file exists at that location). If False then an exception will be
thrown if the destination exists
chunk_size -- Size of chunks to use in copy, if a simple copy is required
"""
src_syspath = self.getsyspath(src, allow_none=True) src_syspath = self.getsyspath(src, allow_none=True)
dst_syspath = self.getsyspath(dst, allow_none=True) dst_syspath = self.getsyspath(dst, allow_none=True)
...@@ -587,6 +601,13 @@ class FS(object): ...@@ -587,6 +601,13 @@ class FS(object):
def movefile(self, src, dst): def movefile(self, src, dst):
"""Moves a file from one location to another.
src -- Source path
dst -- Destination path
"""
src_syspath = self.getsyspath(src, allow_none=True) src_syspath = self.getsyspath(src, allow_none=True)
dst_syspath = self.getsyspath(dst, allow_none=True) dst_syspath = self.getsyspath(dst, allow_none=True)
......
...@@ -147,7 +147,7 @@ if __name__ == "__main__": ...@@ -147,7 +147,7 @@ if __name__ == "__main__":
import browsewin import browsewin
browsewin.browse(osfs) browsewin.browse(osfs)
#print_fs(osfs) print_fs(osfs)
#print osfs.listdir("/projects/fs") #print osfs.listdir("/projects/fs")
......
...@@ -232,6 +232,7 @@ class TestOSFS(unittest.TestCase): ...@@ -232,6 +232,7 @@ class TestOSFS(unittest.TestCase):
self.assertEqual(len(d4), 4) self.assertEqual(len(d4), 4)
self.assertEqual(sorted(d4), ["p/1/2/3/a", "p/1/2/3/b", "p/1/2/3/bar", "p/1/2/3/foo"]) self.assertEqual(sorted(d4), ["p/1/2/3/a", "p/1/2/3/b", "p/1/2/3/bar", "p/1/2/3/foo"])
def test_rename(self): def test_rename(self):
check = self.check check = self.check
self.fs.open("foo.txt", 'wt').write("Hello, World!") self.fs.open("foo.txt", 'wt').write("Hello, World!")
......
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