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
dd808d70
Commit
dd808d70
authored
Apr 30, 2011
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented auto closing for multi/mount fs
parent
bdcfff98
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
4 deletions
+96
-4
fs/mountfs.py
+12
-3
fs/multifs.py
+20
-1
fs/tests/test_mountfs.py
+32
-0
fs/tests/test_multifs.py
+32
-0
No files found.
fs/mountfs.py
View file @
dd808d70
...
...
@@ -71,7 +71,6 @@ class FileMount(object):
class
MountFS
(
FS
):
"""A filesystem that delegates to other filesystems."""
_meta
=
{
'virtual'
:
True
,
'read_only'
:
False
,
'unicode_paths'
:
True
,
...
...
@@ -81,7 +80,8 @@ class MountFS(FS):
DirMount
=
DirMount
FileMount
=
FileMount
def
__init__
(
self
,
thread_synchronize
=
_thread_synchronize_default
):
def
__init__
(
self
,
auto_close
=
True
,
thread_synchronize
=
_thread_synchronize_default
):
self
.
auto_close
=
auto_close
super
(
MountFS
,
self
)
.
__init__
(
thread_synchronize
=
thread_synchronize
)
self
.
mount_tree
=
PathMap
()
...
...
@@ -121,6 +121,16 @@ class MountFS(FS):
else
:
return
self
,
"/"
,
path
@synchronize
def
close
(
self
):
# Explicitly closes children if requested
if
self
.
auto_close
:
for
mount
in
self
.
mount_tree
.
itervalues
():
mount
.
fs
.
close
()
# Free references (which may incidently call the close method of the child filesystems)
self
.
mount_tree
.
clear
()
super
(
MountFS
,
self
)
.
close
()
def
getsyspath
(
self
,
path
,
allow_none
=
False
):
fs
,
_mount_path
,
delegate_path
=
self
.
_delegate
(
path
)
if
fs
is
self
or
fs
is
None
:
...
...
@@ -341,7 +351,6 @@ class MountFS(FS):
if
object
is
None
:
raise
ResourceNotFoundError
(
src
)
# TODO!
raise
UnsupportedError
(
"rename resource"
,
path
=
src
)
@synchronize
...
...
fs/multifs.py
View file @
dd808d70
...
...
@@ -83,9 +83,15 @@ class MultiFS(FS):
'case_insensitive_paths'
:
False
}
def
__init__
(
self
):
def
__init__
(
self
,
auto_close
=
True
):
"""
:param auto_close: If True the child filesystems will be closed when the MultiFS is closed
"""
super
(
MultiFS
,
self
)
.
__init__
(
thread_synchronize
=
_thread_synchronize_default
)
self
.
auto_close
=
auto_close
self
.
fs_sequence
=
[]
self
.
fs_lookup
=
{}
self
.
write_fs
=
None
...
...
@@ -100,6 +106,19 @@ class MultiFS(FS):
def
__unicode__
(
self
):
return
u"<MultiFS:
%
s>"
%
", "
.
join
(
unicode
(
fs
)
for
fs
in
self
.
fs_sequence
)
@synchronize
def
close
(
self
):
# Explicitly close if requested
if
self
.
auto_close
:
for
fs
in
self
.
fs_sequence
:
fs
.
close
()
if
self
.
write_fs
is
not
None
:
self
.
write_fs
.
close
()
# Discard any references
del
self
.
fs_sequence
[:]
self
.
fs_lookup
.
clear
()
self
.
write_fs
=
None
super
(
MultiFS
,
self
)
.
close
()
@synchronize
def
addfs
(
self
,
name
,
fs
,
write
=
False
):
...
...
fs/tests/test_mountfs.py
0 → 100644
View file @
dd808d70
from
fs.mountfs
import
MountFS
from
fs.memoryfs
import
MemoryFS
import
unittest
class
TestMultiFS
(
unittest
.
TestCase
):
def
test_auto_close
(
self
):
"""Test MultiFS auto close is working"""
multi_fs
=
MountFS
()
m1
=
MemoryFS
()
m2
=
MemoryFS
()
multi_fs
.
mount
(
'/m1'
,
m1
)
multi_fs
.
mount
(
'/m2'
,
m2
)
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
multi_fs
.
close
()
self
.
assert_
(
m1
.
closed
)
self
.
assert_
(
m2
.
closed
)
def
test_no_auto_close
(
self
):
"""Test MultiFS auto close can be disabled"""
multi_fs
=
MountFS
(
auto_close
=
False
)
m1
=
MemoryFS
()
m2
=
MemoryFS
()
multi_fs
.
mount
(
'/m1'
,
m1
)
multi_fs
.
mount
(
'/m2'
,
m2
)
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
multi_fs
.
close
()
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
fs/tests/test_multifs.py
0 → 100644
View file @
dd808d70
from
fs.multifs
import
MultiFS
from
fs.memoryfs
import
MemoryFS
import
unittest
class
TestMultiFS
(
unittest
.
TestCase
):
def
test_auto_close
(
self
):
"""Test MultiFS auto close is working"""
multi_fs
=
MultiFS
()
m1
=
MemoryFS
()
m2
=
MemoryFS
()
multi_fs
.
addfs
(
'm1'
,
m1
)
multi_fs
.
addfs
(
'm2'
,
m2
)
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
multi_fs
.
close
()
self
.
assert_
(
m1
.
closed
)
self
.
assert_
(
m2
.
closed
)
def
test_no_auto_close
(
self
):
"""Test MultiFS auto close can be disables"""
multi_fs
=
MultiFS
(
auto_close
=
False
)
m1
=
MemoryFS
()
m2
=
MemoryFS
()
multi_fs
.
addfs
(
'm1'
,
m1
)
multi_fs
.
addfs
(
'm2'
,
m2
)
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
multi_fs
.
close
()
self
.
assert_
(
not
m1
.
closed
)
self
.
assert_
(
not
m2
.
closed
)
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