Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
44ecace3
Commit
44ecace3
authored
Sep 04, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress, added more tests and a info window for BrowseWin
parent
8e72b82d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
17 deletions
+119
-17
fs/browsewin.py
+33
-0
fs/fs.py
+6
-2
fs/memoryfs.py
+50
-0
fs/osfs.py
+0
-1
fs/tests.py
+30
-14
No files found.
fs/browsewin.py
View file @
44ecace3
...
@@ -5,6 +5,29 @@ import wx.gizmos
...
@@ -5,6 +5,29 @@ import wx.gizmos
import
fs
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
):
class
BrowseFrame
(
wx
.
Frame
):
def
__init__
(
self
,
fs
):
def
__init__
(
self
,
fs
):
...
@@ -36,6 +59,8 @@ class BrowseFrame(wx.Frame):
...
@@ -36,6 +59,8 @@ class BrowseFrame(wx.Frame):
self
.
tree
.
SetItemImage
(
self
.
root_id
,
self
.
fldropenidx
,
wx
.
TreeItemIcon_Expanded
)
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_EXPANDING
,
self
.
OnItemExpanding
)
self
.
Bind
(
wx
.
EVT_TREE_ITEM_ACTIVATED
,
self
.
OnItemActivated
)
wx
.
CallAfter
(
self
.
OnInit
)
wx
.
CallAfter
(
self
.
OnInit
)
...
@@ -109,6 +134,14 @@ class BrowseFrame(wx.Frame):
...
@@ -109,6 +134,14 @@ class BrowseFrame(wx.Frame):
self
.
expand
(
e
.
GetItem
())
self
.
expand
(
e
.
GetItem
())
e
.
Skip
()
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
):
def
browse
(
fs
):
...
...
fs/fs.py
View file @
44ecace3
...
@@ -41,6 +41,9 @@ error_msgs = {
...
@@ -41,6 +41,9 @@ error_msgs = {
"NO_FILE"
:
"No such file:
%(path)
s"
,
"NO_FILE"
:
"No such file:
%(path)
s"
,
"NO_RESOURCE"
:
"No path to:
%(path)
s"
,
"NO_RESOURCE"
:
"No path to:
%(path)
s"
,
# ResourceInvalid
"WRONG_TYPE"
:
"Resource is not the type that was expected:
%(path)
s"
,
# SystemError
# SystemError
"OS_ERROR"
:
"Non specific OS error:
%(path)
s"
,
"OS_ERROR"
:
"Non specific OS error:
%(path)
s"
,
}
}
...
@@ -78,6 +81,7 @@ class PathError(FSError): pass
...
@@ -78,6 +81,7 @@ class PathError(FSError): pass
class
ResourceLockedError
(
FSError
):
pass
class
ResourceLockedError
(
FSError
):
pass
class
ResourceNotFoundError
(
FSError
):
pass
class
ResourceNotFoundError
(
FSError
):
pass
class
SystemError
(
FSError
):
pass
class
SystemError
(
FSError
):
pass
class
ResourceInvalid
(
FSError
):
pass
class
NullFile
(
object
):
class
NullFile
(
object
):
...
@@ -549,13 +553,13 @@ class SubFS(FS):
...
@@ -549,13 +553,13 @@ class SubFS(FS):
def
makedir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
def
makedir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
return
self
.
parent
.
makedir
(
self
.
_delegate
(
path
),
mode
=
mode
,
recursive
=
Fals
e
)
return
self
.
parent
.
makedir
(
self
.
_delegate
(
path
),
mode
=
mode
,
recursive
=
recursiv
e
)
def
remove
(
self
,
path
):
def
remove
(
self
,
path
):
return
self
.
parent
.
remove
(
self
.
_delegate
(
path
))
return
self
.
parent
.
remove
(
self
.
_delegate
(
path
))
def
removedir
(
self
,
path
,
recursive
=
False
):
def
removedir
(
self
,
path
,
recursive
=
False
):
self
.
parent
.
removedir
(
self
.
_delegate
(
path
),
recursive
=
Fals
e
)
self
.
parent
.
removedir
(
self
.
_delegate
(
path
),
recursive
=
recursiv
e
)
def
getinfo
(
self
,
path
):
def
getinfo
(
self
,
path
):
return
self
.
parent
.
getinfo
(
self
.
_delegate
(
path
))
return
self
.
parent
.
getinfo
(
self
.
_delegate
(
path
))
...
...
fs/memoryfs.py
View file @
44ecace3
...
@@ -343,6 +343,56 @@ class MemoryFS(FS):
...
@@ -343,6 +343,56 @@ class MemoryFS(FS):
finally
:
finally
:
self
.
_lock
.
release
()
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
):
def
_on_close_memory_file
(
self
,
path
,
value
):
self
.
_lock
.
acquire
()
self
.
_lock
.
acquire
()
try
:
try
:
...
...
fs/osfs.py
View file @
44ecace3
...
@@ -75,7 +75,6 @@ class OSFS(FS):
...
@@ -75,7 +75,6 @@ class OSFS(FS):
except
OSError
,
e
:
except
OSError
,
e
:
raise
OperationFailedError
(
"REMOVE_FAILED"
,
path
,
details
=
e
)
raise
OperationFailedError
(
"REMOVE_FAILED"
,
path
,
details
=
e
)
def
removedir
(
self
,
path
,
recursive
=
False
):
def
removedir
(
self
,
path
,
recursive
=
False
):
sys_path
=
self
.
getsyspath
(
path
)
sys_path
=
self
.
getsyspath
(
path
)
...
...
fs/tests.py
View file @
44ecace3
...
@@ -7,7 +7,6 @@ import shutil
...
@@ -7,7 +7,6 @@ import shutil
class
TestHelpers
(
unittest
.
TestCase
):
class
TestHelpers
(
unittest
.
TestCase
):
def
test_isabsolutepath
(
self
):
def
test_isabsolutepath
(
self
):
"""fs.isabsolutepath tests"""
tests
=
[
(
''
,
False
),
tests
=
[
(
''
,
False
),
(
'/'
,
True
),
(
'/'
,
True
),
(
'/A/B'
,
True
),
(
'/A/B'
,
True
),
...
@@ -18,7 +17,6 @@ class TestHelpers(unittest.TestCase):
...
@@ -18,7 +17,6 @@ class TestHelpers(unittest.TestCase):
self
.
assertEqual
(
fs
.
isabsolutepath
(
path
),
result
)
self
.
assertEqual
(
fs
.
isabsolutepath
(
path
),
result
)
def
test_normpath
(
self
):
def
test_normpath
(
self
):
"""fs.normpath tests"""
tests
=
[
(
"
\\
a
\\
b
\\
c"
,
"/a/b/c"
),
tests
=
[
(
"
\\
a
\\
b
\\
c"
,
"/a/b/c"
),
(
""
,
""
),
(
""
,
""
),
(
"/a/b/c"
,
"/a/b/c"
),
(
"/a/b/c"
,
"/a/b/c"
),
...
@@ -27,7 +25,6 @@ class TestHelpers(unittest.TestCase):
...
@@ -27,7 +25,6 @@ class TestHelpers(unittest.TestCase):
self
.
assertEqual
(
fs
.
normpath
(
path
),
result
)
self
.
assertEqual
(
fs
.
normpath
(
path
),
result
)
def
test_pathjon
(
self
):
def
test_pathjon
(
self
):
"""fs.pathjoin tests"""
tests
=
[
(
""
,
"a"
,
"a"
),
tests
=
[
(
""
,
"a"
,
"a"
),
(
"a"
,
"a"
,
"a/a"
),
(
"a"
,
"a"
,
"a/a"
),
(
"a/b"
,
"../c"
,
"a/c"
),
(
"a/b"
,
"../c"
,
"a/c"
),
...
@@ -55,7 +52,6 @@ class TestHelpers(unittest.TestCase):
...
@@ -55,7 +52,6 @@ class TestHelpers(unittest.TestCase):
self
.
assertRaises
(
fs
.
PathError
,
fs
.
pathjoin
,
"a/b/../../../d"
)
self
.
assertRaises
(
fs
.
PathError
,
fs
.
pathjoin
,
"a/b/../../../d"
)
def
test_makerelative
(
self
):
def
test_makerelative
(
self
):
"""fs.makerelative tests"""
tests
=
[
(
"/a/b"
,
"a/b"
),
tests
=
[
(
"/a/b"
,
"a/b"
),
(
"a/b"
,
"a/b"
),
(
"a/b"
,
"a/b"
),
(
"/"
,
""
)
]
(
"/"
,
""
)
]
...
@@ -65,7 +61,6 @@ class TestHelpers(unittest.TestCase):
...
@@ -65,7 +61,6 @@ class TestHelpers(unittest.TestCase):
self
.
assertEqual
(
fs
.
makerelative
(
path
),
result
)
self
.
assertEqual
(
fs
.
makerelative
(
path
),
result
)
def
test_makeabsolute
(
self
):
def
test_makeabsolute
(
self
):
"""fs.makeabsolute tests"""
tests
=
[
(
"/a/b"
,
"/a/b"
),
tests
=
[
(
"/a/b"
,
"/a/b"
),
(
"a/b"
,
"/a/b"
),
(
"a/b"
,
"/a/b"
),
(
"/"
,
"/"
)
]
(
"/"
,
"/"
)
]
...
@@ -74,7 +69,6 @@ class TestHelpers(unittest.TestCase):
...
@@ -74,7 +69,6 @@ class TestHelpers(unittest.TestCase):
self
.
assertEqual
(
fs
.
makeabsolute
(
path
),
result
)
self
.
assertEqual
(
fs
.
makeabsolute
(
path
),
result
)
def
test_iteratepath
(
self
):
def
test_iteratepath
(
self
):
"""fs.iteratepath tests"""
tests
=
[
(
"a/b"
,
[
"a"
,
"b"
]),
tests
=
[
(
"a/b"
,
[
"a"
,
"b"
]),
(
""
,
[]
),
(
""
,
[]
),
(
"aaa/bbb/ccc"
,
[
"aaa"
,
"bbb"
,
"ccc"
]),
(
"aaa/bbb/ccc"
,
[
"aaa"
,
"bbb"
,
"ccc"
]),
...
@@ -89,7 +83,6 @@ class TestHelpers(unittest.TestCase):
...
@@ -89,7 +83,6 @@ class TestHelpers(unittest.TestCase):
self
.
assertEqual
(
list
(
fs
.
_iteratepath
(
"a/b/c/d"
,
2
)),
[
"a"
,
"b"
,
"c/d"
])
self
.
assertEqual
(
list
(
fs
.
_iteratepath
(
"a/b/c/d"
,
2
)),
[
"a"
,
"b"
,
"c/d"
])
def
test_pathsplit
(
self
):
def
test_pathsplit
(
self
):
"""fs.pathsplit tests"""
tests
=
[
(
"a/b"
,
(
"a"
,
"b"
)),
tests
=
[
(
"a/b"
,
(
"a"
,
"b"
)),
(
"a/b/c"
,
(
"a/b"
,
"c"
)),
(
"a/b/c"
,
(
"a/b"
,
"c"
)),
(
"a"
,
(
""
,
"a"
)),
(
"a"
,
(
""
,
"a"
)),
...
@@ -107,7 +100,6 @@ import objecttree
...
@@ -107,7 +100,6 @@ import objecttree
class
TestObjectTree
(
unittest
.
TestCase
):
class
TestObjectTree
(
unittest
.
TestCase
):
def
test_getset
(
self
):
def
test_getset
(
self
):
"""objecttree.ObjectTree tests"""
ot
=
objecttree
.
ObjectTree
()
ot
=
objecttree
.
ObjectTree
()
ot
[
'foo'
]
=
"bar"
ot
[
'foo'
]
=
"bar"
self
.
assertEqual
(
ot
[
'foo'
],
'bar'
)
self
.
assertEqual
(
ot
[
'foo'
],
'bar'
)
...
@@ -145,23 +137,20 @@ import tempfile
...
@@ -145,23 +137,20 @@ import tempfile
import
osfs
import
osfs
import
os
import
os
class
TestFS
(
unittest
.
TestCase
):
class
Test
OS
FS
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
temp_dir
=
tempfile
.
mkdtemp
(
"fstest"
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
"fstest"
)
self
.
fs
=
osfs
.
OSFS
(
self
.
temp_dir
)
self
.
fs
=
osfs
.
OSFS
(
self
.
temp_dir
)
print
"Temp dir is"
,
self
.
temp_dir
print
"Temp dir is"
,
self
.
temp_dir
def
tearDown
(
self
):
def
tearDown
(
self
):
assert
"fstest"
in
self
.
temp_dir
shutil
.
rmtree
(
self
.
temp_dir
)
shutil
.
rmtree
(
self
.
temp_dir
)
def
check
(
self
,
p
):
def
check
(
self
,
p
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
temp_dir
,
p
))
return
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
temp_dir
,
p
))
def
test_makedir
(
self
):
def
test_makedir
(
self
):
"""osfs.makedir tests"""
check
=
self
.
check
check
=
self
.
check
self
.
fs
.
makedir
(
"a"
)
self
.
fs
.
makedir
(
"a"
)
...
@@ -179,7 +168,6 @@ class TestFS(unittest.TestCase):
...
@@ -179,7 +168,6 @@ class TestFS(unittest.TestCase):
def
test_removedir
(
self
):
def
test_removedir
(
self
):
"""osfs.removedir tests"""
check
=
self
.
check
check
=
self
.
check
self
.
fs
.
makedir
(
"a"
)
self
.
fs
.
makedir
(
"a"
)
self
.
assert_
(
check
(
"a"
))
self
.
assert_
(
check
(
"a"
))
...
@@ -201,13 +189,41 @@ class TestFS(unittest.TestCase):
...
@@ -201,13 +189,41 @@ class TestFS(unittest.TestCase):
self
.
assert_
(
not
check
(
"foo"
))
self
.
assert_
(
not
check
(
"foo"
))
def
test_rename
(
self
):
def
test_rename
(
self
):
"""osfs.rename tests"""
check
=
self
.
check
check
=
self
.
check
self
.
fs
.
open
(
"foo.txt"
,
'wt'
)
.
write
(
"Hello, World!"
)
self
.
fs
.
open
(
"foo.txt"
,
'wt'
)
.
write
(
"Hello, World!"
)
self
.
assert_
(
check
(
"foo.txt"
))
self
.
assert_
(
check
(
"foo.txt"
))
self
.
fs
.
rename
(
"foo.txt"
,
"bar.txt"
)
self
.
fs
.
rename
(
"foo.txt"
,
"bar.txt"
)
self
.
assert_
(
check
(
"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__"
:
if
__name__
==
"__main__"
:
#t = TestFS()
#t = TestFS()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment