Commit 14a92bc6 authored by Yannick Chudy's avatar Yannick Chudy

raise csv error with empty file

parent 4e155c2b
...@@ -222,9 +222,12 @@ class Botapad(object): ...@@ -222,9 +222,12 @@ class Botapad(object):
lines = [ line.strip() for line in lines ] lines = [ line.strip() for line in lines ]
lines = [ line.encode('utf8') for line in lines if len(line)] lines = [ line.encode('utf8') for line in lines if len(line)]
if not len(lines):
raise BotapadCsvError(path, separator, "Table is empty %s lines" % (len(lines) ) )
if separator == 'auto': if separator == 'auto':
line = lines[0].strip() line = lines[0].strip()
print 'auto', lines[0].strip(), line[1:] == "!;"
if line in ( '!;','!,'): if line in ( '!;','!,'):
separator = line[1:] separator = line[1:]
else: separator = ',' else: separator = ','
...@@ -234,8 +237,6 @@ class Botapad(object): ...@@ -234,8 +237,6 @@ class Botapad(object):
try : try :
reader = csv.reader(lines, delimiter=separator) reader = csv.reader(lines, delimiter=separator)
rows = [ r for r in reader] rows = [ r for r in reader]
#start_col = 0 if start_col is None else start_col
#rows = [ r[start_col:end_col] for r in rows]
rows = [ [ e.strip().decode('utf8') for e in r ] for r in rows if len(r) and not all([ len(e) == 0 for e in r]) ] rows = [ [ e.strip().decode('utf8') for e in r ] for r in rows if len(r) and not all([ len(e) == 0 for e in r]) ]
except : except :
raise BotapadCsvError(path, separator, "Error while parsing data %s lines with separator %s" % (len(lines), separator ) ) raise BotapadCsvError(path, separator, "Error while parsing data %s lines with separator %s" % (len(lines), separator ) )
...@@ -264,7 +265,6 @@ class Botapad(object): ...@@ -264,7 +265,6 @@ class Botapad(object):
def _parse(self, path, rows, **kwargs): def _parse(self, path, rows, **kwargs):
""" :param path : txt file path """ :param path : txt file path
handles special lines starting with [# @ _]
for comments, node type, property names for comments, node type, property names
""" """
......
...@@ -489,6 +489,7 @@ def botimport(repo, padurl, gid, content_type): ...@@ -489,6 +489,7 @@ def botimport(repo, padurl, gid, content_type):
'class' : err.__class__.__name__, 'class' : err.__class__.__name__,
'url' : err.path, 'url' : err.path,
'separator' : err.separator, 'separator' : err.separator,
'message' : err.message
} }
except BotapadParseError as err: except BotapadParseError as err:
......
...@@ -352,6 +352,7 @@ ...@@ -352,6 +352,7 @@
<ul class="list"> <ul class="list">
<li>Error while parsing <a href="{{error.url}}" target="_blank">{{error.url}}</a></li> <li>Error while parsing <a href="{{error.url}}" target="_blank">{{error.url}}</a></li>
<li>Parsing data failed in {{error.url}}</li> <li>Parsing data failed in {{error.url}}</li>
<li>{{error.message}}</li>
<li>we used the character <code>{{error.separator}}</code> as a separator</li> <li>we used the character <code>{{error.separator}}</code> as a separator</li>
</ul>{% elif error.class == "BotapadParseError" %} </ul>{% elif error.class == "BotapadParseError" %}
<ul class="list"> <ul class="list">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment