diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 198a3a17407..fbdb477d211 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -53,6 +53,8 @@ import string import netsvc import re +import pickle + import fields import tools @@ -432,7 +434,7 @@ class orm_template(object): return datas def import_data(self, cr, uid, fields, datas, mode='init', - current_module=None, noupdate=False, context=None): + current_module=None, noupdate=False, context=None, filename=None): if not context: context = {} fields = map(lambda x: x.split('/'), fields) @@ -591,7 +593,10 @@ class orm_template(object): fields_def = self.fields_get(cr, uid, context=context) done = 0 + initial_size = len(datas) + counter = 0 while len(datas): + counter += 1 res = {} #try: (res, other, warning, translate, data_id) = \ @@ -606,8 +611,12 @@ class orm_template(object): context2 = context.copy() context2['lang'] = lang self.write(cr, uid, [id], translate[lang], context2) - if config.get('import_partial', False): + if config.get('import_partial', False) and filename: # and (not (counter%100)) : + data = pickle.load(file(config.get('import_partial'))) + data[filename] = initial_size - len(datas) + data.get(filename, 0) + pickle.dump(data, file(config.get('import_partial'),'wb')) cr.commit() + #except Exception, e: # logger.notifyChannel("import", netsvc.LOG_ERROR, e) # cr.rollback() diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 626052c060d..1cf3b9b3db9 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -724,6 +724,10 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', pool = pooler.get_pool(cr.dbname) + input = StringIO.StringIO(csvcontent) + reader = csv.reader(input, quotechar='"', delimiter=',') + fields = reader.next() + import pickle if config.get('import_partial'): if not os.path.isfile(config.get('import_partial')): @@ -732,10 +736,9 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', if fname in data: if not data[fname]: return - - input = StringIO.StringIO(csvcontent) - reader = csv.reader(input, quotechar='"', delimiter=',') - fields = reader.next() + else: + for i in range(data[fname]): + reader.next() if not (mode == 'init' or 'id' in fields): return @@ -746,7 +749,7 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', if (not line) or not reduce(lambda x,y: x or y, line) : continue datas.append( map(lambda x:x.decode('utf8').encode('utf8'), line)) - pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate) + pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate,filename=fname) if config.get('import_partial'): data = pickle.load(file(config.get('import_partial'))) data[fname] = 0