X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=openerp%2Ftools%2Fconvert.py;h=47f75e43fe8042e8a095d3b8f18c85b74279cf68;hb=f9b6ff07609995a1264d02624e53b82403c393cb;hp=616abb23fa70218c883e2695ea3d6d7e023d31f0;hpb=dea9c95ab71495255ceecb8e034014432c6ef28e;p=odoo%2Fodoo.git diff --git a/openerp/tools/convert.py b/openerp/tools/convert.py index 616abb2..47f75e4 100644 --- a/openerp/tools/convert.py +++ b/openerp/tools/convert.py @@ -33,6 +33,7 @@ import time import openerp import openerp.release import openerp.workflow +from yaml_import import convert_yaml_import import assertion_report @@ -877,6 +878,33 @@ form: module.record_id""" % (xml_id,) 'url': self._tag_url } +def convert_file(cr, module, filename, idref, mode='update', noupdate=False, kind=None, report=None): + pathname = os.path.join(module, filename) + fp = misc.file_open(pathname) + ext = os.path.splitext(filename)[1].lower() + try: + if ext == '.csv': + convert_csv_import(cr, module, pathname, fp.read(), idref, mode, noupdate) + elif ext == '.sql': + convert_sql_import(cr, fp) + elif ext == '.yml': + convert_yaml_import(cr, module, fp, kind, idref, mode, noupdate, report) + elif ext == '.xml': + convert_xml_import(cr, module, fp, idref, mode, noupdate, report) + elif ext == '.js': + pass # .js files are valid but ignored here. + else: + _logger.warning("Can't load unknown file type %s.", filename) + finally: + fp.close() + +def convert_sql_import(cr, fp): + queries = fp.read().split(';') + for query in queries: + new_query = ' '.join(query.split()) + if new_query: + cr.execute(new_query) + def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', noupdate=False): '''Import csv file :