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
1c7a928c
Commit
1c7a928c
authored
Dec 23, 2010
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small optimization
parent
5489ce99
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
20 deletions
+34
-20
fs/path.py
+17
-13
fs/tempfs.py
+6
-2
fs/tests/__init__.py
+10
-5
fs/tests/test_path.py
+1
-0
No files found.
fs/path.py
View file @
1c7a928c
...
@@ -77,20 +77,24 @@ def recursepath(path, reverse=False):
...
@@ -77,20 +77,24 @@ def recursepath(path, reverse=False):
>>> recursepath('a/b/c')
>>> recursepath('a/b/c')
['/', u'/a', u'/a/b', u'/a/b/c']
['/', u'/a', u'/a/b', u'/a/b/c']
"""
"""
paths
=
[
u'/'
]
append
=
paths
.
append
path
=
u'/'
+
normpath
(
path
.
lstrip
(
'/'
))
find
=
path
.
find
pos
=
1
if
len
(
path
)
>
1
:
while
1
:
pos
=
find
(
'/'
,
pos
+
1
)
if
pos
==
-
1
:
append
(
path
)
break
append
(
path
[:
pos
])
if
reverse
:
if
reverse
:
paths
=
[]
return
paths
[::
-
1
]
append
=
paths
.
append
return
paths
path
=
abspath
(
normpath
(
path
))
.
rstrip
(
"/"
)
while
path
:
append
(
path
)
path
=
dirname
(
path
)
.
rstrip
(
"/"
)
paths
.
append
(
u"/"
)
return
paths
else
:
paths
=
[
u""
]
+
list
(
iteratepath
(
path
))
return
[
u"/"
]
+
[
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/tempfs.py
View file @
1c7a928c
...
@@ -7,6 +7,7 @@ Make a temporary file system that exists in a folder provided by the OS. All fil
...
@@ -7,6 +7,7 @@ Make a temporary file system that exists in a folder provided by the OS. All fil
"""
"""
import
os
import
os
import
os.path
import
time
import
time
import
tempfile
import
tempfile
...
@@ -23,7 +24,8 @@ class TempFS(OSFS):
...
@@ -23,7 +24,8 @@ class TempFS(OSFS):
_meta
=
{
'virtual'
:
False
,
_meta
=
{
'virtual'
:
False
,
'read_only'
:
False
,
'read_only'
:
False
,
'unicode_paths'
:
os
.
path
.
supports_unicode_filenames
,
'unicode_paths'
:
os
.
path
.
supports_unicode_filenames
,
'case_insensitive_paths'
:
os
.
path
.
normcase
(
'Aa'
)
==
'aa'
,
'case_insensitive_paths'
:
os
.
path
.
normcase
(
'Aa'
)
==
'aa'
,
'pickle_contents'
:
False
,
'network'
:
False
,
'network'
:
False
,
'atomic.move'
:
True
,
'atomic.move'
:
True
,
'atomic.copy'
:
True
,
'atomic.copy'
:
True
,
...
@@ -55,7 +57,9 @@ class TempFS(OSFS):
...
@@ -55,7 +57,9 @@ class TempFS(OSFS):
return
u'<TempFS:
%
s>'
%
self
.
_temp_dir
return
u'<TempFS:
%
s>'
%
self
.
_temp_dir
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
state
=
super
(
TempFS
,
self
)
.
__setstate__
(
state
)
"""Pickle the TempFS. TempFS delted their contents when closed, so pickling
is not garanteed to preserve the directory contents"""
state
=
super
(
TempFS
,
self
)
.
__setstate__
(
state
)
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
self
.
identifier
or
"TempFS"
,
dir
=
self
.
temp_dir
)
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
self
.
identifier
or
"TempFS"
,
dir
=
self
.
temp_dir
)
super
(
TempFS
,
self
)
.
__init__
(
self
.
_temp_dir
,
super
(
TempFS
,
self
)
.
__init__
(
self
.
_temp_dir
,
dir_mode
=
self
.
dir_mode
,
dir_mode
=
self
.
dir_mode
,
...
...
fs/tests/__init__.py
View file @
1c7a928c
...
@@ -685,11 +685,16 @@ class FSTestCases(object):
...
@@ -685,11 +685,16 @@ class FSTestCases(object):
self
.
assertEquals
(
self
.
fs
.
getcontents
(
'f.txt'
),
contents
)
self
.
assertEquals
(
self
.
fs
.
getcontents
(
'f.txt'
),
contents
)
def
test_pickling
(
self
):
def
test_pickling
(
self
):
self
.
fs
.
setcontents
(
"test1"
,
"hello world"
)
if
self
.
fs
.
getmeta
(
'pickle_contents'
,
True
):
fs2
=
pickle
.
loads
(
pickle
.
dumps
(
self
.
fs
))
self
.
fs
.
setcontents
(
"test1"
,
"hello world"
)
self
.
assert_
(
fs2
.
isfile
(
"test1"
))
fs2
=
pickle
.
loads
(
pickle
.
dumps
(
self
.
fs
))
fs3
=
pickle
.
loads
(
pickle
.
dumps
(
self
.
fs
,
-
1
))
self
.
assert_
(
fs2
.
isfile
(
"test1"
))
self
.
assert_
(
fs3
.
isfile
(
"test1"
))
fs3
=
pickle
.
loads
(
pickle
.
dumps
(
self
.
fs
,
-
1
))
self
.
assert_
(
fs3
.
isfile
(
"test1"
))
else
:
# Just make sure it doesn't throw an exception
fs2
=
pickle
.
loads
(
pickle
.
dumps
(
self
.
fs
))
def
test_big_file
(
self
):
def
test_big_file
(
self
):
chunk_size
=
1024
*
256
chunk_size
=
1024
*
256
...
...
fs/tests/test_path.py
View file @
1c7a928c
...
@@ -103,6 +103,7 @@ class TestPathFunctions(unittest.TestCase):
...
@@ -103,6 +103,7 @@ class TestPathFunctions(unittest.TestCase):
self
.
assertEquals
(
recursepath
(
"hello"
,
reverse
=
True
),[
"/hello"
,
"/"
])
self
.
assertEquals
(
recursepath
(
"hello"
,
reverse
=
True
),[
"/hello"
,
"/"
])
self
.
assertEquals
(
recursepath
(
""
,
reverse
=
True
),[
"/"
])
self
.
assertEquals
(
recursepath
(
""
,
reverse
=
True
),[
"/"
])
def
test_isdotfile
(
self
):
def
test_isdotfile
(
self
):
for
path
in
[
'.foo'
,
for
path
in
[
'.foo'
,
'.svn'
,
'.svn'
,
...
...
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