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
fa4c5944
Commit
fa4c5944
authored
Sep 09, 2013
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added constants rather than magic numbers #82
parent
e6559cd5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
+15
-10
fs/sftpfs.py
+15
-10
No files found.
fs/sftpfs.py
View file @
fa4c5944
...
...
@@ -14,6 +14,7 @@ import threading
import
os
import
paramiko
from
getpass
import
getuser
import
errno
from
fs.base
import
*
from
fs.path
import
*
...
...
@@ -22,9 +23,13 @@ from fs.utils import isdir, isfile
from
fs
import
iotools
ENOENT
=
errno
.
ENOENT
class
WrongHostKeyError
(
RemoteConnectionError
):
pass
# SFTPClient appears to not be thread-safe, so we use an instance per thread
if
hasattr
(
threading
,
"local"
):
thread_local
=
threading
.
local
...
...
@@ -364,7 +369,7 @@ class SFTPFS(FS):
try
:
self
.
client
.
stat
(
npath
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
return
False
raise
return
True
...
...
@@ -378,7 +383,7 @@ class SFTPFS(FS):
try
:
stat
=
self
.
client
.
stat
(
npath
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
return
False
raise
return
statinfo
.
S_ISDIR
(
stat
.
st_mode
)
!=
0
...
...
@@ -390,7 +395,7 @@ class SFTPFS(FS):
try
:
stat
=
self
.
client
.
stat
(
npath
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
return
False
raise
return
statinfo
.
S_ISREG
(
stat
.
st_mode
)
!=
0
...
...
@@ -408,7 +413,7 @@ class SFTPFS(FS):
else
:
paths
=
self
.
client
.
listdir
(
npath
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
if
self
.
isfile
(
path
):
raise
ResourceInvalidError
(
path
,
msg
=
"Can't list directory contents of a file:
%(path)
s"
)
raise
ResourceNotFoundError
(
path
)
...
...
@@ -445,7 +450,7 @@ class SFTPFS(FS):
attrs_map
=
dict
((
a
.
filename
,
a
)
for
a
in
attrs
)
paths
=
attrs_map
.
keys
()
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
if
self
.
isfile
(
path
):
raise
ResourceInvalidError
(
path
,
msg
=
"Can't list directory contents of a file:
%(path)
s"
)
raise
ResourceNotFoundError
(
path
)
...
...
@@ -515,7 +520,7 @@ class SFTPFS(FS):
try
:
self
.
client
.
remove
(
npath
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
raise
ResourceNotFoundError
(
path
)
elif
self
.
isdir
(
path
):
raise
ResourceInvalidError
(
path
,
msg
=
"Cannot use remove() on a directory:
%(path)
s"
)
...
...
@@ -538,7 +543,7 @@ class SFTPFS(FS):
try
:
self
.
client
.
rmdir
(
npath
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
if
self
.
isfile
(
path
):
raise
ResourceInvalidError
(
path
,
msg
=
"Can't use removedir() on a file:
%(path)
s"
)
raise
ResourceNotFoundError
(
path
)
...
...
@@ -561,7 +566,7 @@ class SFTPFS(FS):
try
:
self
.
client
.
rename
(
nsrc
,
ndst
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
raise
ResourceNotFoundError
(
src
)
if
not
self
.
isdir
(
dirname
(
dst
)):
raise
ParentDirectoryMissingError
(
dst
)
...
...
@@ -577,7 +582,7 @@ class SFTPFS(FS):
try
:
self
.
client
.
rename
(
nsrc
,
ndst
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
raise
ResourceNotFoundError
(
src
)
if
self
.
exists
(
dst
):
raise
DestinationExistsError
(
dst
)
...
...
@@ -595,7 +600,7 @@ class SFTPFS(FS):
try
:
self
.
client
.
rename
(
nsrc
,
ndst
)
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
if
getattr
(
e
,
"errno"
,
None
)
==
ENOENT
:
raise
ResourceNotFoundError
(
src
)
if
self
.
exists
(
dst
):
raise
DestinationExistsError
(
dst
)
...
...
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