From ade3a27b7dabcbcdd8a78e8e6788a188f36a7570 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Mon, 27 Apr 2015 11:34:07 +0200 Subject: [PATCH] Fix flake8 --- external_file_location/$ | 61 ++++++++++++++++++ .../.ropeproject/globalnames | Bin 1178 -> 1442 bytes external_file_location/.ropeproject/objectdb | 4 +- external_file_location/tasks/ftp.py | 9 ++- external_file_location/tasks/sftp.py | 17 +++-- 5 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 external_file_location/$ diff --git a/external_file_location/$ b/external_file_location/$ new file mode 100644 index 00000000..7243ff70 --- /dev/null +++ b/external_file_location/$ @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +import mock +from contextlib import contextmanager + +class ConnMock(object): + + def __init__(self, response): + import ipdb; ipdb.set_trace() + self.response = response + + def isfile(self, path): + return self.response['isfile'] + + def makedir(self, path): + return self.response['makedir'] + + def exists(self, path): + return self.response['exists'] + + def open(self, path, mode): + return self.response['open'] + + def listdir(self, path): + return self.response['listdir'] + + def remove(self, path): + return self.response['remove'] + + def rename(self, source_path, target_path): + return self.response['rename'] + + def __call__(self, *args, **kwargs): + return self + + def __exit__(self, *args, **kwargs): + pass + +@contextmanager +def sftp_mock(response): + with mock.patch('fs.sftpfs.SFTPFS', ConnMock(response)) as SFTPFS: + yield diff --git a/external_file_location/.ropeproject/globalnames b/external_file_location/.ropeproject/globalnames index 77059482afb7beb31322ea175a3a19aec3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s&=|4`{tD&~hBq{~q9*#QnIbOkg&93WkVrGD@~foqWG ze&Xdi_0p!CR1v!DTXFwiTh{GOwlzOoO*m7eX>gcc8TE2A%Lw zq_MjQ6QOF_Jp=MlJa(&eAM&V#ReLHKwn7g;Z<*$Xy#_n<5DFq-(|XbrT0srg&a zG|a|2nV@I2A=RMRv>V&8r)~NG`tU*@VUlC~cS#L(C~%C01bxb~W0xDLVYO+ri7=VY zsYrHs%Yf;YI*n~^BSpqmcU!qqoMe8R2s5cbJheiqfwkzfp|)LJTk$oa?ZEs97}IWz i!DA1!l`A#$%<1_UNQ(d#>byDvwoo#)xs1NBe&r8a9-w^y diff --git a/external_file_location/.ropeproject/objectdb b/external_file_location/.ropeproject/objectdb index 29c40cda..cddbe847 100644 --- a/external_file_location/.ropeproject/objectdb +++ b/external_file_location/.ropeproject/objectdb @@ -1 +1,3 @@ -€}q. \ No newline at end of file +€}q(Utests/test_sftp.pyq}U/usr/lib/python2.7/tempfile.py}qUNamedTemporaryFilecrope.base.oi.memorydb +ScopeInfo +q)q}q(Unone…qhhhhUunknown…tUinstanceUdefinedU/usr/lib/python2.7/tempfile.pyU_TemporaryFileWrapper‡†s}q†bsu. \ No newline at end of file diff --git a/external_file_location/tasks/ftp.py b/external_file_location/tasks/ftp.py index d480f2fa..928be2ea 100644 --- a/external_file_location/tasks/ftp.py +++ b/external_file_location/tasks/ftp.py @@ -42,7 +42,8 @@ class FtpImportTask(FtpTask): _synchronize_type = 'import' def run(self): - with ftpfs.FTPFS(self.host, self.user, self.pwd, port=self.port) as ftp_conn: + with ftpfs.FTPFS(self.host, self.user, self.pwd, + port=self.port) as ftp_conn: files_to_process = self._get_files(ftp_conn, self.path) for file_to_process in files_to_process: self._process_file(ftp_conn, file_to_process) @@ -57,10 +58,8 @@ class FtpExportTask(FtpTask): if attachment.state in ('pending', 'failed'): self.attachment_id = attachment with ftpfs.FTPFS(self.host, self.user, self.pwd, - port=self.port) as ftp_conn: + port=self.port) as ftp_conn: self._upload_file(ftp_conn, self.host, self.port, - self.user, - self.pwd, - self.path, + self.user, self.pwd, self.path, attachment.datas_fname, b64decode(attachment.datas)) diff --git a/external_file_location/tasks/sftp.py b/external_file_location/tasks/sftp.py index 25f0a53d..f4bacd8f 100644 --- a/external_file_location/tasks/sftp.py +++ b/external_file_location/tasks/sftp.py @@ -44,8 +44,10 @@ class SftpImportTask(SftpTask): def run(self): connection_string = "{}:{}".format(self.host, self.port) root = "/home/{}".format(self.user) - with sftpfs.SFTPFS(connection=connection_string, root_path=root, - username=self.user, password=self.pwd) as sftp_conn: + with sftpfs.SFTPFS(connection=connection_string, + root_path=root, + username=self.user, + password=self.pwd) as sftp_conn: files_to_process = self._get_files(sftp_conn, self.path) for file_to_process in files_to_process: self._process_file(sftp_conn, file_to_process) @@ -61,12 +63,9 @@ class SftpExportTask(SftpTask): self.attachment_id = attachment connection_string = "{}:{}".format(self.host, self.port) with sftpfs.SFTPFS(connection=connection_string, - username=self.user, - password=self.pwd) as sftp_conn: + username=self.user, + password=self.pwd) as sftp_conn: datas = b64decode(attachment.datas) self._upload_file(sftp_conn, self.host, self.port, - self.user, - self.pwd, - self.path, - attachment.datas_fname, - datas) + self.user, self.pwd, self.path, + attachment.datas_fname, datas)