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
d6ec7a9d
Commit
d6ec7a9d
authored
Sep 08, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress
parent
e0dd1077
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
63 deletions
+63
-63
fs/helpers.py
+27
-4
fs/path.py
+0
-59
fs/tempfs.py
+22
-0
fs/tests.py
+14
-0
No files found.
fs/helpers.py
View file @
d6ec7a9d
...
...
@@ -83,9 +83,25 @@ def pathsplit(path):
return
tuple
(
split
)
def
getroot
(
path
):
"""Returns the root directory of a path.
path -- A path
>>> getroot('foo/bar/baz')
'foo/bar'
"""
return
pathsplit
(
path
)[
0
]
def
getresourcename
(
path
):
"""Returns the resource references by a path.
path -- A path
>>> getresourcename('foo/bar/baz')
'baz'
"""
return
pathsplit
(
path
)[
1
]
def
resolvepath
(
path
):
...
...
@@ -127,8 +143,15 @@ def makeabsolute(path):
return
'/'
+
path
return
path
def
issamedir
(
path1
,
path2
):
dirname1
,
name1
=
pathsplit
(
path1
)
dirname2
,
name2
=
pathsplit
(
path2
)
return
dirname1
==
dirname2
"""Return true if two paths reference a resource in the same directory.
path1 -- First path
path2 -- Second path
>>> issamedir("foo/bar/baz.txt", "foo/bar/spam.txt")
True
>>> issamedir("foo/bar/baz/txt", "spam/eggs/spam.txt")
False
"""
return
pathsplit
(
path1
)[
0
]
==
pathsplit
(
path2
)[
0
]
fs/path.py
deleted
100644 → 0
View file @
e0dd1077
#!/usr/bin/env python
import
fs
from
os
import
path
class
Path
(
unicode
):
def
__repr__
(
self
):
return
"Path(
%
s)"
%
unicode
.
__repr__
(
self
)
def
__add__
(
self
,
path
):
return
self
.
__class__
(
unicode
.
__add__
(
self
,
path
))
def
__radd__
(
self
,
path
):
return
self
.
__class__
(
path
.
__add__
(
self
))
def
join
(
self
,
*
paths
):
return
self
.
__class__
(
fs
.
pathjoin
(
self
,
*
paths
))
def
_get_ext
(
self
):
return
path
.
splitext
(
self
)[
-
1
]
ext
=
property
(
_get_ext
,
None
,
"Retrieve the extension"
)
def
_get_head
(
self
):
head
,
tail
=
path
.
split
(
self
)
return
self
.
__class__
(
head
)
head
=
property
(
_get_head
,
None
,
"Retrieve the head of the path"
)
def
_get_tail
(
self
):
head
,
tail
=
path
.
split
(
self
)
return
self
.
__class__
(
tail
)
tail
=
property
(
_get_tail
,
None
,
"Retrieve the head of the path"
)
def
splitall
(
self
):
return
[
p
for
p
in
self
.
split
(
'/'
)
if
p
]
def
replace
(
self
,
s1
,
s2
):
return
self
.
__class__
(
unicode
.
replace
(
self
,
s1
,
s2
))
def
__getitem__
(
self
,
slice
):
return
self
.
__class__
(
unicode
.
__getitem__
(
self
,
slice
))
def
__div__
(
self
,
pth
):
return
self
.
join
(
pth
)
__truediv__
=
__div__
if
__name__
==
"__main__"
:
p1
=
Path
(
"a/b"
)
p2
=
p1
.
join
(
"c/d.txt"
)
print
repr
(
p1
.
replace
(
'a'
,
'HAI!'
))
print
repr
(
p1
[
0
])
print
repr
(
p1
+
p2
)
print
p1
/
"d/e/f"
print
p2
print
p2
.
ext
print
p2
.
head
print
p2
.
tail
print
p2
print
p2
.
splitall
()
fs/tempfs.py
0 → 100644
View file @
d6ec7a9d
#!/usr/bin/env python
from
osfs
import
OSFS
import
tempfile
from
shutil
import
rmtree
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"
)
OSFS
.
__init__
(
self
,
self
.
_temp_dir
)
def
_cleanup
(
self
):
if
self
.
_temp_dir
:
rmtree
(
self
.
_temp_dir
)
self
.
_temp_dir
=
""
def
__del__
(
self
):
self
.
_cleanup
()
fs/tests.py
View file @
d6ec7a9d
...
...
@@ -454,6 +454,20 @@ class TestMountFS(TestOSFS):
def
check
(
self
,
p
):
return
self
.
mount_fs
.
exists
(
os
.
path
.
join
(
"mounted/memfs"
,
makerelative
(
p
)))
import
tempfs
class
TestTempFS
(
TestOSFS
):
def
setUp
(
self
):
self
.
fs
=
tempfs
.
TempFS
()
def
tearDown
(
self
):
td
=
self
.
fs
.
_temp_dir
del
self
.
fs
self
.
assert_
(
not
os
.
path
.
exists
(
td
))
def
check
(
self
,
p
):
td
=
self
.
fs
.
_temp_dir
return
os
.
path
.
exists
(
os
.
path
.
join
(
td
,
makerelative
(
p
)))
if
__name__
==
"__main__"
:
#t = TestFS()
...
...
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