mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-25 18:08:42 -06:00
Flake8 fix
This commit is contained in:
parent
1cfaf44b25
commit
a23f15166f
@ -44,4 +44,4 @@
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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')]
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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))
|
Loading…
Reference in New Issue
Block a user