[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-137]
added listdir_attr() add SFTPClient.listdir_attr() to fetch a list of files & their attributes, instead of just their filenames. artur piwko would find this useful.
This commit is contained in:
parent
811f2bf30f
commit
1eda9b051b
|
@ -82,9 +82,11 @@ class SFTPAttributes (object):
|
||||||
### internals...
|
### internals...
|
||||||
|
|
||||||
|
|
||||||
def _from_msg(cls, msg):
|
def _from_msg(cls, msg, filename=None):
|
||||||
attr = cls()
|
attr = cls()
|
||||||
attr._unpack(msg)
|
attr._unpack(msg)
|
||||||
|
if filename is not None:
|
||||||
|
attr.filename = filename
|
||||||
return attr
|
return attr
|
||||||
_from_msg = classmethod(_from_msg)
|
_from_msg = classmethod(_from_msg)
|
||||||
|
|
||||||
|
|
|
@ -76,11 +76,29 @@ class SFTPClient (BaseSFTP):
|
||||||
Return a list containing the names of the entries in the given C{path}.
|
Return a list containing the names of the entries in the given C{path}.
|
||||||
The list is in arbitrary order. It does not include the special
|
The list is in arbitrary order. It does not include the special
|
||||||
entries C{'.'} and C{'..'} even if they are present in the folder.
|
entries C{'.'} and C{'..'} even if they are present in the folder.
|
||||||
|
This method is meant to mirror C{os.listdir} as closely as possible.
|
||||||
|
For a list of full L{SFTPAttributes} objects, see L{listdir_attr}.
|
||||||
|
|
||||||
@param path: path to list.
|
@param path: path to list.
|
||||||
@type path: string
|
@type path: str
|
||||||
@return: list of filenames.
|
@return: list of filenames.
|
||||||
@rtype: list of string
|
@rtype: list of str
|
||||||
|
"""
|
||||||
|
return [f.filename for f in self.listdir_attr(path)]
|
||||||
|
|
||||||
|
def listdir_attr(self, path):
|
||||||
|
"""
|
||||||
|
Return a list containing L{SFTPAttributes} objects corresponding to
|
||||||
|
files in the given C{path}. The list is in arbitrary order. It does
|
||||||
|
not include the special entries C{'.'} and C{'..'} even if they are
|
||||||
|
present in the folder.
|
||||||
|
|
||||||
|
@param path: path to list.
|
||||||
|
@type path: str
|
||||||
|
@return: list of attributes.
|
||||||
|
@rtype: list of L{SFTPAttributes}
|
||||||
|
|
||||||
|
@since: 1.2
|
||||||
"""
|
"""
|
||||||
t, msg = self._request(CMD_OPENDIR, path)
|
t, msg = self._request(CMD_OPENDIR, path)
|
||||||
if t != CMD_HANDLE:
|
if t != CMD_HANDLE:
|
||||||
|
@ -99,10 +117,9 @@ class SFTPClient (BaseSFTP):
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
filename = msg.get_string()
|
filename = msg.get_string()
|
||||||
longname = msg.get_string()
|
longname = msg.get_string()
|
||||||
attr = SFTPAttributes._from_msg(msg)
|
attr = SFTPAttributes._from_msg(msg, filename)
|
||||||
if (filename != '.') and (filename != '..'):
|
if (filename != '.') and (filename != '..'):
|
||||||
filelist.append(filename)
|
filelist.append(attr)
|
||||||
# currently we ignore the rest
|
|
||||||
self._request(CMD_CLOSE, handle)
|
self._request(CMD_CLOSE, handle)
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue