diff --git a/external_file_location/abstract_task.py b/external_file_location/abstract_task.py index b1016fac..f8fe3237 100644 --- a/external_file_location/abstract_task.py +++ b/external_file_location/abstract_task.py @@ -6,6 +6,11 @@ from base64 import b64encode class AbstractTask(object): + _name = None + _key = None + _synchronize_type = None + _default_port = None + def create_file(self, filename, data): ir_attachment_id = self.env['ir.attachment.metadata'].create({ 'name': filename, diff --git a/external_file_location/task.py b/external_file_location/task.py index 69a1294f..bdf3e66a 100644 --- a/external_file_location/task.py +++ b/external_file_location/task.py @@ -50,11 +50,10 @@ class Task(models.Model): return [('move', 'Move'), ('delete', 'Delete')] def _get_method(self): - print 'get method' res = [] for cls in itersubclasses(AbstractTask): - if cls._synchronize_type: #\ - # and cls._key == self._context.get('protocol'): + if cls._synchronize_type: # \ + # and cls._key == self._context.get('protocol'): cls_info = (cls._key + '_' + cls._synchronize_type, cls._name + ' ' + cls._synchronize_type) res.append(cls_info) diff --git a/external_file_location/tasks/abstract_fs.py b/external_file_location/tasks/abstract_fs.py index d3e1a1d2..44cfd396 100644 --- a/external_file_location/tasks/abstract_fs.py +++ b/external_file_location/tasks/abstract_fs.py @@ -20,7 +20,6 @@ ############################################################################## from ..abstract_task import AbstractTask -from base64 import b64decode import logging import os _logger = logging.getLogger(__name__) @@ -31,6 +30,7 @@ class AbstractFSTask(AbstractTask): _name = None _key = None _synchronize_type = None + _default_port = None def __init__(self, env, config): self.env = env @@ -53,7 +53,7 @@ class AbstractFSTask(AbstractTask): """open and read given file into create_file method, move file if move_directory is given""" with fs_conn.open(self._source_name(download_directory, file_name), - "rb") as fileobj: + "rb") as fileobj: data = fileobj.read() return self.create_file(file_name, data) @@ -127,7 +127,8 @@ class AbstractFSTask(AbstractTask): def _target_name(self, fs_conn, upload_directory, filename): return os.path.join(upload_directory, filename) - def _upload_file(self, conn, host, port, user, pwd, path, filename, filedata): + def _upload_file(self, conn, host, port, user, pwd, + path, filename, filedata): upload_directory = path or '.' target_name = self._target_name(conn, upload_directory, diff --git a/external_file_location/tasks/filestore.py b/external_file_location/tasks/filestore.py index 8dce3d52..6278e6e5 100644 --- a/external_file_location/tasks/filestore.py +++ b/external_file_location/tasks/filestore.py @@ -21,11 +21,8 @@ from .abstract_fs import AbstractFSTask from base64 import b64decode -import fs from fs.osfs import OSFS -from ftputil.error import FTPIOError import logging -import os _logger = logging.getLogger(__name__) @@ -70,12 +67,12 @@ class FileStoreExportTask(FileStoreTask): for attachment in self.attachment_ids: if attachment.state in ('pending', 'failed'): self.attachment_id = attachment - with OSFS(host) as fs_conn: + with OSFS(self.host) as fs_conn: self._upload_file(fs_conn, - self.host, - self.port, - self.user, + self.host, + self.port, + self.user, self.pwd, self.path, attachment.datas_fname, - b64decode(attachment.datas)) + b64decode(attachment.datas)) diff --git a/external_file_location/tasks/ftp.py b/external_file_location/tasks/ftp.py index 2e58493a..37477b5f 100644 --- a/external_file_location/tasks/ftp.py +++ b/external_file_location/tasks/ftp.py @@ -23,7 +23,6 @@ from .abstract_fs import AbstractFSTask from base64 import b64decode from fs.ftpfs import FTPFS import logging -import os _logger = logging.getLogger(__name__) @@ -68,7 +67,7 @@ class FtpExportTask(FtpTask): for attachment in self.attachment_ids: if attachment.state in ('pending', 'failed'): self.attachment_id = attachment - with FTPFS(self.host, self.user, self.pwd, + with FTPFS(self.host, self.user, self.pwd, port=self.port) as ftp_conn: self._upload_file(ftp_conn, self.host, self.port, self.user, diff --git a/external_file_location/tasks/sftp.py b/external_file_location/tasks/sftp.py index 1f62472f..e061c3cc 100644 --- a/external_file_location/tasks/sftp.py +++ b/external_file_location/tasks/sftp.py @@ -23,7 +23,6 @@ from .abstract_fs import AbstractFSTask from base64 import b64decode from fs.sftpfs import SFTPFS import logging -import os _logger = logging.getLogger(__name__) @@ -72,9 +71,8 @@ class SftpExportTask(SftpTask): if attachment.state in ('pending', 'failed'): self.attachment_id = attachment connection_string = "{}:{}".format(self.host, self.port) - root = "/home/{}".format(self.user) - with SFTPFS(connection=connection_string, root_path=root, - username=self.user, + with SFTPFS(connection=connection_string, + username=self.user, password=self.pwd) as sftp_conn: self._upload_file(sftp_conn, self.host, self.port, self.user,