1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 """ This is a testing module, which exports some functions for the YAML tests.
23 Instead of repeating the same FTP code all over, we prefer to have
27 from ftplib import FTP
28 from tools import config
30 def get_plain_ftp(timeout=10.0):
32 host = config.get('ftp_server_host', '127.0.0.1')
33 port = config.get('ftp_server_port', '8021')
34 ftp.connect(host, port,timeout)
37 def get_ftp_login(cr, uid, ormobj):
39 user = ormobj.pool.get('res.users').browse(cr, uid, uid)
40 passwd = user.password or ''
41 if passwd.startswith("$1$"):
42 # md5 by base crypt. We cannot decode, wild guess
45 ftp.login(user.login, passwd)
46 ftp.cwd("/" + cr.dbname)
49 def get_ftp_anonymous(cr):
51 ftp.login('anonymous', 'the-test')
55 def get_ftp_folder(cr, uid, ormobj, foldername):
56 ftp = get_ftp_login(cr, uid, ormobj)
57 ftp.cwd("/" + cr.dbname+"/"+foldername)
60 def get_ftp_fulldata(ftp, fname, limit=8192):
61 from functools import partial
64 if len(data)+ len(ndata) > limit:
65 raise IndexError('Data over the limit')
67 ftp.retrbinary('RETR %s' % fname, partial(ffp,data))
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: