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
315ea957
Commit
315ea957
authored
Jan 12, 2012
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a remove_all function to utils
parent
39ef2b67
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
13 deletions
+38
-13
ChangeLog
+1
-0
fs/tests/test_utils.py
+20
-13
fs/utils.py
+17
-0
No files found.
ChangeLog
View file @
315ea957
...
...
@@ -84,3 +84,4 @@
* Ported to Python 3.X
* Added a DeleteRootError to exceptions thrown when trying to delete '/'
* Added a remove_all function to utils
fs/tests/test_utils.py
View file @
315ea957
...
...
@@ -87,20 +87,27 @@ class TestUtils(unittest.TestCase):
utils
.
movedir
((
fs1
,
"from"
),
fs2
)
self
.
assert_
(
not
fs1
.
exists
(
"from"
))
self
.
_check_fs
(
fs2
)
if
__name__
==
"__main__"
:
def
_make_fs
(
fs
):
def
test_remove_all
(
self
)
:
"""Test remove_all function"""
fs
=
TempFS
()
fs
.
setcontents
(
"f1"
,
"file 1"
)
fs
.
setcontents
(
"f2"
,
"file 2"
)
fs
.
setcontents
(
"f3"
,
"file 3"
)
fs
.
makedir
(
"foo/bar"
,
recursive
=
True
)
fs
.
setcontents
(
"foo/bar/fruit"
,
"apple"
)
fs
.
setcontents
(
"foo/bar/fruit"
,
"apple"
)
fs
.
setcontents
(
"foo/baz"
,
"baz"
)
utils
.
remove_all
(
fs
,
"foo/bar"
)
self
.
assert_
(
not
fs
.
exists
(
"foo/bar/fruit"
))
self
.
assert_
(
fs
.
exists
(
"foo/bar"
))
self
.
assert_
(
fs
.
exists
(
"foo/baz"
))
utils
.
remove_all
(
fs
,
""
)
self
.
assert_
(
not
fs
.
exists
(
"foo/bar/fruit"
))
self
.
assert_
(
not
fs
.
exists
(
"foo/bar/baz"
))
self
.
assert_
(
not
fs
.
exists
(
"foo/baz"
))
self
.
assert_
(
not
fs
.
exists
(
"foo"
))
self
.
assert_
(
not
fs
.
exists
(
"f1"
))
self
.
assert_
(
fs
.
isdirempty
(
'/'
))
fs1
=
TempFS
()
fs2
=
TempFS
()
fs1sub
=
fs1
.
makeopendir
(
"from"
)
_make_fs
(
fs1sub
)
utils
.
movedir
((
fs1
,
"from"
),
fs2
)
#self.assert_(not fs1.exists("from"))
#self._check_fs(fs2)
\ No newline at end of file
\ No newline at end of file
fs/utils.py
View file @
315ea957
...
...
@@ -253,6 +253,23 @@ def copydir(fs1, fs2, create_destination=True, ignore_errors=False, chunk_size=6
chunk_size
=
chunk_size
)
def
remove_all
(
fs
,
path
):
"""Remove everything in a directory. Returns True if successful.
:param fs: A filesystem
:param path: Path to a directory
"""
fs
.
tree
()
sub_fs
=
fs
.
opendir
(
path
)
for
sub_path
in
sub_fs
.
listdir
():
if
sub_fs
.
isdir
(
sub_path
):
sub_fs
.
removedir
(
sub_path
,
force
=
True
)
else
:
sub_fs
.
remove
(
sub_path
)
return
fs
.
isdirempty
(
path
)
def
copystructure
(
src_fs
,
dst_fs
):
"""Copies the directory structure from one filesystem to another, so that
all directories in `src_fs` will have a corresponding directory in `dst_fs`
...
...
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