Commit 8b26b05d authored by Jérome Perrin's avatar Jérome Perrin

createDirectory an removeDirectory operations for sFTP

/reviewed-on nexedi/erp5!756
parents 78e66722 2781646f
...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo ...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
class FTPConnector(XMLObject): class FTPConnector(XMLObject):
# CMF Type Definition # CMF Type Definition
meta_type = 'FTP Connector' meta_type = 'FTP Connector'
...@@ -111,3 +112,25 @@ class FTPConnector(XMLObject): ...@@ -111,3 +112,25 @@ class FTPConnector(XMLObject):
conn.writeFile(remotepath, '%s' % filename, data, confirm=confirm) conn.writeFile(remotepath, '%s' % filename, data, confirm=confirm)
finally: finally:
conn.logout() conn.logout()
def createDirectory(self, path, mode=0777):
"""Create a directory `path`, with file mode `mode`.
The directory is created immediatly, even if transaction is aborted.
"""
conn = self.getConnection()
try:
conn.createDirectory(path, mode)
finally:
conn.logout()
def removeDirectory(self, path):
"""Create a directory `path`, with file mode `mode`.
The directory is removed immediatly, even if transaction is aborted.
"""
conn = self.getConnection()
try:
conn.removeDirectory(path)
finally:
conn.logout()
\ No newline at end of file
...@@ -92,6 +92,12 @@ class TestSFTPConnection(ERP5TypeTestCase): ...@@ -92,6 +92,12 @@ class TestSFTPConnection(ERP5TypeTestCase):
self.connection.listFiles(".", sort_on="st_size") self.connection.listFiles(".", sort_on="st_size")
) )
def test_create_remove_directory(self):
self.connection.createDirectory("foo")
self.assertItemsEqual(["foo"], self.connection.listFiles("."))
self.connection.removeDirectory("foo")
self.assertItemsEqual([], self.connection.listFiles("."))
else: else:
def test_no_SFTP_URL_in_environ(self): def test_no_SFTP_URL_in_environ(self):
raise unittest.SkipTest( raise unittest.SkipTest(
......
...@@ -171,6 +171,16 @@ class SFTPConnection: ...@@ -171,6 +171,16 @@ class SFTPConnection:
raise SFTPError('%s while trying to rename "%s" to "%s" on %s.' % \ raise SFTPError('%s while trying to rename "%s" to "%s" on %s.' % \
(str(msg), old_path, new_path, self.url)) (str(msg), old_path, new_path, self.url))
def createDirectory(self, path, mode=0777):
"""Create a directory `path` with mode `mode`.
"""
return self.conn.mkdir(path, mode)
def removeDirectory(self, path):
"""Remove directory `path`.
"""
return self.conn.rmdir(path)
def logout(self): def logout(self):
"""Logout of the SFTP Server""" """Logout of the SFTP Server"""
self.conn.close() self.conn.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment