mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-25 18:08:42 -06:00
[FIX] pep8 fixes
This commit is contained in:
parent
8dcb2a1fbf
commit
d8e4bbc161
@ -26,7 +26,8 @@
|
||||
'name': 'Shared Repositories (FTP)',
|
||||
'version': '8.0.0.0.1',
|
||||
'category': 'Knowledge Management',
|
||||
'author': 'OpenERP SA',
|
||||
'author': 'Community Association (OCA)',
|
||||
"license": "AGPL-3",
|
||||
'website': 'http://www.openerp.com',
|
||||
'depends': ['base', 'document'],
|
||||
'data': [
|
||||
@ -42,7 +43,9 @@
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'images': ['images/1_configure_ftp.jpeg', 'images/2_document_browse.jpeg', 'images/3_document_ftp.jpeg'],
|
||||
'images': ['images/1_configure_ftp.jpeg',
|
||||
'images/2_document_browse.jpeg',
|
||||
'images/3_document_ftp.jpeg'],
|
||||
'post_load': 'post_load',
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,9 @@
|
||||
import threading
|
||||
import logging
|
||||
|
||||
import authorizer
|
||||
import abstracted_fs
|
||||
import ftpserver
|
||||
import document_ftp.ftpserver.Authorizer
|
||||
import document_ftp.ftpserver.AbstractedFs
|
||||
import document_ftp.ftpserver.ftpserver
|
||||
|
||||
import openerp
|
||||
from openerp.tools import config
|
||||
@ -37,7 +37,8 @@ def start_server():
|
||||
if openerp.multi_process:
|
||||
_logger.info("FTP disabled in multiprocess mode")
|
||||
return
|
||||
ip_address = ([(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])
|
||||
ip_address = ([(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) \
|
||||
for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])
|
||||
if not ip_address:
|
||||
ip_address = '127.0.0.1'
|
||||
HOST = config.get('ftp_server_host', str(ip_address))
|
||||
@ -47,10 +48,10 @@ def start_server():
|
||||
if len(pps) == 2:
|
||||
PASSIVE_PORTS = int(pps[0]), int(pps[1])
|
||||
|
||||
class ftp_server(threading.Thread):
|
||||
class FtpServer(threading.Thread):
|
||||
|
||||
def run(self):
|
||||
autho = authorizer.authorizer()
|
||||
autho = authorizer.Authorizer()
|
||||
ftpserver.FTPHandler.authorizer = autho
|
||||
ftpserver.max_cons = 300
|
||||
ftpserver.max_cons_per_ip = 50
|
||||
@ -69,6 +70,6 @@ def start_server():
|
||||
_logger.info("\n Server FTP Not Started\n")
|
||||
else:
|
||||
_logger.info("\n Serving FTP on %s:%s\n" % (HOST, PORT))
|
||||
ds = ftp_server()
|
||||
ds = FtpServer()
|
||||
ds.daemon = True
|
||||
ds.start()
|
||||
|
@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import time
|
||||
@ -11,7 +11,6 @@ import fnmatch
|
||||
|
||||
from openerp import pooler, netsvc, sql_db
|
||||
from openerp.service import security
|
||||
from openerp.osv import osv
|
||||
|
||||
from openerp.addons.document.document import get_node_context
|
||||
|
||||
@ -30,10 +29,10 @@ def _get_month_name(month):
|
||||
elif month == 11:return 'Nov'
|
||||
elif month == 12:return 'Dec'
|
||||
|
||||
from ftpserver import _to_decode, _to_unicode
|
||||
from document_ftp.ftpserver.ftpserver import _to_decode, _to_unicode
|
||||
|
||||
|
||||
class abstracted_fs(object):
|
||||
class AbstractedFs(object):
|
||||
"""A class used to interact with the file system, providing a high
|
||||
level, cross-platform interface compatible with both Windows and
|
||||
UNIX style filesystems.
|
||||
@ -190,21 +189,19 @@ class abstracted_fs(object):
|
||||
"""
|
||||
raise NotImplementedError # TODO
|
||||
|
||||
text = not 'b' in mode
|
||||
# for unique file , maintain version if duplicate file
|
||||
if dir:
|
||||
cr = dir.cr
|
||||
uid = dir.uid
|
||||
pool = pooler.get_pool(node.context.dbname)
|
||||
object = dir and dir.object or False
|
||||
object2 = dir and dir.object2 or False
|
||||
res = pool.get('ir.attachment').search(cr, uid, [('name', 'like', prefix), ('parent_id', '=', object and object.type in ('directory', 'ressource') and object.id or False), ('res_id', '=', object2 and object2.id or False), ('res_model', '=', object2 and object2._name or False)])
|
||||
if len(res):
|
||||
pre = prefix.split('.')
|
||||
prefix = pre[0] + '.v' + str(len(res)) + '.' + pre[1]
|
||||
return self.create(dir, suffix + prefix, text)
|
||||
|
||||
|
||||
# text = not 'b' in mode
|
||||
# # for unique file , maintain version if duplicate file
|
||||
# if dir:
|
||||
# cr = dir.cr
|
||||
# uid = dir.uid
|
||||
# pool = pooler.get_pool(node.context.dbname)
|
||||
# object = dir and dir.object or False
|
||||
# object2 = dir and dir.object2 or False
|
||||
# res = pool.get('ir.attachment').search(cr, uid, [('name', 'like', prefix), ('parent_id', '=', object and object.type in ('directory', 'ressource') and object.id or False), ('res_id', '=', object2 and object2.id or False), ('res_model', '=', object2 and object2._name or False)])
|
||||
# if len(res):
|
||||
# pre = prefix.split('.')
|
||||
# prefix = pre[0] + '.v' + str(len(res)) + '.' + pre[1]
|
||||
# return self.create(dir, suffix + prefix, text)
|
||||
|
||||
# Ok
|
||||
def chdir(self, datacr):
|
||||
@ -341,7 +338,7 @@ class abstracted_fs(object):
|
||||
|
||||
def listdir(self, datacr):
|
||||
"""List the content of a directory."""
|
||||
class false_node(object):
|
||||
class FalseNode(object):
|
||||
write_date = 0.0
|
||||
create_date = 0.0
|
||||
unixperms = 040550
|
||||
@ -357,8 +354,8 @@ class abstracted_fs(object):
|
||||
result = []
|
||||
for db in self.db_list():
|
||||
try:
|
||||
result.append(false_node(db))
|
||||
except osv.except_osv:
|
||||
result.append(FalseNode(db))
|
||||
except:
|
||||
pass
|
||||
return result
|
||||
cr, node, rem = datacr
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
class authorizer:
|
||||
class Authorizer:
|
||||
read_perms = "elr"
|
||||
write_perms = "adfmw"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# ftpserver.py
|
||||
#
|
||||
# pyftpdlib is released under the MIT license, reproduced below:
|
||||
@ -1579,29 +1579,29 @@ class FTPHandler(asynchat.async_chat):
|
||||
|
||||
def __check_perm(self, cmd, line, datacr):
|
||||
"""Check permissions depending on issued command."""
|
||||
map = {'CWD':'e', 'XCWD':'e', 'CDUP':'e', 'XCUP':'e',
|
||||
'LIST':'l', 'NLST':'l', 'MLSD':'l', 'STAT':'l',
|
||||
'RETR':'r',
|
||||
'APPE':'a',
|
||||
'DELE':'d', 'RMD':'d', 'XRMD':'d',
|
||||
'RNFR':'f',
|
||||
'MKD':'m', 'XMKD':'m',
|
||||
'STOR':'w'}
|
||||
map = {'CWD': 'e', 'XCWD':'e', 'CDUP':'e', 'XCUP':'e',
|
||||
'LIST': 'l', 'NLST':'l', 'MLSD':'l', 'STAT':'l',
|
||||
'RETR': 'r',
|
||||
'APPE': 'a',
|
||||
'DELE': 'd', 'RMD':'d', 'XRMD':'d',
|
||||
'RNFR': 'f',
|
||||
'MKD': 'm', 'XMKD':'m',
|
||||
'STOR': 'w'}
|
||||
raise NotImplementedError
|
||||
if cmd in map:
|
||||
if cmd == 'STAT' and not line:
|
||||
return True
|
||||
perm = map[cmd]
|
||||
if not line and (cmd in ('LIST', 'NLST', 'MLSD')):
|
||||
path = self.fs.ftp2fs(self.fs.cwd, datacr)
|
||||
else:
|
||||
path = self.fs.ftp2fs(line, datacr)
|
||||
if not self.authorizer.has_perm(self.username, perm, path):
|
||||
self.log('FAIL %s "%s". Not enough privileges.' \
|
||||
% (cmd, self.fs.ftpnorm(line)))
|
||||
self.respond("550 Can't %s. Not enough privileges." % cmd)
|
||||
return False
|
||||
return True
|
||||
# if cmd in map:
|
||||
# if cmd == 'STAT' and not line:
|
||||
# return True
|
||||
# perm = map[cmd]
|
||||
# if not line and (cmd in ('LIST', 'NLST', 'MLSD')):
|
||||
# path = self.fs.ftp2fs(self.fs.cwd, datacr)
|
||||
# else:
|
||||
# path = self.fs.ftp2fs(line, datacr)
|
||||
# if not self.authorizer.has_perm(self.username, perm, path):
|
||||
# self.log('FAIL %s "%s". Not enough privileges.' \
|
||||
# % (cmd, self.fs.ftpnorm(line)))
|
||||
# self.respond("550 Can't %s. Not enough privileges." % cmd)
|
||||
# return False
|
||||
# return True
|
||||
|
||||
def handle_expt(self):
|
||||
"""Called when there is out of band (OOB) data for the socket
|
||||
@ -2098,7 +2098,7 @@ class FTPHandler(asynchat.async_chat):
|
||||
data = ''
|
||||
if listing:
|
||||
listing.sort()
|
||||
data = ''.join([ _to_decode(x) + '\r\n' for x in listing ])
|
||||
data = ''.join([_to_decode(x) + '\r\n' for x in listing])
|
||||
self.log('OK NLST "%s". Transfer starting.' % line)
|
||||
self.push_dtp_data(data)
|
||||
|
||||
@ -2287,7 +2287,7 @@ class FTPHandler(asynchat.async_chat):
|
||||
basedir = self.fs.ftp2fs(self.fs.cwd, datacr)
|
||||
prefix = 'ftpd.'
|
||||
try:
|
||||
fd = self.try_as_current_user(self.fs.mkstemp, kwargs={'prefix':prefix,
|
||||
fd = self.try_as_current_user(self.fs.mkstemp, kwargs={'prefix': prefix,
|
||||
'dir': basedir}, line=line)
|
||||
except FTPExceptionSent:
|
||||
self.fs.close_cr(datacr)
|
||||
@ -2480,7 +2480,6 @@ class FTPHandler(asynchat.async_chat):
|
||||
# code to be given in this case, but this is wrong...
|
||||
self.respond("230 Ready for new user.")
|
||||
|
||||
|
||||
# --- filesystem operations
|
||||
|
||||
def ftp_PWD(self, line):
|
||||
|
@ -24,12 +24,12 @@
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools import config
|
||||
|
||||
class documnet_ftp_setting(osv.osv_memory):
|
||||
class DocumentFtpSetting(osv.osv_memory):
|
||||
_name = 'knowledge.config.settings'
|
||||
_inherit = 'knowledge.config.settings'
|
||||
_columns = {
|
||||
'ftp_server_host' : fields.char(string='Host'),
|
||||
'ftp_server_port' : fields.char(string='Port'),
|
||||
'ftp_server_host': fields.char(string='Host'),
|
||||
'ftp_server_port': fields.char(string='Port'),
|
||||
'document_ftp_url': fields.char('Browse Documents', size=128,
|
||||
help="""Click the url to browse the documents""", readonly=True),
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
from openerp.osv import fields, osv
|
||||
from .. import ftpserver
|
||||
|
||||
class document_ftp_browse(osv.osv_memory):
|
||||
class DocumentFtpBrowse(osv.osv_memory):
|
||||
_name = 'document.ftp.browse'
|
||||
_description = 'Document FTP Browse'
|
||||
|
||||
@ -61,5 +61,5 @@ class document_ftp_browse(osv.osv_memory):
|
||||
'target': 'new'
|
||||
}
|
||||
|
||||
document_ftp_browse()
|
||||
DocumentFtpBrowse()
|
||||
|
||||
|
@ -22,9 +22,10 @@
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.osv.orm import TransientModel
|
||||
from openerp.tools import config
|
||||
|
||||
class document_ftp_configuration(osv.osv_memory):
|
||||
class DocumentFtpConfiguration(TransientModel):
|
||||
|
||||
_name = 'document.ftp.configuration'
|
||||
_description = 'Auto Directory Configuration'
|
||||
@ -49,5 +50,5 @@ class document_ftp_configuration(osv.osv_memory):
|
||||
self.pool.get('ir.actions.act_url').write(cr, uid, [aid],
|
||||
{'url': 'ftp://' + (conf.host or 'localhost:8021') + '/' + cr.dbname + '/'})
|
||||
|
||||
document_ftp_configuration()
|
||||
DocumentFtpConfiguration()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user