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
853bc49d
Commit
853bc49d
authored
Apr 06, 2010
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include root dir in output of recursepath()
parent
1a46e329
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
7 deletions
+14
-7
fs/path.py
+6
-7
fs/tests/test_path.py
+8
-0
No files found.
fs/path.py
View file @
853bc49d
...
@@ -74,17 +74,16 @@ def iteratepath(path, numsplits=None):
...
@@ -74,17 +74,16 @@ def iteratepath(path, numsplits=None):
def
recursepath
(
path
,
reverse
=
False
):
def
recursepath
(
path
,
reverse
=
False
):
"""Iterate from root to path, returning intermediate paths"""
"""Iterate from root to path, returning intermediate paths"""
paths
=
list
(
iteratepath
(
path
))
if
reverse
:
if
reverse
:
paths
=
[]
paths
=
[]
while
path
.
lstrip
(
'/'
):
path
=
abspath
(
path
)
.
rstrip
(
"/"
)
while
path
:
paths
.
append
(
path
)
paths
.
append
(
path
)
path
=
dirname
(
path
)
path
=
dirname
(
path
)
.
rstrip
(
"/"
)
return
paths
return
paths
+
[
"/"
]
else
:
else
:
return
[
u'/'
.
join
(
paths
[:
i
+
1
])
for
i
in
xrange
(
len
(
paths
))]
paths
=
[
""
]
+
list
(
iteratepath
(
path
))
return
[
"/"
]
+
[
u'/'
.
join
(
paths
[:
i
+
1
])
for
i
in
xrange
(
1
,
len
(
paths
))]
def
abspath
(
path
):
def
abspath
(
path
):
"""Convert the given path to an absolute path.
"""Convert the given path to an absolute path.
...
...
fs/tests/test_path.py
View file @
853bc49d
...
@@ -94,6 +94,14 @@ class TestPathFunctions(unittest.TestCase):
...
@@ -94,6 +94,14 @@ class TestPathFunctions(unittest.TestCase):
for
path
,
result
in
tests
:
for
path
,
result
in
tests
:
self
.
assertEqual
(
fs
.
pathsplit
(
path
),
result
)
self
.
assertEqual
(
fs
.
pathsplit
(
path
),
result
)
def
test_recursepath
(
self
):
self
.
assertEquals
(
recursepath
(
"/"
),[
"/"
])
self
.
assertEquals
(
recursepath
(
"hello"
),[
"/"
,
"/hello"
])
self
.
assertEquals
(
recursepath
(
"/hello/world/"
),[
"/"
,
"/hello"
,
"/hello/world"
])
self
.
assertEquals
(
recursepath
(
"/hello/world/"
,
reverse
=
True
),[
"/hello/world"
,
"/hello"
,
"/"
])
self
.
assertEquals
(
recursepath
(
"hello"
,
reverse
=
True
),[
"/hello"
,
"/"
])
self
.
assertEquals
(
recursepath
(
""
,
reverse
=
True
),[
"/"
])
class
Test_PathMap
(
unittest
.
TestCase
):
class
Test_PathMap
(
unittest
.
TestCase
):
...
...
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