Commit e0c4f0fe authored by Jérome Perrin's avatar Jérome Perrin

createDirectory an removeDirectory operations for sFTP

/reviewed-on https://lab.nexedi.com/nexedi/erp5-capago/merge_requests/27
parents fbc06a5f a9f898c1
......@@ -32,6 +32,7 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces
from Products.ERP5Type.XMLObject import XMLObject
class FTPConnector(XMLObject):
# CMF Type Definition
meta_type = 'FTP Connector'
......@@ -112,3 +113,25 @@ class FTPConnector(XMLObject):
conn.writeFile(remotepath, '%s' % filename, data, confirm=confirm)
finally:
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):
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:
def test_no_SFTP_URL_in_environ(self):
raise unittest.SkipTest(
......
......@@ -171,6 +171,16 @@ class SFTPConnection:
raise SFTPError('%s while trying to rename "%s" to "%s" on %s.' % \
(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):
"""Logout of the SFTP Server"""
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