diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-04 16:24:15 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-04 16:24:15 +0000 |
commit | 60e6eff7b1f723a78b564f0ba9d75ac4e7d18b39 (patch) | |
tree | faf15bcdaff5501ead277f0611879991bb3dd161 | |
parent | 41f626a4b268e6734e1e9addb559d3d15a4c1a5f (diff) | |
download | pyfilesystem-git-60e6eff7b1f723a78b564f0ba9d75ac4e7d18b39.tar.gz |
Work in progress
-rw-r--r-- | fs/browsewin.py | 4 | ||||
-rw-r--r-- | fs/fs.py | 42 | ||||
-rw-r--r-- | fs/memoryfs.py | 4 | ||||
-rw-r--r-- | fs/osfs.py | 8 | ||||
-rw-r--r-- | fs/tests.py | 6 | ||||
-rw-r--r-- | fs/utils.py | 7 |
6 files changed, 18 insertions, 53 deletions
diff --git a/fs/browsewin.py b/fs/browsewin.py index 5096c21..49b0954 100644 --- a/fs/browsewin.py +++ b/fs/browsewin.py @@ -8,7 +8,7 @@ import fs class InfoFrame(wx.Frame): def __init__(self, path, desc, info): - wx.Frame.__init__(self, None, -1, style=wx.DEFAULT_FRAME_STYLE, size=(700, 500)) + wx.Frame.__init__(self, None, -1, style=wx.DEFAULT_FRAME_STYLE, size=(500, 500)) self.SetTitle("FS Object info - %s (%s)" % (path, desc)) @@ -20,7 +20,7 @@ class InfoFrame(wx.Frame): self.list_ctrl.InsertColumn(0, "Key") self.list_ctrl.InsertColumn(1, "Value") - self.list_ctrl.SetColumnWidth(0, 150) + self.list_ctrl.SetColumnWidth(0, 190) self.list_ctrl.SetColumnWidth(1, 300) for key in keys: @@ -25,6 +25,7 @@ error_msgs = { "DIR_EXISTS" : "Directory exists (try allow_recreate=True): %(path)s", "REMOVE_FAILED" : "Unable to remove file: %(path)s", "REMOVEDIR_FAILED" : "Unable to remove dir: %(path)s", + "GETSIZE_FAILED" : "Unable to retrieve size of resource: %(path)s", # NoSysPathError "NO_SYS_PATH" : "No mapping to OS filesytem: %(path)s,", @@ -487,7 +488,16 @@ class FS(object): def getsize(self, path): - return self.getinfo(path)['size'] + """Returns the size (in bytes) of a resource. + + path -- A path to the resource + + """ + info = self.getinfo(path) + size = info.get('size', None) + if 'size' is None: + raise OperationFailedError("GETSIZE_FAILED", path) + return size @@ -576,36 +586,6 @@ class SubFS(FS): def rename(self, src, dst): return self.parent.rename(self._delegate(src), self._delegate(dst)) -def validatefs(fs): - - expected_methods = [ "abspath", - "getsyspath", - "open", - "exists", - "isdir", - "isfile", - "ishidden", - "listdir", - "makedir", - "remove", - "removedir", - "getinfo", - "getsize", - "rename", - ] - - pad_size = len(max(expected_methods, key=str.__len__)) - count = 0 - for method_name in sorted(expected_methods): - method = getattr(fs, method_name, None) - if method is None: - print method_name.ljust(pad_size), '?' - else: - print method_name.ljust(pad_size), 'X' - count += 1 - print - print "%i out of %i methods" % (count, len(expected_methods)) - if __name__ == "__main__": import osfs diff --git a/fs/memoryfs.py b/fs/memoryfs.py index 10751b8..003ffbe 100644 --- a/fs/memoryfs.py +++ b/fs/memoryfs.py @@ -411,9 +411,7 @@ class MemoryFS(FS): dir_entry = self._get_dir_entry(path)
if dir_entry is None:
raise ResourceNotFoundError("NO_DIR", path)
- paths = dir_entry.contents.keys()
- print "Listdir", paths
-
+ paths = dir_entry.contents.keys()
return self._listdir_helper(path, paths, wildcard, full, absolute, hidden, dirs_only, files_only)
finally:
self._lock.release()
@@ -140,14 +140,6 @@ class OSFS(FS): if __name__ == "__main__": osfs = OSFS("~/projects") - print osfs - - for filename in osfs.walkfiles("/", "*.pov"): - print filename - print osfs.getinfo(filename) - - validatefs(osfs) - import browsewin browsewin.browse(osfs) diff --git a/fs/tests.py b/fs/tests.py index d44f2a5..3c753fd 100644 --- a/fs/tests.py +++ b/fs/tests.py @@ -247,15 +247,13 @@ class TestOSFS(unittest.TestCase): info = self.fs.getinfo("info.txt") self.assertEqual(info['size'], len(test_str)) - def test_getsize(self): - test_str = "*"*23 f = self.fs.open("info.txt", 'wb') f.write(test_str) f.close() - info = self.fs.getinfo("info.txt") - self.assertEqual(info['size'], len(test_str)) + size = self.fs.getsize("info.txt") + self.assertEqual(size, len(test_str)) class TestSubFS(TestOSFS): diff --git a/fs/utils.py b/fs/utils.py index 8a94750..672f55a 100644 --- a/fs/utils.py +++ b/fs/utils.py @@ -10,7 +10,7 @@ def copy_file(src_fs, src_path, dst_fs, dst_path, chunk_size=1024*16): dst_fs -- Destination filesystem object dst_path -- Destination filesystem object chunk_size -- Size of chunks to move if system copyfile is not available (default 16K) - + """ src_syspath = src_fs.getsyspath(src_path, default="") @@ -48,7 +48,4 @@ def get_total_data(count_fs): """ - total = 0 - for f in count_fs.walkfiles(absolute=True): - total += count_fs.getsize(f) - return total + total = sum(count_fs.getsize(f) for f in count_fs.walkfiles(absolute=True)) |