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
851fadda
Commit
851fadda
authored
Sep 20, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests now pass on Windows
parent
d6848353
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
36 deletions
+53
-36
fs/base.py
+25
-21
fs/osfs.py
+9
-2
fs/tempfs.py
+5
-4
fs/tests.py
+14
-9
No files found.
fs/base.py
View file @
851fadda
...
@@ -604,33 +604,37 @@ class FS(object):
...
@@ -604,33 +604,37 @@ class FS(object):
dst_syspath
=
self
.
getsyspath
(
dst
,
allow_none
=
True
)
dst_syspath
=
self
.
getsyspath
(
dst
,
allow_none
=
True
)
if
src_syspath
is
not
None
and
dst_syspath
is
not
None
:
if
src_syspath
is
not
None
and
dst_syspath
is
not
None
:
shutil
.
move
(
src_syspath
,
dst_syspath
)
try
:
else
:
shutil
.
move
(
src_syspath
,
dst_syspath
)
return
except
WindowsError
:
pass
def
movefile_noerrors
(
src
,
dst
):
def
movefile_noerrors
(
src
,
dst
):
try
:
try
:
return
self
.
move
(
src
,
dst
)
return
self
.
move
(
src
,
dst
)
except
FSError
:
except
FSError
:
return
return
if
ignore_errors
:
if
ignore_errors
:
movefile
=
movefile_noerrors
movefile
=
movefile_noerrors
else
:
else
:
movefile
=
self
.
move
movefile
=
self
.
move
self
.
makedir
(
dst
,
allow_recreate
=
True
)
self
.
makedir
(
dst
,
allow_recreate
=
True
)
for
dirname
,
filenames
in
self
.
walk
(
src
,
search
=
"depth"
):
for
dirname
,
filenames
in
self
.
walk
(
src
,
search
=
"depth"
):
dst_dirname
=
makerelative
(
dirname
[
len
(
src
):])
dst_dirname
=
makerelative
(
dirname
[
len
(
src
):])
dst_dirpath
=
pathjoin
(
dst
,
dst_dirname
)
dst_dirpath
=
pathjoin
(
dst
,
dst_dirname
)
self
.
makedir
(
dst_dirpath
,
allow_recreate
=
True
,
recursive
=
True
)
self
.
makedir
(
dst_dirpath
,
allow_recreate
=
True
,
recursive
=
True
)
for
filename
in
filenames
:
for
filename
in
filenames
:
src_filename
=
pathjoin
(
dirname
,
filename
)
src_filename
=
pathjoin
(
dirname
,
filename
)
dst_filename
=
pathjoin
(
dst_dirpath
,
filename
)
dst_filename
=
pathjoin
(
dst_dirpath
,
filename
)
movefile
(
src_filename
,
dst_filename
,
chunk_size
=
chunk_size
)
movefile
(
src_filename
,
dst_filename
,
chunk_size
=
chunk_size
)
self
.
removedir
(
dirname
)
self
.
removedir
(
dirname
)
...
...
fs/osfs.py
View file @
851fadda
...
@@ -28,7 +28,7 @@ class OSFS(FS):
...
@@ -28,7 +28,7 @@ class OSFS(FS):
__repr__
=
__str__
__repr__
=
__str__
def
getsyspath
(
self
,
path
,
allow_none
=
False
):
def
getsyspath
(
self
,
path
,
allow_none
=
False
):
sys_path
=
os
.
path
.
join
(
self
.
root_path
,
makerelative
(
self
.
_resolve
(
path
)))
sys_path
=
os
.
path
.
join
(
self
.
root_path
,
makerelative
(
self
.
_resolve
(
path
)))
.
replace
(
'/'
,
os
.
sep
)
return
sys_path
return
sys_path
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
...
@@ -77,10 +77,17 @@ class OSFS(FS):
...
@@ -77,10 +77,17 @@ class OSFS(FS):
os
.
mkdir
(
sys_path
,
mode
)
os
.
mkdir
(
sys_path
,
mode
)
except
OSError
,
e
:
except
OSError
,
e
:
if
allow_recreate
:
if
allow_recreate
:
if
e
.
errno
!=
17
:
if
e
.
errno
!=
17
:
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
else
:
else
:
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
except
WindowsError
,
e
:
if
allow_recreate
:
if
e
.
errno
!=
183
:
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
else
:
raise
OperationFailedError
(
"MAKEDIR_FAILED"
,
path
)
except
OSError
,
e
:
except
OSError
,
e
:
if
e
.
errno
==
17
:
if
e
.
errno
==
17
:
return
return
...
...
fs/tempfs.py
View file @
851fadda
...
@@ -28,9 +28,10 @@ class TempFS(OSFS):
...
@@ -28,9 +28,10 @@ class TempFS(OSFS):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
unicode
(
self
.
__str__
())
return
unicode
(
self
.
__str__
())
def
_cleanup
(
self
):
def
close
(
self
):
"""Called by __del__ to remove the temporary directory. Can be called directly,
"""Removes the temporary directory.
but it is probably not neccesary."""
This will be called automatically when the object is cleaned up by Python.
Note that once this method has been called, the FS object may no longer be used."""
if
not
self
.
_cleaned
:
if
not
self
.
_cleaned
:
self
.
_lock
.
acquire
()
self
.
_lock
.
acquire
()
...
@@ -41,7 +42,7 @@ class TempFS(OSFS):
...
@@ -41,7 +42,7 @@ class TempFS(OSFS):
self
.
_lock
.
release
()
self
.
_lock
.
release
()
def
__del__
(
self
):
def
__del__
(
self
):
self
.
_cleanup
()
self
.
close
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
fs/tests.py
View file @
851fadda
...
@@ -145,7 +145,7 @@ class TestOSFS(unittest.TestCase):
...
@@ -145,7 +145,7 @@ class TestOSFS(unittest.TestCase):
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
):
shutil
.
rmtree
(
self
.
temp_dir
)
shutil
.
rmtree
(
self
.
temp_dir
)
def
check
(
self
,
p
):
def
check
(
self
,
p
):
...
@@ -357,9 +357,13 @@ class TestOSFS(unittest.TestCase):
...
@@ -357,9 +357,13 @@ class TestOSFS(unittest.TestCase):
def
test_readwriteappendseek
(
self
):
def
test_readwriteappendseek
(
self
):
def
checkcontents
(
path
,
check_contents
):
def
checkcontents
(
path
,
check_contents
):
f
=
self
.
fs
.
open
(
path
,
"rb"
)
f
=
None
read_contents
=
f
.
read
()
try
:
f
.
close
()
f
=
self
.
fs
.
open
(
path
,
"rb"
)
read_contents
=
f
.
read
()
finally
:
if
f
is
not
None
:
f
.
close
()
return
read_contents
==
check_contents
return
read_contents
==
check_contents
test_strings
=
[
"Beautiful is better than ugly."
,
test_strings
=
[
"Beautiful is better than ugly."
,
"Explicit is better than implicit."
,
"Explicit is better than implicit."
,
...
@@ -390,15 +394,15 @@ class TestOSFS(unittest.TestCase):
...
@@ -390,15 +394,15 @@ class TestOSFS(unittest.TestCase):
f4
.
write
(
test_strings
[
2
])
f4
.
write
(
test_strings
[
2
])
f4
.
close
()
f4
.
close
()
self
.
assert_
(
checkcontents
(
"b.txt"
,
test_strings
[
2
]))
self
.
assert_
(
checkcontents
(
"b.txt"
,
test_strings
[
2
]))
f5
=
self
.
fs
.
open
(
"c.txt"
,
"w
t
"
)
f5
=
self
.
fs
.
open
(
"c.txt"
,
"w
b
"
)
for
s
in
test_strings
:
for
s
in
test_strings
:
f5
.
write
(
s
+
"
\n
"
)
f5
.
write
(
s
+
"
\n
"
)
f5
.
close
()
f5
.
close
()
f6
=
self
.
fs
.
open
(
"c.txt"
,
"r
t"
)
f6
=
self
.
fs
.
open
(
"c.txt"
,
"r
b"
)
for
s
,
t
in
zip
(
f6
,
test_strings
):
for
s
,
t
in
zip
(
f6
,
test_strings
):
self
.
assertEqual
(
s
,
t
+
"
\n
"
)
self
.
assertEqual
(
s
,
t
+
"
\n
"
)
f6
.
close
()
f6
.
close
()
f7
=
self
.
fs
.
open
(
"c.txt"
,
"r
t
"
)
f7
=
self
.
fs
.
open
(
"c.txt"
,
"r
b
"
)
f7
.
seek
(
13
)
f7
.
seek
(
13
)
word
=
f7
.
read
(
6
)
word
=
f7
.
read
(
6
)
self
.
assertEqual
(
word
,
"better"
)
self
.
assertEqual
(
word
,
"better"
)
...
@@ -409,7 +413,8 @@ class TestOSFS(unittest.TestCase):
...
@@ -409,7 +413,8 @@ class TestOSFS(unittest.TestCase):
word
=
f7
.
read
(
7
)
word
=
f7
.
read
(
7
)
self
.
assertEqual
(
word
,
"complex"
)
self
.
assertEqual
(
word
,
"complex"
)
f7
.
close
()
f7
.
close
()
self
.
assertEqual
(
self
.
fs
.
getcontents
(
"a.txt"
),
all_strings
)
self
.
assertEqual
(
self
.
fs
.
getcontents
(
"a.txt"
),
all_strings
)
class
TestSubFS
(
TestOSFS
):
class
TestSubFS
(
TestOSFS
):
...
@@ -466,7 +471,7 @@ class TestTempFS(TestOSFS):
...
@@ -466,7 +471,7 @@ class TestTempFS(TestOSFS):
def
tearDown
(
self
):
def
tearDown
(
self
):
td
=
self
.
fs
.
_temp_dir
td
=
self
.
fs
.
_temp_dir
del
self
.
fs
self
.
fs
.
close
()
self
.
assert_
(
not
os
.
path
.
exists
(
td
))
self
.
assert_
(
not
os
.
path
.
exists
(
td
))
def
check
(
self
,
p
):
def
check
(
self
,
p
):
...
...
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