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

web_service: support createDirectory / removeDirectory for sFTP

parent 52a046a9
...@@ -113,3 +113,25 @@ class FTPConnector(XMLObject): ...@@ -113,3 +113,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