devtools/dataimport.py
changeset 4140 46ddd27a4ca4
parent 4136 47060a66c97f
child 4152 30fd1229137d
equal deleted inserted replaced
4139:2718f2fd0576 4140:46ddd27a4ca4
    61     """same as ucsvreader but a progress bar is displayed as we iter on rows"""
    61     """same as ucsvreader but a progress bar is displayed as we iter on rows"""
    62     rowcount = int(shellutils.Execute('wc -l %s' % filepath).out.strip().split()[0])
    62     rowcount = int(shellutils.Execute('wc -l %s' % filepath).out.strip().split()[0])
    63     if skipfirst:
    63     if skipfirst:
    64         rowcount -= 1
    64         rowcount -= 1
    65     if withpb:
    65     if withpb:
    66         pb = shellutils.ProgressBar(rowcount)
    66         pb = shellutils.ProgressBar(rowcount, 50)
    67     for urow in ucsvreader(file(filepath), encoding, separator, quote, skipfirst):
    67     for urow in ucsvreader(file(filepath), encoding, separator, quote, skipfirst):
    68         yield urow
    68         yield urow
    69         if withpb:
    69         if withpb:
    70             pb.update()
    70             pb.update()
    71     print ' %s rows imported' % rowcount
    71     print ' %s rows imported' % rowcount
   306                 if buckets:
   306                 if buckets:
   307                     err = func(buckets)
   307                     err = func(buckets)
   308                     if err:
   308                     if err:
   309                         self.errors[title] = (help, err)
   309                         self.errors[title] = (help, err)
   310             self.store.checkpoint()
   310             self.store.checkpoint()
   311         self.tell('Import completed: %i entities (%i types), %i relations'
   311         self.tell('\nImport completed: %i entities (%i types), %i relations'
   312                   % (len(self.store.eids), len(self.store.types),
   312                   % (len(self.store.eids), len(self.store.types),
   313                      len(self.store.relations)))
   313                      len(self.store.relations)))
   314         nberrors = sum(len(err[1]) for err in self.errors.values())
   314         nberrors = sum(len(err[1]) for err in self.errors.values())
   315         if nberrors:
   315         if nberrors:
   316             print '%s errors' % nberrors
   316             print '%s errors' % nberrors