mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-26 18:38:41 -06:00
Fix flake8
This commit is contained in:
parent
6e9e9fff5a
commit
ade3a27b7d
61
external_file_location/$
Normal file
61
external_file_location/$
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Akretion (http://www.akretion.com).
|
||||||
|
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
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
|
Binary file not shown.
@ -1 +1,3 @@
|
|||||||
<EFBFBD>}q.
|
€}q(Utests/test_sftp.pyq}U/usr/lib/python2.7/tempfile.py}qUNamedTemporaryFilecrope.base.oi.memorydb
|
||||||
|
ScopeInfo
|
||||||
|
q)<29>q}q(Unone…qhhhhUunknown…tUinstanceUdefinedU/usr/lib/python2.7/tempfile.pyU_TemporaryFileWrapper‡†s}q†bsu.
|
@ -42,7 +42,8 @@ class FtpImportTask(FtpTask):
|
|||||||
_synchronize_type = 'import'
|
_synchronize_type = 'import'
|
||||||
|
|
||||||
def run(self):
|
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)
|
files_to_process = self._get_files(ftp_conn, self.path)
|
||||||
for file_to_process in files_to_process:
|
for file_to_process in files_to_process:
|
||||||
self._process_file(ftp_conn, file_to_process)
|
self._process_file(ftp_conn, file_to_process)
|
||||||
@ -59,8 +60,6 @@ class FtpExportTask(FtpTask):
|
|||||||
with ftpfs.FTPFS(self.host, self.user, self.pwd,
|
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._upload_file(ftp_conn, self.host, self.port,
|
||||||
self.user,
|
self.user, self.pwd, self.path,
|
||||||
self.pwd,
|
|
||||||
self.path,
|
|
||||||
attachment.datas_fname,
|
attachment.datas_fname,
|
||||||
b64decode(attachment.datas))
|
b64decode(attachment.datas))
|
||||||
|
@ -44,8 +44,10 @@ class SftpImportTask(SftpTask):
|
|||||||
def run(self):
|
def run(self):
|
||||||
connection_string = "{}:{}".format(self.host, self.port)
|
connection_string = "{}:{}".format(self.host, self.port)
|
||||||
root = "/home/{}".format(self.user)
|
root = "/home/{}".format(self.user)
|
||||||
with sftpfs.SFTPFS(connection=connection_string, root_path=root,
|
with sftpfs.SFTPFS(connection=connection_string,
|
||||||
username=self.user, password=self.pwd) as sftp_conn:
|
root_path=root,
|
||||||
|
username=self.user,
|
||||||
|
password=self.pwd) as sftp_conn:
|
||||||
files_to_process = self._get_files(sftp_conn, self.path)
|
files_to_process = self._get_files(sftp_conn, self.path)
|
||||||
for file_to_process in files_to_process:
|
for file_to_process in files_to_process:
|
||||||
self._process_file(sftp_conn, file_to_process)
|
self._process_file(sftp_conn, file_to_process)
|
||||||
@ -65,8 +67,5 @@ class SftpExportTask(SftpTask):
|
|||||||
password=self.pwd) as sftp_conn:
|
password=self.pwd) as sftp_conn:
|
||||||
datas = b64decode(attachment.datas)
|
datas = b64decode(attachment.datas)
|
||||||
self._upload_file(sftp_conn, self.host, self.port,
|
self._upload_file(sftp_conn, self.host, self.port,
|
||||||
self.user,
|
self.user, self.pwd, self.path,
|
||||||
self.pwd,
|
attachment.datas_fname, datas)
|
||||||
self.path,
|
|
||||||
attachment.datas_fname,
|
|
||||||
datas)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user