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
b6db31f6
Commit
b6db31f6
authored
Sep 08, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress
parent
d6ec7a9d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
4 deletions
+34
-4
fs/memoryfs.py
+3
-0
fs/tempfs.py
+23
-4
fs/tests.py
+8
-0
No files found.
fs/memoryfs.py
View file @
b6db31f6
...
...
@@ -51,6 +51,9 @@ class MemoryFile(object):
assert
self
.
mem_file
is
not
None
,
"self.mem_file should have a value"
self
.
closed
=
False
def
__str__
(
self
):
return
"<MemoryFile in
%
s
%
s>"
%
(
self
.
memory_fs
,
self
.
path
)
def
__del__
(
self
):
if
not
self
.
closed
:
self
.
close
()
...
...
fs/tempfs.py
View file @
b6db31f6
...
...
@@ -9,14 +9,32 @@ class TempFS(OSFS):
"""Create a Filesystem in a tempory directory (with tempfile.mkdtemp),
and removes it when the TempFS object is cleaned up."""
def
__init__
(
self
):
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
"fstest"
)
def
__init__
(
self
,
identifier
=
None
):
"""Creates a temporary Filesystem
identifier -- A string that is included in the name of the temporary directory,
default uses "TempFS"
"""
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
identifier
or
"TempFS"
)
self
.
_cleaned
=
False
OSFS
.
__init__
(
self
,
self
.
_temp_dir
)
def
__str__
(
self
):
return
'<TempFS in "
%
s">'
%
self
.
_temp_dir
def
_cleanup
(
self
):
if
self
.
_temp_dir
:
"""Called by __del__ to remove the temporary directory. Can be called directly,
but it is probably not advisable."""
if
not
self
.
_cleaned
:
rmtree
(
self
.
_temp_dir
)
self
.
_
temp_dir
=
""
self
.
_
cleaned
=
True
def
__del__
(
self
):
self
.
_cleanup
()
if
__name__
==
"__main__"
:
tfs
=
TempFS
()
print
tfs
\ No newline at end of file
fs/tests.py
View file @
b6db31f6
...
...
@@ -150,6 +150,11 @@ class TestOSFS(unittest.TestCase):
def
check
(
self
,
p
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
temp_dir
,
makerelative
(
p
)))
def
test_debug
(
self
):
str
(
self
.
fs
)
repr
(
self
.
fs
)
self
.
assert_
(
hasattr
(
self
.
fs
,
'desc'
))
def
test_makedir
(
self
):
check
=
self
.
check
...
...
@@ -166,6 +171,8 @@ class TestOSFS(unittest.TestCase):
self
.
fs
.
makedir
(
"a/b/child"
)
self
.
assert_
(
check
(
"a/b/child"
))
self
.
fs
.
desc
(
"a"
)
self
.
fs
.
desc
(
"a/b/child"
)
def
test_removedir
(
self
):
check
=
self
.
check
...
...
@@ -247,6 +254,7 @@ class TestOSFS(unittest.TestCase):
f
.
close
()
info
=
self
.
fs
.
getinfo
(
"info.txt"
)
self
.
assertEqual
(
info
[
'size'
],
len
(
test_str
))
self
.
fs
.
desc
(
"info.txt"
)
def
test_getsize
(
self
):
test_str
=
"*"
*
23
...
...
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