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
3aa1997b
Commit
3aa1997b
authored
Aug 19, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fleshing out the test suite. Also changed fs.mkdir to fs.makedir, for sake of consistancy...
parent
f24a6884
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
23 deletions
+103
-23
fs/fs.py
+10
-4
fs/memoryfs.py
+4
-4
fs/mountfs.py
+2
-2
fs/multifs.py
+3
-3
fs/osfs.py
+14
-8
fs/tests.py
+70
-2
No files found.
fs/fs.py
View file @
3aa1997b
...
@@ -37,6 +37,9 @@ error_msgs = {
...
@@ -37,6 +37,9 @@ error_msgs = {
"NO_DIR"
:
"Directory does not exist:
%(path)
s"
,
"NO_DIR"
:
"Directory does not exist:
%(path)
s"
,
"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"
,
# SystemError
"OS_ERROR"
:
"Non specific OS error:
%(path)
s"
,
}
}
error_codes
=
error_msgs
.
keys
()
error_codes
=
error_msgs
.
keys
()
...
@@ -83,6 +86,9 @@ class ResourceLockedError(FSError):
...
@@ -83,6 +86,9 @@ class ResourceLockedError(FSError):
class
ResourceNotFoundError
(
FSError
):
class
ResourceNotFoundError
(
FSError
):
pass
pass
class
SystemError
(
FSError
):
pass
class
NullFile
(
object
):
class
NullFile
(
object
):
...
@@ -283,7 +289,7 @@ class FS(object):
...
@@ -283,7 +289,7 @@ class FS(object):
def
listdir
(
self
,
path
=
"./"
,
wildcard
=
None
,
full
=
False
,
absolute
=
False
,
hidden
=
False
,
dirs_only
=
False
,
files_only
=
False
):
def
listdir
(
self
,
path
=
"./"
,
wildcard
=
None
,
full
=
False
,
absolute
=
False
,
hidden
=
False
,
dirs_only
=
False
,
files_only
=
False
):
raise
UnsupportedError
(
"UNSUPPORTED"
)
raise
UnsupportedError
(
"UNSUPPORTED"
)
def
m
k
dir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
def
m
ake
dir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
raise
UnsupportedError
(
"UNSUPPORTED"
)
raise
UnsupportedError
(
"UNSUPPORTED"
)
def
remove
(
self
,
path
):
def
remove
(
self
,
path
):
...
@@ -456,8 +462,8 @@ class SubFS(FS):
...
@@ -456,8 +462,8 @@ class SubFS(FS):
return
paths
return
paths
def
m
k
dir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
def
m
ake
dir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
return
self
.
parent
.
m
k
dir
(
self
.
_delegate
(
path
),
mode
=
mode
,
recursive
=
False
)
return
self
.
parent
.
m
ake
dir
(
self
.
_delegate
(
path
),
mode
=
mode
,
recursive
=
False
)
def
remove
(
self
,
path
):
def
remove
(
self
,
path
):
return
self
.
parent
.
remove
(
self
.
_delegate
(
path
))
return
self
.
parent
.
remove
(
self
.
_delegate
(
path
))
...
@@ -484,7 +490,7 @@ def validatefs(fs):
...
@@ -484,7 +490,7 @@ def validatefs(fs):
"isfile"
,
"isfile"
,
"ishidden"
,
"ishidden"
,
"listdir"
,
"listdir"
,
"m
k
dir"
,
"m
ake
dir"
,
"remove"
,
"remove"
,
"removedir"
,
"removedir"
,
"getinfo"
,
"getinfo"
,
...
...
fs/memoryfs.py
View file @
3aa1997b
...
@@ -186,7 +186,7 @@ class MemoryFS(FS):
...
@@ -186,7 +186,7 @@ class MemoryFS(FS):
def
exists
(
self
,
path
):
def
exists
(
self
,
path
):
return
self
.
_get_dir_entry
(
path
)
is
not
None
return
self
.
_get_dir_entry
(
path
)
is
not
None
def
m
k
dir
(
self
,
dirname
,
mode
=
0777
,
recursive
=
False
,
allow_recreate
=
False
):
def
m
ake
dir
(
self
,
dirname
,
mode
=
0777
,
recursive
=
False
,
allow_recreate
=
False
):
fullpath
=
dirname
fullpath
=
dirname
dirpath
,
dirname
=
pathsplit
(
dirname
)
dirpath
,
dirname
=
pathsplit
(
dirname
)
...
@@ -340,9 +340,9 @@ class MemoryFS(FS):
...
@@ -340,9 +340,9 @@ class MemoryFS(FS):
def
main
():
def
main
():
mem_fs
=
MemoryFS
()
mem_fs
=
MemoryFS
()
mem_fs
.
m
k
dir
(
'test/test2'
,
recursive
=
True
)
mem_fs
.
m
ake
dir
(
'test/test2'
,
recursive
=
True
)
mem_fs
.
m
k
dir
(
'test/A'
,
recursive
=
True
)
mem_fs
.
m
ake
dir
(
'test/A'
,
recursive
=
True
)
mem_fs
.
m
k
dir
(
'test/A/B'
,
recursive
=
True
)
mem_fs
.
m
ake
dir
(
'test/A/B'
,
recursive
=
True
)
...
...
fs/mountfs.py
View file @
3aa1997b
...
@@ -327,7 +327,7 @@ class MountFS(FS):
...
@@ -327,7 +327,7 @@ class MountFS(FS):
# return paths
# return paths
#
#
# def mount(self, name, path, fs):
# def mount(self, name, path, fs):
# self.mem_fs.m
k
dir(path, recursive=True)
# self.mem_fs.m
ake
dir(path, recursive=True)
# mount_filename = pathjoin(path, '.mount')
# mount_filename = pathjoin(path, '.mount')
# mount = self.mem_fs.open(mount_filename, 'w')
# mount = self.mem_fs.open(mount_filename, 'w')
# mount.name = name
# mount.name = name
...
@@ -338,7 +338,7 @@ class MountFS(FS):
...
@@ -338,7 +338,7 @@ class MountFS(FS):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
fs1
=
MemoryFS
()
fs1
=
MemoryFS
()
fs1
.
m
k
dir
(
"Memroot/B/C/D"
,
recursive
=
True
)
fs1
.
m
ake
dir
(
"Memroot/B/C/D"
,
recursive
=
True
)
fs1
.
open
(
"test.txt"
,
'w'
)
.
write
(
"Hello, World!"
)
fs1
.
open
(
"test.txt"
,
'w'
)
.
write
(
"Hello, World!"
)
#print_fs(fs1)
#print_fs(fs1)
...
...
fs/multifs.py
View file @
3aa1997b
...
@@ -140,9 +140,9 @@ if __name__ == "__main__":
...
@@ -140,9 +140,9 @@ if __name__ == "__main__":
import
memoryfs
import
memoryfs
mem_fs
=
memoryfs
.
MemoryFS
()
mem_fs
=
memoryfs
.
MemoryFS
()
mem_fs
.
m
k
dir
(
'projects/test2'
,
recursive
=
True
)
mem_fs
.
m
ake
dir
(
'projects/test2'
,
recursive
=
True
)
mem_fs
.
m
k
dir
(
'projects/A'
,
recursive
=
True
)
mem_fs
.
m
ake
dir
(
'projects/A'
,
recursive
=
True
)
mem_fs
.
m
k
dir
(
'projects/A/B'
,
recursive
=
True
)
mem_fs
.
m
ake
dir
(
'projects/A/B'
,
recursive
=
True
)
mem_fs
.
open
(
"projects/test2/readme.txt"
,
'w'
)
.
write
(
"Hello, World!"
)
mem_fs
.
open
(
"projects/test2/readme.txt"
,
'w'
)
.
write
(
"Hello, World!"
)
...
...
fs/osfs.py
View file @
3aa1997b
...
@@ -53,14 +53,19 @@ class OSFS(FS):
...
@@ -53,14 +53,19 @@ class OSFS(FS):
return
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
return
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
)
def
m
k
dir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
def
m
ake
dir
(
self
,
path
,
mode
=
0777
,
recursive
=
False
):
sys_path
=
self
.
getsyspath
(
path
)
sys_path
=
self
.
getsyspath
(
path
)
if
recursive
:
try
:
os
.
makedirs
(
sys_path
,
mode
)
if
recursive
:
else
:
os
.
makedirs
(
sys_path
,
mode
)
os
.
makedir
(
sys_path
,
mode
)
else
:
try
:
os
.
mkdir
(
sys_path
,
mode
)
except
OSError
,
e
:
raise
FSError
(
"NO_DIR"
,
sys_path
)
except
OSError
,
e
:
raise
FSError
(
"OS_ERROR"
,
sys_path
,
details
=
e
)
def
remove
(
self
,
path
):
def
remove
(
self
,
path
):
sys_path
=
self
.
getsyspath
(
path
)
sys_path
=
self
.
getsyspath
(
path
)
...
@@ -75,12 +80,12 @@ class OSFS(FS):
...
@@ -75,12 +80,12 @@ class OSFS(FS):
if
recursive
:
if
recursive
:
try
:
try
:
os
.
r
mdir
(
sys_path
)
os
.
r
emovedirs
(
sys_path
)
except
OSError
,
e
:
except
OSError
,
e
:
raise
OperationFailedError
(
"REMOVEDIR_FAILED"
,
path
,
details
=
e
)
raise
OperationFailedError
(
"REMOVEDIR_FAILED"
,
path
,
details
=
e
)
else
:
else
:
try
:
try
:
os
.
r
emovedirs
(
sys_path
)
os
.
r
mdir
(
sys_path
)
except
OSError
,
e
:
except
OSError
,
e
:
raise
OperationFailedError
(
"REMOVEDIR_FAILED"
,
path
,
details
=
e
)
raise
OperationFailedError
(
"REMOVEDIR_FAILED"
,
path
,
details
=
e
)
...
@@ -131,6 +136,7 @@ class OSFS(FS):
...
@@ -131,6 +136,7 @@ class OSFS(FS):
return
stats
.
st_size
return
stats
.
st_size
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
osfs
=
OSFS
(
"~/projects"
)
osfs
=
OSFS
(
"~/projects"
)
...
...
fs/tests.py
View file @
3aa1997b
...
@@ -93,6 +93,74 @@ class TestHelpers(unittest.TestCase):
...
@@ -93,6 +93,74 @@ class TestHelpers(unittest.TestCase):
for
path
,
result
in
tests
:
for
path
,
result
in
tests
:
self
.
assertEqual
(
fs
.
pathsplit
(
path
),
result
)
self
.
assertEqual
(
fs
.
pathsplit
(
path
),
result
)
import
tempfile
import
osfs
import
os
class
TestFS
(
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
for
root
,
dirs
,
files
in
os
.
walk
(
self
.
temp_dir
,
topdown
=
False
):
for
f
in
files
:
os
.
remove
(
os
.
path
.
join
(
root
,
f
))
for
d
in
dirs
:
os
.
rmdir
(
os
.
path
.
join
(
root
,
d
))
os
.
removedirs
(
self
.
temp_dir
)
def
check
(
self
,
p
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
temp_dir
,
p
))
def
test_makedir
(
self
):
check
=
self
.
check
self
.
fs
.
makedir
(
"a"
)
self
.
assert_
(
check
(
"a"
))
self
.
assertRaises
(
fs
.
FSError
,
self
.
fs
.
makedir
,
"a/b/c"
)
self
.
fs
.
makedir
(
"a/b/c"
,
recursive
=
True
)
self
.
assert_
(
check
(
"a/b/c"
))
self
.
fs
.
makedir
(
"foo/bar/baz"
,
recursive
=
True
)
self
.
assert_
(
check
(
"foo/bar/baz"
))
self
.
fs
.
makedir
(
"a/b/child"
)
self
.
assert_
(
check
(
"a/b/child"
))
def
test_removedir
(
self
):
check
=
self
.
check
self
.
fs
.
makedir
(
"a"
)
self
.
assert_
(
check
(
"a"
))
self
.
fs
.
removedir
(
"a"
)
self
.
assert_
(
not
check
(
"a"
))
self
.
fs
.
makedir
(
"a/b/c/d"
,
recursive
=
True
)
self
.
assertRaises
(
fs
.
FSError
,
self
.
fs
.
removedir
,
"a/b"
)
self
.
fs
.
removedir
(
"a/b/c/d"
)
self
.
assert_
(
not
check
(
"a/b/c/d"
))
self
.
fs
.
removedir
(
"a/b/c"
)
self
.
assert_
(
not
check
(
"a/b/c"
))
self
.
fs
.
removedir
(
"a/b"
)
self
.
assert_
(
not
check
(
"a/b"
))
self
.
fs
.
makedir
(
"foo/bar/baz"
,
recursive
=
True
)
self
.
fs
.
removedir
(
"foo/bar/baz"
,
recursive
=
True
)
self
.
assert_
(
not
check
(
"foo/bar/baz"
))
self
.
assert_
(
not
check
(
"foo/bar"
))
self
.
assert_
(
not
check
(
"foo"
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
#t = TestFS()
#t.setUp()
#t.tearDown()
import
nose
import
nose
nose
.
run
()
nose
.
main
()
\ No newline at end of file
\ No newline at end of file
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