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
dc2e9a34
Commit
dc2e9a34
authored
Dec 17, 2010
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed some broken tests
parent
3e149d2f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
35 deletions
+49
-35
fs/base.py
+13
-7
fs/sftpfs.py
+26
-18
fs/tempfs.py
+6
-6
fs/tests/__init__.py
+1
-2
fs/tests/test_expose.py
+3
-2
No files found.
fs/base.py
View file @
dc2e9a34
...
@@ -174,6 +174,10 @@ class FS(object):
...
@@ -174,6 +174,10 @@ class FS(object):
pass
pass
def
close
(
self
):
def
close
(
self
):
"""Close the filesystem. This will perform any shutdown related
operations required. This method will be called automatically when
an the filesystem object is cleaned up, but it is a good idea to call
it explicitly."""
self
.
closed
=
True
self
.
closed
=
True
def
__getstate__
(
self
):
def
__getstate__
(
self
):
...
@@ -190,9 +194,7 @@ class FS(object):
...
@@ -190,9 +194,7 @@ class FS(object):
return
state
return
state
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
self
.
__dict__
.
update
(
state
)
self
.
__dict__
.
update
(
state
)
#for (k,v) in state.iteritems():
# self.__dict__[k] = v
lock
=
state
.
get
(
"_lock"
)
lock
=
state
.
get
(
"_lock"
)
if
lock
is
not
None
:
if
lock
is
not
None
:
if
lock
:
if
lock
:
...
@@ -202,7 +204,7 @@ class FS(object):
...
@@ -202,7 +204,7 @@ class FS(object):
def
getmeta
(
self
,
meta_name
,
default
=
NoDefaultMeta
):
def
getmeta
(
self
,
meta_name
,
default
=
NoDefaultMeta
):
"""Retrieve a meta value associated with an FS object. Meta values are
"""Retrieve a meta value associated with an FS object. Meta values are
a way
of
an FS implementation to report potentially useful information
a way
for
an FS implementation to report potentially useful information
associated with the file system.
associated with the file system.
A meta key is a lower case string with no spaces. Meta keys may also
A meta key is a lower case string with no spaces. Meta keys may also
...
@@ -213,7 +215,7 @@ class FS(object):
...
@@ -213,7 +215,7 @@ class FS(object):
* *read_only* True if the file system can not be modified
* *read_only* True if the file system can not be modified
* *network* True if the file system requires network access
* *network* True if the file system requires network access
* *unicode_paths* True if the file system
can use
unicode paths
* *unicode_paths* True if the file system
supports
unicode paths
* *case_insensitive_paths* True if the file system ignores the case of paths
* *case_insensitive_paths* True if the file system ignores the case of paths
* *atomic.makedir* True if making a directory is an atomic operation
* *atomic.makedir* True if making a directory is an atomic operation
* *atomic.rename* True if rename is an atomic operation, (and not implemented as a copy followed by a delete)
* *atomic.rename* True if rename is an atomic operation, (and not implemented as a copy followed by a delete)
...
@@ -342,6 +344,7 @@ class FS(object):
...
@@ -342,6 +344,7 @@ class FS(object):
:param path: A path in the filessystem
:param path: A path in the filessystem
:rtype: bool
:rtype: bool
"""
"""
return
self
.
isfile
(
path
)
or
self
.
isdir
(
path
)
return
self
.
isfile
(
path
)
or
self
.
isdir
(
path
)
...
@@ -1031,7 +1034,10 @@ class FS(object):
...
@@ -1031,7 +1034,10 @@ class FS(object):
if
syspath
is
None
:
if
syspath
is
None
:
raise
NoMMapError
(
path
)
raise
NoMMapError
(
path
)
import
mmap
try
:
import
mmap
except
ImportError
:
raise
NoMMapError
(
msg
=
"mmap not supported"
)
if
read_only
:
if
read_only
:
f
=
open
(
syspath
,
'rb'
)
f
=
open
(
syspath
,
'rb'
)
...
@@ -1044,7 +1050,7 @@ class FS(object):
...
@@ -1044,7 +1050,7 @@ class FS(object):
f
=
open
(
syspath
,
'r+b'
)
f
=
open
(
syspath
,
'r+b'
)
access
=
mmap
.
ACCESS_WRITE
access
=
mmap
.
ACCESS_WRITE
m
=
mmap
.
mmap
(
f
.
fileno
,
0
,
access
=
access
)
m
=
mmap
.
mmap
(
f
.
fileno
()
,
0
,
access
=
access
)
return
m
return
m
...
...
fs/sftpfs.py
View file @
dc2e9a34
...
@@ -47,7 +47,7 @@ if not hasattr(paramiko.SFTPFile,"__enter__"):
...
@@ -47,7 +47,7 @@ if not hasattr(paramiko.SFTPFile,"__enter__"):
class
SFTPFS
(
FS
):
class
SFTPFS
(
FS
):
"""A filesystem stored on a remote SFTP server.
"""A filesystem stored on a remote SFTP server.
This is basically a compat
a
bility wrapper for the excellent SFTPClient
This is basically a compat
i
bility wrapper for the excellent SFTPClient
class in the paramiko module.
class in the paramiko module.
"""
"""
...
@@ -65,7 +65,7 @@ class SFTPFS(FS):
...
@@ -65,7 +65,7 @@ class SFTPFS(FS):
}
}
def
__init__
(
self
,
connection
,
root_path
=
"/"
,
encoding
=
None
,
hostkey
=
None
,
username
=
''
,
password
=
None
,
pkey
=
None
):
def
__init__
(
self
,
connection
,
root_path
=
"/"
,
encoding
=
None
,
hostkey
=
None
,
username
=
''
,
password
=
None
,
pkey
=
None
,
agent_auth
=
True
,
no_auth
=
False
):
"""SFTPFS constructor.
"""SFTPFS constructor.
The only required argument is 'connection', which must be something
The only required argument is 'connection', which must be something
...
@@ -78,7 +78,7 @@ class SFTPFS(FS):
...
@@ -78,7 +78,7 @@ class SFTPFS(FS):
* a paramiko.Channel instance in "sftp" mode
* a paramiko.Channel instance in "sftp" mode
The kwd argument 'root_path' specifies the root directory on the remote
The kwd argument 'root_path' specifies the root directory on the remote
machine - access to files outsi
t
e this root wil be prevented.
machine - access to files outsi
d
e this root wil be prevented.
:param connection: a connection string
:param connection: a connection string
:param root_path: The root path to open
:param root_path: The root path to open
...
@@ -87,6 +87,8 @@ class SFTPFS(FS):
...
@@ -87,6 +87,8 @@ class SFTPFS(FS):
:param username: Name of SFTP user
:param username: Name of SFTP user
:param password: Password for SFTP user
:param password: Password for SFTP user
:param pkey: Public key
:param pkey: Public key
:param agent_auth: attempt to authorise with the user's public keys
:param no_auth: attempt to log in without any kind of authorisation
"""
"""
...
@@ -127,20 +129,29 @@ class SFTPFS(FS):
...
@@ -127,20 +129,29 @@ class SFTPFS(FS):
key
=
self
.
get_remote_server_key
()
key
=
self
.
get_remote_server_key
()
if
hostkey
!=
key
:
if
hostkey
!=
key
:
raise
WrongHostKeyError
(
'Host keys do not match'
)
raise
WrongHostKeyError
(
'Host keys do not match'
)
connection
.
start_client
()
connection
.
start_client
()
if
not
connection
.
is_authenticated
():
if
not
connection
.
is_active
():
raise
RemoteConnectionError
(
'Unable to connect'
)
if
no_auth
:
try
:
connection
.
auth_none
(
''
)
except
paramiko
.
SSHException
:
pass
if
not
connection
.
is_authenticated
():
try
:
try
:
if
pkey
:
if
pkey
:
connection
.
auth_publickey
(
username
,
pkey
)
connection
.
auth_publickey
(
username
,
pkey
)
if
not
connection
.
is_authenticated
()
and
password
:
if
not
connection
.
is_authenticated
()
and
password
:
connection
.
auth_password
(
username
,
password
)
connection
.
auth_password
(
username
,
password
)
if
not
connection
.
is_authenticated
():
if
agent_auth
and
not
connection
.
is_authenticated
():
self
.
_agent_auth
(
connection
,
username
)
self
.
_agent_auth
(
connection
,
username
)
if
not
connection
.
is_authenticated
():
if
not
connection
.
is_authenticated
():
connection
.
close
()
connection
.
close
()
raise
RemoteConnectionError
(
'no auth'
)
raise
RemoteConnectionError
(
'no auth'
)
...
@@ -163,11 +174,10 @@ class SFTPFS(FS):
...
@@ -163,11 +174,10 @@ class SFTPFS(FS):
agent
=
paramiko
.
Agent
()
agent
=
paramiko
.
Agent
()
agent_keys
=
agent
.
get_keys
()
agent_keys
=
agent
.
get_keys
()
if
len
(
agent_keys
)
==
0
:
if
not
agent_keys
:
return
False
return
None
for
key
in
agent_keys
:
for
key
in
agent_keys
:
try
:
try
:
transport
.
auth_publickey
(
username
,
key
)
transport
.
auth_publickey
(
username
,
key
)
return
key
return
key
except
paramiko
.
SSHException
:
except
paramiko
.
SSHException
:
...
@@ -383,8 +393,6 @@ class SFTPFS(FS):
...
@@ -383,8 +393,6 @@ class SFTPFS(FS):
return
[(
p
,
getinfo
(
p
))
for
p
in
return
[(
p
,
getinfo
(
p
))
for
p
in
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
False
,
False
)]
self
.
_listdir_helper
(
path
,
paths
,
wildcard
,
full
,
absolute
,
False
,
False
)]
@convert_os_errors
@convert_os_errors
def
makedir
(
self
,
path
,
recursive
=
False
,
allow_recreate
=
False
):
def
makedir
(
self
,
path
,
recursive
=
False
,
allow_recreate
=
False
):
npath
=
self
.
_normpath
(
path
)
npath
=
self
.
_normpath
(
path
)
...
...
fs/tempfs.py
View file @
dc2e9a34
...
@@ -54,12 +54,12 @@ class TempFS(OSFS):
...
@@ -54,12 +54,12 @@ class TempFS(OSFS):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
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
)
#
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,
thread_synchronize
=
self
.
thread_synchronize
)
#
thread_synchronize=self.thread_synchronize)
def
close
(
self
):
def
close
(
self
):
"""Removes the temporary directory.
"""Removes the temporary directory.
...
...
fs/tests/__init__.py
View file @
dc2e9a34
...
@@ -691,8 +691,7 @@ class FSTestCases(object):
...
@@ -691,8 +691,7 @@ class FSTestCases(object):
fs3
=
pickle
.
loads
(
pickle
.
dumps
(
self
.
fs
,
-
1
))
fs3
=
pickle
.
loads
(
pickle
.
dumps
(
self
.
fs
,
-
1
))
self
.
assert_
(
fs3
.
isfile
(
"test1"
))
self
.
assert_
(
fs3
.
isfile
(
"test1"
))
def
test_big_file
(
self
):
def
test_big_file
(
self
):
return
chunk_size
=
1024
*
256
chunk_size
=
1024
*
256
num_chunks
=
4
num_chunks
=
4
def
chunk_stream
():
def
chunk_stream
():
...
...
fs/tests/test_expose.py
View file @
dc2e9a34
...
@@ -38,7 +38,8 @@ class TestRPCFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
...
@@ -38,7 +38,8 @@ class TestRPCFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
raise
raise
self
.
server_addr
=
(
"localhost"
,
port
)
self
.
server_addr
=
(
"localhost"
,
port
)
self
.
serve_more_requests
=
True
self
.
serve_more_requests
=
True
self
.
server_thread
=
threading
.
Thread
(
target
=
self
.
runServer
)
self
.
server_thread
=
threading
.
Thread
(
target
=
self
.
runServer
)
self
.
server_thread
.
daemon
=
True
self
.
server_thread
.
start
()
self
.
server_thread
.
start
()
def
runServer
(
self
):
def
runServer
(
self
):
...
@@ -94,7 +95,7 @@ class TestSFTPFS(TestRPCFS):
...
@@ -94,7 +95,7 @@ class TestSFTPFS(TestRPCFS):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
startServer
()
self
.
startServer
()
self
.
fs
=
sftpfs
.
SFTPFS
(
self
.
server_addr
)
self
.
fs
=
sftpfs
.
SFTPFS
(
self
.
server_addr
,
no_auth
=
True
)
def
bump
(
self
):
def
bump
(
self
):
# paramiko doesn't like being bumped, just wait for it to timeout.
# paramiko doesn't like being bumped, just wait for it to timeout.
...
...
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