Commit 2781646f authored by Jérome Perrin's avatar Jérome Perrin

web_service: support createDirectory / removeDirectory for sFTP

parent 2c550420
Pipeline #5544 failed with stage
......@@ -112,3 +112,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