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
2cafbe31
Commit
2cafbe31
authored
Jan 07, 2010
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A few tweaks and fixes
parent
c85ece62
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
35 additions
and
49 deletions
+35
-49
fs/base.py
+1
-1
fs/ftpfs.py
+10
-19
fs/memoryfs.py
+1
-2
fs/mountfs.py
+1
-1
fs/multifs.py
+1
-2
fs/osfs.py
+10
-5
fs/s3fs.py
+1
-2
fs/sftpfs.py
+1
-2
fs/tempfs.py
+1
-3
fs/tests/__init__.py
+4
-6
fs/zipfs.py
+4
-6
No files found.
fs/base.py
View file @
2cafbe31
...
@@ -320,7 +320,7 @@ class FS(object):
...
@@ -320,7 +320,7 @@ class FS(object):
"""
"""
def
get_path
(
p
):
def
get_path
(
p
):
if
not
full
:
if
not
full
or
absolute
:
return
pathjoin
(
path
,
p
)
return
pathjoin
(
path
,
p
)
return
[(
p
,
self
.
getinfo
(
get_path
(
p
)))
return
[(
p
,
self
.
getinfo
(
get_path
(
p
)))
...
...
fs/ftpfs.py
View file @
2cafbe31
...
@@ -543,8 +543,6 @@ class _FTPFile(object):
...
@@ -543,8 +543,6 @@ class _FTPFile(object):
self
.
ftp
.
voidcmd
(
'TYPE I'
)
self
.
ftp
.
voidcmd
(
'TYPE I'
)
self
.
conn
=
ftp
.
transfercmd
(
'RETR '
+
path
,
None
)
self
.
conn
=
ftp
.
transfercmd
(
'RETR '
+
path
,
None
)
#self._ftp_thread = threading.Thread(target=do_read)
#self._ftp_thread.start()
elif
'w'
in
mode
or
'a'
in
mode
:
elif
'w'
in
mode
or
'a'
in
mode
:
self
.
ftp
.
voidcmd
(
'TYPE I'
)
self
.
ftp
.
voidcmd
(
'TYPE I'
)
if
'a'
in
mode
:
if
'a'
in
mode
:
...
@@ -552,16 +550,6 @@ class _FTPFile(object):
...
@@ -552,16 +550,6 @@ class _FTPFile(object):
self
.
conn
=
self
.
ftp
.
transfercmd
(
'APPE '
+
path
)
self
.
conn
=
self
.
ftp
.
transfercmd
(
'APPE '
+
path
)
else
:
else
:
self
.
conn
=
self
.
ftp
.
transfercmd
(
'STOR '
+
path
)
self
.
conn
=
self
.
ftp
.
transfercmd
(
'STOR '
+
path
)
#while 1:
# buf = fp.read(blocksize)
# if not buf: break
# conn.sendall(buf)
# if callback: callback(buf)
#conn.close()
#return self.voidresp()
#self._ftp_thread = threading.Thread(target=do_write)
#self._ftp_thread.start()
@synchronize
@synchronize
def
read
(
self
,
size
=
None
):
def
read
(
self
,
size
=
None
):
...
@@ -689,17 +677,20 @@ class _FTPFile(object):
...
@@ -689,17 +677,20 @@ class _FTPFile(object):
"""
"""
endings
=
'
\r\n
'
endings
=
'
\r\n
'
chars
=
[]
chars
=
[]
append
=
chars
.
append
read
=
self
.
read
join
=
''
.
join
while
True
:
while
True
:
char
=
self
.
read
(
1
)
char
=
read
(
1
)
if
not
char
:
if
not
char
:
yield
''
.
join
(
chars
)
if
chars
:
del
chars
[:]
yield
join
(
chars
)
break
break
chars
.
append
(
char
)
append
(
char
)
if
char
in
endings
:
if
char
in
endings
:
line
=
''
.
join
(
chars
)
line
=
join
(
chars
)
del
chars
[:]
del
chars
[:]
c
=
self
.
read
(
1
)
c
=
read
(
1
)
if
not
char
:
if
not
char
:
yield
line
yield
line
break
break
...
@@ -707,7 +698,7 @@ class _FTPFile(object):
...
@@ -707,7 +698,7 @@ class _FTPFile(object):
yield
line
+
c
yield
line
+
c
else
:
else
:
yield
line
yield
line
chars
.
append
(
c
)
append
(
c
)
...
...
fs/memoryfs.py
View file @
2cafbe31
...
@@ -181,6 +181,7 @@ class MemoryFS(FS):
...
@@ -181,6 +181,7 @@ class MemoryFS(FS):
def
__init__
(
self
,
file_factory
=
None
):
def
__init__
(
self
,
file_factory
=
None
):
super
(
MemoryFS
,
self
)
.
__init__
(
thread_synchronize
=
_thread_synchronize_default
)
super
(
MemoryFS
,
self
)
.
__init__
(
thread_synchronize
=
_thread_synchronize_default
)
self
.
dir_entry_factory
=
DirEntry
self
.
dir_entry_factory
=
DirEntry
self
.
file_factory
=
file_factory
or
MemoryFile
self
.
file_factory
=
file_factory
or
MemoryFile
...
@@ -463,5 +464,3 @@ class MemoryFS(FS):
...
@@ -463,5 +464,3 @@ class MemoryFS(FS):
info
[
'size'
]
=
len
(
dir_entry
.
data
or
''
)
info
[
'size'
]
=
len
(
dir_entry
.
data
or
''
)
return
info
return
info
fs/mountfs.py
View file @
2cafbe31
...
@@ -35,7 +35,7 @@ class MountFS(FS):
...
@@ -35,7 +35,7 @@ class MountFS(FS):
FileMount
=
FileMount
FileMount
=
FileMount
def
__init__
(
self
,
thread_synchronize
=
_thread_synchronize_default
):
def
__init__
(
self
,
thread_synchronize
=
_thread_synchronize_default
):
FS
.
__init__
(
self
,
thread_synchronize
=
thread_synchronize
)
super
(
MountFS
,
self
)
.
__init__
(
thread_synchronize
=
thread_synchronize
)
self
.
mount_tree
=
ObjectTree
()
self
.
mount_tree
=
ObjectTree
()
def
__str__
(
self
):
def
__str__
(
self
):
...
...
fs/multifs.py
View file @
2cafbe31
...
@@ -39,7 +39,7 @@ class MultiFS(FS):
...
@@ -39,7 +39,7 @@ class MultiFS(FS):
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
FS
.
__init__
(
self
,
thread_synchronize
=
_thread_synchronize_default
)
super
(
MultiFS
,
self
)
.
__init__
(
thread_synchronize
=
_thread_synchronize_default
)
self
.
fs_sequence
=
[]
self
.
fs_sequence
=
[]
self
.
fs_lookup
=
{}
self
.
fs_lookup
=
{}
...
@@ -195,4 +195,3 @@ class MultiFS(FS):
...
@@ -195,4 +195,3 @@ class MultiFS(FS):
if
fs
.
exists
(
path
):
if
fs
.
exists
(
path
):
return
fs
.
getinfo
(
path
)
return
fs
.
getinfo
(
path
)
raise
ResourceNotFoundError
(
path
)
raise
ResourceNotFoundError
(
path
)
fs/osfs.py
View file @
2cafbe31
...
@@ -41,8 +41,7 @@ class OSFS(FS):
...
@@ -41,8 +41,7 @@ class OSFS(FS):
methods in the os and os.path modules.
methods in the os and os.path modules.
"""
"""
def
__init__
(
self
,
root_path
,
dir_mode
=
0700
,
thread_synchronize
=
_thread_synchronize_default
,
encoding
=
None
):
def
__init__
(
self
,
root_path
,
dir_mode
=
0700
,
thread_synchronize
=
_thread_synchronize_default
,
encoding
=
None
,
create
=
False
):
"""
"""
Creates an FS object that represents the OS Filesystem under a given root path
Creates an FS object that represents the OS Filesystem under a given root path
...
@@ -50,10 +49,11 @@ class OSFS(FS):
...
@@ -50,10 +49,11 @@ class OSFS(FS):
:param dir_mode: srt
:param dir_mode: srt
:param thread_synchronize: If True, this object will be thread-safe by use of a threading.Lock object
:param thread_synchronize: If True, this object will be thread-safe by use of a threading.Lock object
:param encoding: The encoding method for path strings
:param encoding: The encoding method for path strings
:param create: Of True, then root_path will be created (if neccesary)
"""
"""
FS
.
__init__
(
self
,
thread_synchronize
=
thread_synchronize
)
super
(
OSFS
,
self
)
.
__init__
(
thread_synchronize
=
thread_synchronize
)
self
.
encoding
=
encoding
self
.
encoding
=
encoding
root_path
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
root_path
))
root_path
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
root_path
))
root_path
=
os
.
path
.
normpath
(
os
.
path
.
abspath
(
root_path
))
root_path
=
os
.
path
.
normpath
(
os
.
path
.
abspath
(
root_path
))
...
@@ -61,6 +61,13 @@ class OSFS(FS):
...
@@ -61,6 +61,13 @@ class OSFS(FS):
if
sys
.
platform
==
"win32"
:
if
sys
.
platform
==
"win32"
:
if
not
root_path
.
startswith
(
"
\\\\
?
\\
"
):
if
not
root_path
.
startswith
(
"
\\\\
?
\\
"
):
root_path
=
u"
\\\\
?
\\
"
+
root_path
root_path
=
u"
\\\\
?
\\
"
+
root_path
if
create
:
try
:
os
.
makedirs
(
root_path
,
mode
=
dir_mode
)
except
OSError
:
pass
if
not
os
.
path
.
exists
(
root_path
):
if
not
os
.
path
.
exists
(
root_path
):
raise
ResourceNotFoundError
(
root_path
,
msg
=
"Root directory does not exist:
%(path)
s"
)
raise
ResourceNotFoundError
(
root_path
,
msg
=
"Root directory does not exist:
%(path)
s"
)
if
not
os
.
path
.
isdir
(
root_path
):
if
not
os
.
path
.
isdir
(
root_path
):
...
@@ -225,5 +232,3 @@ class OSFS(FS):
...
@@ -225,5 +232,3 @@ class OSFS(FS):
@convert_os_errors
@convert_os_errors
def
listxattrs
(
self
,
path
):
def
listxattrs
(
self
,
path
):
return
xattr
.
xattr
(
self
.
getsyspath
(
path
))
.
keys
()
return
xattr
.
xattr
(
self
.
getsyspath
(
path
))
.
keys
()
fs/s3fs.py
View file @
2cafbe31
...
@@ -88,7 +88,7 @@ class S3FS(FS):
...
@@ -88,7 +88,7 @@ class S3FS(FS):
prefix
=
prefix
+
separator
prefix
=
prefix
+
separator
self
.
_prefix
=
prefix
self
.
_prefix
=
prefix
self
.
_tlocal
=
thread_local
()
self
.
_tlocal
=
thread_local
()
FS
.
__init__
(
self
,
thread_synchronize
=
thread_synchronize
)
super
(
S3FS
,
self
)
.
__init__
(
thread_synchronize
=
thread_synchronize
)
# Make _s3conn and _s3bukt properties that are created on demand,
# Make _s3conn and _s3bukt properties that are created on demand,
# since they cannot be stored during pickling.
# since they cannot be stored during pickling.
...
@@ -486,4 +486,3 @@ class S3FS(FS):
...
@@ -486,4 +486,3 @@ class S3FS(FS):
def
get_total_size
(
self
):
def
get_total_size
(
self
):
"""Get total size of all files in this FS."""
"""Get total size of all files in this FS."""
return
sum
(
k
.
size
for
k
in
self
.
_s3bukt
.
list
(
prefix
=
self
.
_prefix
))
return
sum
(
k
.
size
for
k
in
self
.
_s3bukt
.
list
(
prefix
=
self
.
_prefix
))
fs/sftpfs.py
View file @
2cafbe31
...
@@ -79,6 +79,7 @@ class SFTPFS(FS):
...
@@ -79,6 +79,7 @@ class SFTPFS(FS):
connection
.
connect
(
**
credentials
)
connection
.
connect
(
**
credentials
)
self
.
_transport
=
connection
self
.
_transport
=
connection
self
.
root_path
=
abspath
(
normpath
(
root_path
))
self
.
root_path
=
abspath
(
normpath
(
root_path
))
super
(
SFTPFS
,
self
)
.
__init__
()
def
__del__
(
self
):
def
__del__
(
self
):
self
.
close
()
self
.
close
()
...
@@ -320,5 +321,3 @@ class SFTPFS(FS):
...
@@ -320,5 +321,3 @@ class SFTPFS(FS):
npath
=
self
.
_normpath
(
path
)
npath
=
self
.
_normpath
(
path
)
stats
=
self
.
client
.
stat
(
npath
)
stats
=
self
.
client
.
stat
(
npath
)
return
stats
.
st_size
return
stats
.
st_size
fs/tempfs.py
View file @
2cafbe31
...
@@ -28,7 +28,7 @@ class TempFS(OSFS):
...
@@ -28,7 +28,7 @@ class TempFS(OSFS):
"""
"""
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
identifier
or
"TempFS"
,
dir
=
temp_dir
)
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
identifier
or
"TempFS"
,
dir
=
temp_dir
)
self
.
_cleaned
=
False
self
.
_cleaned
=
False
OSFS
.
__init__
(
self
,
self
.
_temp_dir
,
dir_mode
=
dir_mode
,
thread_synchronize
=
thread_synchronize
)
super
(
TempFS
,
self
)
.
__init__
(
self
.
_temp_dir
,
dir_mode
=
dir_mode
,
thread_synchronize
=
thread_synchronize
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'<TempFS:
%
s>'
%
self
.
_temp_dir
return
'<TempFS:
%
s>'
%
self
.
_temp_dir
...
@@ -86,5 +86,3 @@ class TempFS(OSFS):
...
@@ -86,5 +86,3 @@ class TempFS(OSFS):
finally
:
finally
:
self
.
_lock
.
release
()
self
.
_lock
.
release
()
super
(
TempFS
,
self
)
.
close
()
super
(
TempFS
,
self
)
.
close
()
fs/tests/__init__.py
View file @
2cafbe31
...
@@ -26,7 +26,7 @@ except ImportError:
...
@@ -26,7 +26,7 @@ except ImportError:
import
dummy_threading
as
threading
import
dummy_threading
as
threading
class
FSTestCases
:
class
FSTestCases
(
object
)
:
"""Base suite of testcases for filesystem implementations.
"""Base suite of testcases for filesystem implementations.
Any FS subclass should be capable of passing all of these tests.
Any FS subclass should be capable of passing all of these tests.
...
@@ -70,14 +70,14 @@ class FSTestCases:
...
@@ -70,14 +70,14 @@ class FSTestCases:
f
=
self
.
fs
.
open
(
"test1.txt"
,
"w"
)
f
=
self
.
fs
.
open
(
"test1.txt"
,
"w"
)
f
.
write
(
"testing"
)
f
.
write
(
"testing"
)
f
.
close
()
f
.
close
()
self
.
check
(
"test1.txt"
)
self
.
assertTrue
(
self
.
check
(
"test1.txt"
)
)
f
=
self
.
fs
.
open
(
"test1.txt"
,
"r"
)
f
=
self
.
fs
.
open
(
"test1.txt"
,
"r"
)
self
.
assertEquals
(
f
.
read
(),
"testing"
)
self
.
assertEquals
(
f
.
read
(),
"testing"
)
f
.
close
()
f
.
close
()
f
=
self
.
fs
.
open
(
"test1.txt"
,
"w"
)
f
=
self
.
fs
.
open
(
"test1.txt"
,
"w"
)
f
.
write
(
"test file overwrite"
)
f
.
write
(
"test file overwrite"
)
f
.
close
()
f
.
close
()
self
.
check
(
"test1.txt"
)
self
.
assertTrue
(
self
.
check
(
"test1.txt"
)
)
f
=
self
.
fs
.
open
(
"test1.txt"
,
"r"
)
f
=
self
.
fs
.
open
(
"test1.txt"
,
"r"
)
self
.
assertEquals
(
f
.
read
(),
"test file overwrite"
)
self
.
assertEquals
(
f
.
read
(),
"test file overwrite"
)
f
.
close
()
f
.
close
()
...
@@ -165,7 +165,7 @@ class FSTestCases:
...
@@ -165,7 +165,7 @@ class FSTestCases:
self
.
fs
.
makedir
(
alpha
)
self
.
fs
.
makedir
(
alpha
)
self
.
fs
.
createfile
(
alpha
+
"/a"
)
self
.
fs
.
createfile
(
alpha
+
"/a"
)
self
.
fs
.
createfile
(
alpha
+
"/"
+
beta
)
self
.
fs
.
createfile
(
alpha
+
"/"
+
beta
)
self
.
check
(
alpha
)
self
.
assertTrue
(
self
.
check
(
alpha
)
)
self
.
assertEquals
(
sorted
(
self
.
fs
.
listdir
(
alpha
)),[
"a"
,
beta
])
self
.
assertEquals
(
sorted
(
self
.
fs
.
listdir
(
alpha
)),[
"a"
,
beta
])
def
test_makedir
(
self
):
def
test_makedir
(
self
):
...
@@ -746,5 +746,3 @@ class ThreadingTestCases:
...
@@ -746,5 +746,3 @@ class ThreadingTestCases:
self
.
assertEquals
(
self
.
fs
.
getsize
(
"thread2.txt"
),
len
(
c
))
self
.
assertEquals
(
self
.
fs
.
getsize
(
"thread2.txt"
),
len
(
c
))
self
.
assertEquals
(
self
.
fs
.
getcontents
(
"thread2.txt"
),
c
)
self
.
assertEquals
(
self
.
fs
.
getcontents
(
"thread2.txt"
),
c
)
self
.
_runThreads
(
thread1
,
thread2
)
self
.
_runThreads
(
thread1
,
thread2
)
fs/zipfs.py
View file @
2cafbe31
...
@@ -55,18 +55,18 @@ class ZipFS(FS):
...
@@ -55,18 +55,18 @@ class ZipFS(FS):
"""A FileSystem that represents a zip file."""
"""A FileSystem that represents a zip file."""
def
__init__
(
self
,
zip_file
,
mode
=
"r"
,
compression
=
"deflated"
,
allow
Zip
64
=
False
,
encoding
=
"CP437"
,
thread_synchronize
=
True
):
def
__init__
(
self
,
zip_file
,
mode
=
"r"
,
compression
=
"deflated"
,
allow
_zip_
64
=
False
,
encoding
=
"CP437"
,
thread_synchronize
=
True
):
"""Create a FS that maps on to a zip file.
"""Create a FS that maps on to a zip file.
:param zip_file: A (system) path, or a file-like object
:param zip_file: A (system) path, or a file-like object
:param mode: Mode to open zip file: 'r' for reading, 'w' for writing or 'a' for appending
:param mode: Mode to open zip file: 'r' for reading, 'w' for writing or 'a' for appending
:param compression: Can be 'deflated' (default) to compress data or 'stored' to just store date
:param compression: Can be 'deflated' (default) to compress data or 'stored' to just store date
:param allow
Zip
64: -- Set to True to use zip files greater than 2 MB, default is False
:param allow
_zip_
64: -- Set to True to use zip files greater than 2 MB, default is False
:param encoding: -- The encoding to use for unicode filenames
:param encoding: -- The encoding to use for unicode filenames
:param thread_synchronize: -- Set to True (default) to enable thread-safety
:param thread_synchronize: -- Set to True (default) to enable thread-safety
"""
"""
FS
.
__init__
(
self
,
thread_synchronize
=
thread_synchronize
)
super
(
ZipFS
,
self
)
.
__init__
(
thread_synchronize
=
thread_synchronize
)
if
compression
==
"deflated"
:
if
compression
==
"deflated"
:
compression_type
=
ZIP_DEFLATED
compression_type
=
ZIP_DEFLATED
elif
compression
==
"stored"
:
elif
compression
==
"stored"
:
...
@@ -80,7 +80,7 @@ class ZipFS(FS):
...
@@ -80,7 +80,7 @@ class ZipFS(FS):
self
.
zip_mode
=
mode
self
.
zip_mode
=
mode
self
.
encoding
=
encoding
self
.
encoding
=
encoding
try
:
try
:
self
.
zf
=
ZipFile
(
zip_file
,
mode
,
compression_type
,
allow
Zip
64
)
self
.
zf
=
ZipFile
(
zip_file
,
mode
,
compression_type
,
allow
_zip_
64
)
except
IOError
:
except
IOError
:
raise
ResourceNotFoundError
(
str
(
zip_file
),
msg
=
"Zip file does not exist:
%(path)
s"
)
raise
ResourceNotFoundError
(
str
(
zip_file
),
msg
=
"Zip file does not exist:
%(path)
s"
)
self
.
zip_path
=
str
(
zip_file
)
self
.
zip_path
=
str
(
zip_file
)
...
@@ -212,5 +212,3 @@ class ZipFS(FS):
...
@@ -212,5 +212,3 @@ class ZipFS(FS):
info
[
'created_time'
]
=
datetime
.
datetime
(
*
zinfo
[
'date_time'
])
info
[
'created_time'
]
=
datetime
.
datetime
(
*
zinfo
[
'date_time'
])
info
.
update
(
zinfo
)
info
.
update
(
zinfo
)
return
info
return
info
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