~therp-nl/openobject-server/trunk_lp1188136

« back to all changes in this revision

Viewing changes to openerp/tools/convert.py

  • Committer: Antony Lesuisse
  • Date: 2013-09-09 10:55:23 UTC
  • Revision ID: al@openerp.com-20130909105523-jkffhy5gr34k25hr
[MERGE] data file loading refactoring, ready for code autoreload

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import openerp
34
34
import openerp.release
35
35
import openerp.workflow
 
36
from yaml_import import convert_yaml_import
36
37
 
37
38
import assertion_report
38
39
 
877
878
            'url': self._tag_url
878
879
        }
879
880
 
 
881
def convert_file(cr, module, filename, idref, mode='update', noupdate=False, kind=None, report=None):
 
882
    pathname = os.path.join(module, filename)
 
883
    fp = misc.file_open(pathname)
 
884
    ext = os.path.splitext(filename)[1].lower()
 
885
    try:
 
886
        if ext == '.csv':
 
887
            convert_csv_import(cr, module, pathname, fp.read(), idref, mode, noupdate)
 
888
        elif ext == '.sql':
 
889
            convert_sql_import(cr, fp)
 
890
        elif ext == '.yml':
 
891
            convert_yaml_import(cr, module, fp, kind, idref, mode, noupdate, report)
 
892
        elif ext == '.xml':
 
893
            convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
 
894
        elif ext == '.js':
 
895
            pass # .js files are valid but ignored here.
 
896
        else:
 
897
            _logger.warning("Can't load unknown file type %s.", filename)
 
898
    finally:
 
899
        fp.close()
 
900
 
 
901
def convert_sql_import(cr, fp):
 
902
    queries = fp.read().split(';')
 
903
    for query in queries:
 
904
        new_query = ' '.join(query.split())
 
905
        if new_query:
 
906
            cr.execute(new_query)
 
907
 
880
908
def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
881
909
        noupdate=False):
882
910
    '''Import csv file :