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
b379d4c1
Commit
b379d4c1
authored
Sep 18, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more zipfs tests, and fixed a few issues
parent
45fbe7c8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
10 deletions
+93
-10
fs/fs.py
+5
-1
fs/helpers.py
+8
-8
fs/osfs.py
+3
-0
fs/tests.py
+76
-0
fs/zipfs.py
+1
-1
No files found.
fs/fs.py
View file @
b379d4c1
...
@@ -77,7 +77,11 @@ class FSError(Exception):
...
@@ -77,7 +77,11 @@ class FSError(Exception):
self
.
details
=
details
self
.
details
=
details
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
details
is
None
:
msg
=
self
.
msg
%
dict
((
k
,
str
(
v
))
for
k
,
v
in
self
.
__dict__
.
iteritems
())
msg
=
self
.
msg
%
dict
((
k
,
str
(
v
))
for
k
,
v
in
self
.
__dict__
.
iteritems
())
else
:
msg
=
self
.
msg
%
dict
((
k
,
str
(
v
))
for
k
,
v
in
self
.
__dict__
.
iteritems
())
msg
+=
", "
+
str
(
self
.
details
)
return
'
%
s.
%
s'
%
(
self
.
code
,
msg
)
return
'
%
s.
%
s'
%
(
self
.
code
,
msg
)
...
@@ -516,7 +520,7 @@ class FS(object):
...
@@ -516,7 +520,7 @@ class FS(object):
"""
"""
if
self
.
isdir
(
dst
):
if
self
.
isdir
(
dst
):
dst
=
pathjoin
(
getroot
(
dst
),
get
resourcename
(
src
)
)
dst
=
pathjoin
(
dirname
(
dst
),
resourcename
(
src
)
)
if
not
self
.
isfile
(
src
):
if
not
self
.
isfile
(
src
):
raise
ResourceInvalid
(
"WRONG_TYPE"
,
src
,
msg
=
"Source is not a file:
%(path)
s"
)
raise
ResourceInvalid
(
"WRONG_TYPE"
,
src
,
msg
=
"Source is not a file:
%(path)
s"
)
...
...
fs/helpers.py
View file @
b379d4c1
...
@@ -82,23 +82,23 @@ def pathsplit(path):
...
@@ -82,23 +82,23 @@ def pathsplit(path):
return
(
''
,
split
[
0
])
return
(
''
,
split
[
0
])
return
tuple
(
split
)
return
tuple
(
split
)
def
getroot
(
path
):
def
dirname
(
path
):
"""Returns the
roo
t directory of a path.
"""Returns the
paren
t directory of a path.
path -- A path
path -- A
FS
path
>>>
getroot
('foo/bar/baz')
>>>
dirname
('foo/bar/baz')
'foo/bar'
'foo/bar'
"""
"""
return
pathsplit
(
path
)[
0
]
return
pathsplit
(
path
)[
0
]
def
get
resourcename
(
path
):
def
resourcename
(
path
):
"""Returns the resource references by a path.
"""Returns the resource references by a path.
path -- A path
path -- A
FS
path
>>>
get
resourcename('foo/bar/baz')
>>> resourcename('foo/bar/baz')
'baz'
'baz'
"""
"""
...
@@ -154,4 +154,4 @@ def issamedir(path1, path2):
...
@@ -154,4 +154,4 @@ def issamedir(path1, path2):
>>> issamedir("foo/bar/baz/txt", "spam/eggs/spam.txt")
>>> issamedir("foo/bar/baz/txt", "spam/eggs/spam.txt")
False
False
"""
"""
return
pathsplit
(
path1
)[
0
]
==
pathsplit
(
path2
)[
0
]
return
pathsplit
(
resolvepath
(
path1
))[
0
]
==
pathsplit
(
resolvepath
(
path2
)
)[
0
]
fs/osfs.py
View file @
b379d4c1
...
@@ -74,6 +74,9 @@ class OSFS(FS):
...
@@ -74,6 +74,9 @@ class OSFS(FS):
else
:
else
:
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
except
OSError
,
e
:
except
OSError
,
e
:
if
e
.
errno
==
17
:
return
else
:
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
,
details
=
e
)
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
,
details
=
e
)
def
remove
(
self
,
path
):
def
remove
(
self
,
path
):
...
...
fs/tests.py
View file @
b379d4c1
...
@@ -522,6 +522,13 @@ class TestReadZipFS(unittest.TestCase):
...
@@ -522,6 +522,13 @@ class TestReadZipFS(unittest.TestCase):
check_contents
(
"1.txt"
,
"1"
)
check_contents
(
"1.txt"
,
"1"
)
check_contents
(
"foo/bar/baz.txt"
,
"baz"
)
check_contents
(
"foo/bar/baz.txt"
,
"baz"
)
def
test_is
(
self
):
self
.
assert_
(
self
.
fs
.
isfile
(
'a.txt'
))
self
.
assert_
(
self
.
fs
.
isfile
(
'1.txt'
))
self
.
assert_
(
self
.
fs
.
isfile
(
'foo/bar/baz.txt'
))
self
.
assert_
(
self
.
fs
.
isdir
(
'foo'
))
self
.
assert_
(
self
.
fs
.
isdir
(
'foo/bar'
))
def
test_listdir
(
self
):
def
test_listdir
(
self
):
def
check_listing
(
path
,
expected
):
def
check_listing
(
path
,
expected
):
...
@@ -531,6 +538,75 @@ class TestReadZipFS(unittest.TestCase):
...
@@ -531,6 +538,75 @@ class TestReadZipFS(unittest.TestCase):
check_listing
(
'foo'
,
[
'second.txt'
,
'bar'
])
check_listing
(
'foo'
,
[
'second.txt'
,
'bar'
])
check_listing
(
'foo/bar'
,
[
'baz.txt'
])
check_listing
(
'foo/bar'
,
[
'baz.txt'
])
class
TestWriteZipFS
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
temp_filename
=
""
.
join
(
random
.
choice
(
"abcdefghijklmnopqrstuvwxyz"
)
for
_
in
range
(
6
))
+
".zip"
self
.
temp_filename
=
os
.
path
.
abspath
(
self
.
temp_filename
)
zip_fs
=
zipfs
.
ZipFS
(
self
.
temp_filename
,
'w'
)
def
makefile
(
filename
,
contents
):
if
dirname
(
filename
):
zip_fs
.
makedir
(
dirname
(
filename
),
recursive
=
True
,
allow_recreate
=
True
)
f
=
zip_fs
.
open
(
filename
,
'w'
)
f
.
write
(
contents
)
f
.
close
()
makefile
(
"a.txt"
,
"Hello, World!"
)
makefile
(
"b.txt"
,
"b"
)
makefile
(
"foo/bar/baz.txt"
,
"baz"
)
makefile
(
"foo/second.txt"
,
"hai"
)
zip_fs
.
close
()
def
tearDown
(
self
):
os
.
remove
(
self
.
temp_filename
)
def
test_valid
(
self
):
zf
=
zipfile
.
ZipFile
(
self
.
temp_filename
,
"r"
)
self
.
assert_
(
zf
.
testzip
()
is
None
)
zf
.
close
()
def
test_creation
(
self
):
zf
=
zipfile
.
ZipFile
(
self
.
temp_filename
,
"r"
)
def
check_contents
(
filename
,
contents
):
zcontents
=
zf
.
read
(
filename
)
self
.
assertEqual
(
contents
,
zcontents
)
check_contents
(
"a.txt"
,
"Hello, World!"
)
check_contents
(
"b.txt"
,
"b"
)
check_contents
(
"foo/bar/baz.txt"
,
"baz"
)
check_contents
(
"foo/second.txt"
,
"hai"
)
class
TestAppendZipFS
(
TestWriteZipFS
):
def
setUp
(
self
):
self
.
temp_filename
=
""
.
join
(
random
.
choice
(
"abcdefghijklmnopqrstuvwxyz"
)
for
_
in
range
(
6
))
+
".zip"
self
.
temp_filename
=
os
.
path
.
abspath
(
self
.
temp_filename
)
zip_fs
=
zipfs
.
ZipFS
(
self
.
temp_filename
,
'w'
)
def
makefile
(
filename
,
contents
):
if
dirname
(
filename
):
zip_fs
.
makedir
(
dirname
(
filename
),
recursive
=
True
,
allow_recreate
=
True
)
f
=
zip_fs
.
open
(
filename
,
'w'
)
f
.
write
(
contents
)
f
.
close
()
makefile
(
"a.txt"
,
"Hello, World!"
)
makefile
(
"b.txt"
,
"b"
)
zip_fs
.
close
()
zip_fs
=
zipfs
.
ZipFS
(
self
.
temp_filename
,
'a'
)
makefile
(
"foo/bar/baz.txt"
,
"baz"
)
makefile
(
"foo/second.txt"
,
"hai"
)
zip_fs
.
close
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
#t = TestFS()
#t = TestFS()
#t.setUp()
#t.setUp()
...
...
fs/zipfs.py
View file @
b379d4c1
...
@@ -179,7 +179,7 @@ class ZipFS(FS):
...
@@ -179,7 +179,7 @@ class ZipFS(FS):
return
self
.
_path_fs
.
isdir
(
path
)
return
self
.
_path_fs
.
isdir
(
path
)
def
isfile
(
self
,
path
):
def
isfile
(
self
,
path
):
return
self
.
_path_fs
.
is
dir
(
path
)
return
self
.
_path_fs
.
is
file
(
path
)
def
exists
(
self
,
path
):
def
exists
(
self
,
path
):
return
self
.
_path_fs
.
exists
(
path
)
return
self
.
_path_fs
.
exists
(
path
)
...
...
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