Commit 44ecace3 by willmcgugan

Work in progress, added more tests and a info window for BrowseWin

parent 8e72b82d
......@@ -5,6 +5,29 @@ import wx.gizmos
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))
self.SetTitle("FS Object info - %s (%s)" % (path, desc))
keys = info.keys()
keys.sort()
self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.list_ctrl.InsertColumn(0, "Key")
self.list_ctrl.InsertColumn(1, "Value")
self.list_ctrl.SetColumnWidth(0, 150)
self.list_ctrl.SetColumnWidth(1, 300)
for key in keys:
self.list_ctrl.Append((key, str(info[key])))
class BrowseFrame(wx.Frame):
def __init__(self, fs):
......@@ -36,6 +59,8 @@ class BrowseFrame(wx.Frame):
self.tree.SetItemImage(self.root_id, self.fldropenidx, wx.TreeItemIcon_Expanded)
self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.OnItemExpanding)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemActivated)
wx.CallAfter(self.OnInit)
......@@ -109,6 +134,14 @@ class BrowseFrame(wx.Frame):
self.expand(e.GetItem())
e.Skip()
def OnItemActivated(self, e):
item_data = self.tree.GetItemData(e.GetItem()).GetData()
path = item_data["path"]
info = self.fs.getinfo(path)
info_frame = InfoFrame(path, self.fs.desc(path), info)
info_frame.Show()
def browse(fs):
......
......@@ -41,6 +41,9 @@ error_msgs = {
"NO_FILE" : "No such file: %(path)s",
"NO_RESOURCE" : "No path to: %(path)s",
# ResourceInvalid
"WRONG_TYPE" : "Resource is not the type that was expected: %(path)s",
# SystemError
"OS_ERROR" : "Non specific OS error: %(path)s",
}
......@@ -78,6 +81,7 @@ class PathError(FSError): pass
class ResourceLockedError(FSError): pass
class ResourceNotFoundError(FSError): pass
class SystemError(FSError): pass
class ResourceInvalid(FSError): pass
class NullFile(object):
......@@ -549,13 +553,13 @@ class SubFS(FS):
def makedir(self, path, mode=0777, recursive=False):
return self.parent.makedir(self._delegate(path), mode=mode, recursive=False)
return self.parent.makedir(self._delegate(path), mode=mode, recursive=recursive)
def remove(self, path):
return self.parent.remove(self._delegate(path))
def removedir(self, path, recursive=False):
self.parent.removedir(self._delegate(path), recursive=False)
self.parent.removedir(self._delegate(path), recursive=recursive)
def getinfo(self, path):
return self.parent.getinfo(self._delegate(path))
......
......@@ -343,6 +343,56 @@ class MemoryFS(FS):
finally:
self._lock.release()
def removedir(self, path, recursive=False):
self._lock.acquire()
try:
dir_entry = self._get_dir_entry(path)
if dir_entry is None:
raise ResourceNotFoundError("NO_DIR", path)
if dir_entry.islocked():
raise ResourceLockedError("FILE_LOCKED", path)
if not dir_entry.isdir():
raise ResourceInvalid("WRONG_TYPE", path, msg="Can't remove resource, its not a directory: %(path)s" )
if not recursive and len(dir_entry.contents):
raise OperationFailedError("REMOVEDIR_FAILED", "Directory is not empty: %(path)s")
if recursive:
rpathname = path
while rpathname:
rpathname, dirname = pathsplit(rpathname)
parent_dir = self._get_dir_entry(rpathname)
del parent_dir.contents[dirname]
else:
pathname, dirname = pathsplit(path)
parent_dir = self._get_dir_entry(pathname)
del parent_dir.contents[dirname]
finally:
self._lock.release()
def rename(self, src, dst):
self._lock.acquire()
try:
dir_entry = self._get_dir_entry(src)
if dir_entry is None:
raise ResourceNotFoundError("NO_DIR", src)
if dir_entry.islocked():
raise ResourceLockedError("FILE_LOCKED", src)
dst_dir_entry = self._get_dir_entry(dst)
if dst_dir_entry is not None:
raise OperationFailedError("RENAME_FAILED", "Destination exists: %(path)s", src + " -> " + dst )
pathname, dirname = pathsplit(src)
parent_dir = self._get_dir_entry(pathname)
parent_dir.contents[dst] = parent_dir.contents[dirname]
del parent_dir.contents[dirname]
finally:
self._lock.release()
def _on_close_memory_file(self, path, value):
self._lock.acquire()
try:
......
......@@ -75,7 +75,6 @@ class OSFS(FS):
except OSError, e:
raise OperationFailedError("REMOVE_FAILED", path, details=e)
def removedir(self, path, recursive=False):
sys_path = self.getsyspath(path)
......
......@@ -7,7 +7,6 @@ import shutil
class TestHelpers(unittest.TestCase):
def test_isabsolutepath(self):
"""fs.isabsolutepath tests"""
tests = [ ('', False),
('/', True),
('/A/B', True),
......@@ -18,7 +17,6 @@ class TestHelpers(unittest.TestCase):
self.assertEqual(fs.isabsolutepath(path), result)
def test_normpath(self):
"""fs.normpath tests"""
tests = [ ("\\a\\b\\c", "/a/b/c"),
("", ""),
("/a/b/c", "/a/b/c"),
......@@ -27,7 +25,6 @@ class TestHelpers(unittest.TestCase):
self.assertEqual(fs.normpath(path), result)
def test_pathjon(self):
"""fs.pathjoin tests"""
tests = [ ("", "a", "a"),
("a", "a", "a/a"),
("a/b", "../c", "a/c"),
......@@ -55,7 +52,6 @@ class TestHelpers(unittest.TestCase):
self.assertRaises(fs.PathError, fs.pathjoin, "a/b/../../../d")
def test_makerelative(self):
"""fs.makerelative tests"""
tests = [ ("/a/b", "a/b"),
("a/b", "a/b"),
("/", "") ]
......@@ -65,7 +61,6 @@ class TestHelpers(unittest.TestCase):
self.assertEqual(fs.makerelative(path), result)
def test_makeabsolute(self):
"""fs.makeabsolute tests"""
tests = [ ("/a/b", "/a/b"),
("a/b", "/a/b"),
("/", "/") ]
......@@ -74,7 +69,6 @@ class TestHelpers(unittest.TestCase):
self.assertEqual(fs.makeabsolute(path), result)
def test_iteratepath(self):
"""fs.iteratepath tests"""
tests = [ ("a/b", ["a", "b"]),
("", [] ),
("aaa/bbb/ccc", ["aaa", "bbb", "ccc"]),
......@@ -89,7 +83,6 @@ class TestHelpers(unittest.TestCase):
self.assertEqual(list(fs._iteratepath("a/b/c/d", 2)), ["a", "b", "c/d"])
def test_pathsplit(self):
"""fs.pathsplit tests"""
tests = [ ("a/b", ("a", "b")),
("a/b/c", ("a/b", "c")),
("a", ("", "a")),
......@@ -107,7 +100,6 @@ import objecttree
class TestObjectTree(unittest.TestCase):
def test_getset(self):
"""objecttree.ObjectTree tests"""
ot = objecttree.ObjectTree()
ot['foo'] = "bar"
self.assertEqual(ot['foo'], 'bar')
......@@ -145,23 +137,20 @@ import tempfile
import osfs
import os
class TestFS(unittest.TestCase):
class TestOSFS(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp("fstest")
self.fs = osfs.OSFS(self.temp_dir)
print "Temp dir is", self.temp_dir
def tearDown(self):
assert "fstest" in self.temp_dir
shutil.rmtree(self.temp_dir)
def check(self, p):
return os.path.exists(os.path.join(self.temp_dir, p))
def test_makedir(self):
"""osfs.makedir tests"""
check = self.check
self.fs.makedir("a")
......@@ -179,7 +168,6 @@ class TestFS(unittest.TestCase):
def test_removedir(self):
"""osfs.removedir tests"""
check = self.check
self.fs.makedir("a")
self.assert_(check("a"))
......@@ -201,13 +189,41 @@ class TestFS(unittest.TestCase):
self.assert_(not check("foo"))
def test_rename(self):
"""osfs.rename tests"""
check = self.check
self.fs.open("foo.txt", 'wt').write("Hello, World!")
self.assert_(check("foo.txt"))
self.fs.rename("foo.txt", "bar.txt")
self.assert_(check("bar.txt"))
class TestSubFS(TestOSFS):
def setUp(self):
self.temp_dir = tempfile.mkdtemp("fstest")
self.parent_fs = osfs.OSFS(self.temp_dir)
self.parent_fs.makedir("foo/bar", recursive=True)
self.fs = self.parent_fs.opendir("foo/bar")
print "Temp dir is", self.temp_dir
def tearDown(self):
shutil.rmtree(self.temp_dir)
def check(self, p):
p = os.path.join("foo/bar", p)
return os.path.exists(os.path.join(self.temp_dir, p))
import memoryfs
class TestMemoryFS(TestOSFS):
def setUp(self):
self.fs = memoryfs.MemoryFS()
def tearDown(self):
pass
def check(self, p):
return self.fs.exists(p)
if __name__ == "__main__":
#t = TestFS()
......
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