--- a/dataimport.py Mon Apr 04 14:49:39 2011 +0200
+++ b/dataimport.py Mon Apr 04 14:50:10 2011 +0200
@@ -79,6 +79,7 @@
from logilab.common.decorators import cached
from logilab.common.deprecation import deprecated
+from cubicweb import QueryError
from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES
from cubicweb.server.utils import eschema_eid
from cubicweb.server.edition import EditedEntity
@@ -540,6 +541,10 @@
def run(self):
self.errors = {}
+ if self.commitevery is None:
+ self.tell('Will commit all or nothing.')
+ else:
+ self.tell('Will commit every %s iterations' % self.commitevery)
for func, checks in self.generators:
self._checks = {}
func_name = func.__name__
@@ -558,7 +563,12 @@
err = func(buckets)
if err:
self.errors[title] = (help, err)
- txuuid = self.store.commit()
+ try:
+ txuuid = self.store.commit()
+ if txuuid is not None:
+ self.tell('Transaction commited (txuuid: %s)' % txuuid)
+ except QueryError, ex:
+ self.tell('Transaction aborted: %s' % ex)
self._print_stats()
if self.errors:
if self.askerror == 2 or (self.askerror and confirm('Display errors ?')):
@@ -566,8 +576,7 @@
for errkey, error in self.errors.items():
self.tell("\n%s (%s): %d\n" % (error[0], errkey, len(error[1])))
self.tell(pformat(sorted(error[1])))
- if txuuid is not None:
- print 'transaction id:', txuuid
+
def _print_stats(self):
nberrors = sum(len(err[1]) for err in self.errors.values())
self.tell('\nImport statistics: %i entities, %i types, %i relations and %i errors'