import osv
import pooler
from config import config
+from tools.translate import _
from yaml_import import convert_yaml_import
+# List of etree._Element subclasses that we choose to ignore when parsing XML.
+from tools import SKIPPED_ELEMENT_TYPES
+
# Import of XML records requires the unsafe eval as well,
# almost everywhere, which is ok because it supposedly comes
# from trusted data, but at least we make it obvious now.
As a convention we'll surround multiple root with a container "data" element, to be
ignored later when parsing.
"""
-
- if len(node) > 1:
+ real_nodes = [x for x in node if not isinstance(x, SKIPPED_ELEMENT_TYPES)]
+ if len(real_nodes) > 1:
data_node = etree.Element("data")
for child in node:
data_node.append(child)
self.__logger.error('Parse error in %s:%d: \n%s',
rec.getroottree().docinfo.URL,
rec.sourceline,
- etree.tostring(rec).strip())
+ etree.tostring(rec).strip(), exc_info=True)
self.cr.rollback()
raise
return True
datas.append(map(lambda x: misc.ustr(x), line))
except:
logger.error("Cannot import the line: %s", line)
- pool.get(model).import_data(cr, uid, fields, datas,mode, module, noupdate, filename=fname_partial)
+ result, rows, warning_msg, dummy = pool.get(model).import_data(cr, uid, fields, datas,mode, module, noupdate, filename=fname_partial)
+ if result < 0:
+ # Report failed import and abort module install
+ raise Exception(_('Module loading failed: file %s/%s could not be processed:\n %s') % (module, fname, warning_msg))
if config.get('import_partial'):
data = pickle.load(file(config.get('import_partial')))
data[fname_partial] = 0