# HG changeset patch # User Sylvain Thénault # Date 1261506239 -3600 # Node ID ca7e526b07b6a1f40c15a0deb4605572fcc75386 # Parent 7002e91d304ab67e0e97f119dd53b46dd9104738 import cleanup, check data file exists diff -r 7002e91d304a -r ca7e526b07b6 devtools/dataimport.py --- a/devtools/dataimport.py Tue Dec 22 13:16:17 2009 +0100 +++ b/devtools/dataimport.py Tue Dec 22 19:23:59 2009 +0100 @@ -51,7 +51,11 @@ """ __docformat__ = "restructuredtext en" -import sys, csv, traceback +import sys +import csv +import traceback +import os.path as osp +from StringIO import StringIO from logilab.common import shellutils from logilab.common.deprecation import deprecated @@ -59,6 +63,8 @@ def ucsvreader_pb(filepath, encoding='utf-8', separator=',', quote='"', skipfirst=False, withpb=True): """same as ucsvreader but a progress bar is displayed as we iter on rows""" + if not osp.exists(filepath): + raise Exception("file doesn't exists: %s" % filepath) rowcount = int(shellutils.Execute('wc -l "%s"' % filepath).out.strip().split()[0]) if skipfirst: rowcount -= 1 @@ -326,8 +332,7 @@ entity[key] = default def record_error(self, key, msg=None, type=None, value=None, tb=None): - import StringIO - tmp = StringIO.StringIO() + tmp = StringIO() if type is None: traceback.print_exc(file=tmp) else: