From a23f15166f4e7793c2a8252b24bb346668e61a73 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Mon, 16 Mar 2015 10:27:16 +0100 Subject: [PATCH] Flake8 fix --- external_file_location/__openerp__.py | 2 +- external_file_location/helper.py | 7 ++- external_file_location/location.py | 3 +- external_file_location/task.py | 2 +- external_file_location/tasks/filestore.py | 73 ----------------------- external_file_location/tasks/sftp.py | 59 ------------------ 6 files changed, 7 insertions(+), 139 deletions(-) delete mode 100644 external_file_location/tasks/filestore.py delete mode 100644 external_file_location/tasks/sftp.py diff --git a/external_file_location/__openerp__.py b/external_file_location/__openerp__.py index 85177bf5..022bb2a8 100644 --- a/external_file_location/__openerp__.py +++ b/external_file_location/__openerp__.py @@ -44,4 +44,4 @@ ], 'installable': True, 'application': True, -} + } diff --git a/external_file_location/helper.py b/external_file_location/helper.py index f46e5f0d..6bfe08dc 100644 --- a/external_file_location/helper.py +++ b/external_file_location/helper.py @@ -19,6 +19,7 @@ # ############################################################################## + def itersubclasses(cls, _seen=None): """ itersubclasses(cls) @@ -43,13 +44,13 @@ def itersubclasses(cls, _seen=None): """ if not isinstance(cls, type): raise TypeError('itersubclasses must be called with ' - 'new-style classes, not %.100r' % cls - ) + 'new-style classes, not %.100r' % cls + ) if _seen is None: _seen = set() try: subs = cls.__subclasses__() - except TypeError: # fails only when cls is type + except TypeError: # fails only when cls is type subs = cls.__subclasses__(cls) for sub in subs: if sub not in _seen: diff --git a/external_file_location/location.py b/external_file_location/location.py index 81cbecbc..6d082c99 100644 --- a/external_file_location/location.py +++ b/external_file_location/location.py @@ -24,6 +24,7 @@ from openerp import models, fields, api from .abstract_task import AbstractTask from .helper import itersubclasses + class Location(models.Model): _name = 'external.file.location' _description = 'Description' @@ -36,7 +37,6 @@ class Location(models.Model): password = fields.Char() task_ids = fields.One2many('external.file.task', 'location_id') - def _get_protocol(self): res = [] for cls in itersubclasses(AbstractTask): @@ -50,4 +50,3 @@ class Location(models.Model): for cls in itersubclasses(AbstractTask): if cls._key == self.protocol: self.port = cls._default_port - diff --git a/external_file_location/task.py b/external_file_location/task.py index cca65cd4..11b5c955 100644 --- a/external_file_location/task.py +++ b/external_file_location/task.py @@ -45,7 +45,7 @@ class Task(models.Model): ' a md5 file') after_import = fields.Selection(selection='_get_action', help='Action after import a file') - + def _get_action(self): return [('move', 'Move'), ('delete', 'Delete')] diff --git a/external_file_location/tasks/filestore.py b/external_file_location/tasks/filestore.py deleted file mode 100644 index 302fc733..00000000 --- a/external_file_location/tasks/filestore.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from ..backend import AbstractTask -import sys -import os -from tempfile import TemporaryFile - - -class FileStore(AbstractTask): - _key = "filestore" - _name = "Filestore" - _synchronize_type = None - - def __init__(self, config): - # super(FilestoreConnection, self).__init__(host, user, pwd, port, allow_dir_creation) - self.host = config.get('host', '') - self.user = config.get('user', '') - self.pwd = config.get('pwd', '') - self.port = config.get('port', '') - self.allow_dir_creation = config.get('allow_dir_creation', '') - self.filename = config.get('filename', '') - self.path = config.get('path', '') - - def connect(self): - return NotImplemented - - def close(self): - return NotImplemented - - def get(self): - if self.path: - filepath = "{}/{}".format(self.path, self.filename) - else: - filepath = self.filename - return open(filepath, 'r+b') - - def put(self): - if self.path: - filepath = "{}/{}".format(self.path, self.filename) - else: - filepath = self.filename - output = open(filepath, 'w+b') - return True - - def search(self): - if self.path: - filepath = "{}/{}".format(self.path, self.filename) - else: - filepath = self.filename - connection_list_result = os.listdir(filepath) - return [x for x in connection_list_result if filename in x] - - -class ImportFileStore(FileStore): - _synchronize_type = "import" - - - def run(): - self.connect() - file = self.get(self.filename) - self.close() - return file - -class ExportFileStore(FileStore): - _synchronize_type = "export" - - - def run(): - self.connect() - self.put(self.filename) - self.close() - diff --git a/external_file_location/tasks/sftp.py b/external_file_location/tasks/sftp.py deleted file mode 100644 index 4d40b896..00000000 --- a/external_file_location/tasks/sftp.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys -import paramiko -import os -from tempfile import TemporaryFile - - -class SFTPConnection(AbstractConnection): - - def __init__(self, host, user, pwd, port=None, allow_dir_creation=False): - super(SFTPConnection, self).__init__(host, user, pwd, port, allow_dir_creation) - if not port: - self.port = 22 - self.protocol = "STFP" - - def connect(self): - self.ssh = paramiko.SSHClient() - self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - self.ssh.connect(self.host, self.port, self.user, self.pwd, compress=True) - self.connection = self.ssh.open_sftp() - - def close(self): - self.connection.close() - - def get(self, filename, path=None): - if path: - remotefile = "{}/{}".format(path, filename) - else: - remotefile = filename - localfile = filename - newfile = open(filename, 'w') - self.connection.getfo(remotefile, newfile) - return newfile - - def put(self, fileobject, filename, path=None): - if path: - remotefile = "{}/{}".format(path, filename) - else: - remotefile = filename - if self.allow_dir_creation: - self.connection.mkdirs(path) - oldfile = open(fileobj, 'r') - self.connection.putfo(oldfile, remotefile) - - def search(self, filename, path=None): - if path: - self.connection.chdir(path) - file_list = self.connection.listdir() - return [x for x in file_list if filename in x] - - def move(self, filename, oldpath, newpath): - self.connection.rename(os.path.join(oldpath, filename), os.path.join(newpath, filename)) - - def rename(self, oldfilename, newfilename, path=None): - if not path: - path = '' - self.connection.rename(os.path.join(path, oldfilename), os.path.join(path, newfilename))