scripts: Reverted csv read/writing to pass notes through
On second thought, let's keep the more complicated results contained in the json format. No reason to create complexity we don't need. Note this also rips note parsing out of csv.py's collect_csv. Now all scripts should ignore note fields in csv files, but accept note fields in json files. The impl is still in the history if we want to revert this in the future.
This commit is contained in:
+5
-18
@@ -937,10 +937,10 @@ def read_csv(path, Result, *,
|
||||
|
||||
with openio(path, 'r') as f:
|
||||
# csv or json? assume json starts with [
|
||||
json = (f.buffer.peek(1)[:1] == b'[')
|
||||
is_json = (f.buffer.peek(1)[:1] == b'[')
|
||||
|
||||
# read csv?
|
||||
if not json:
|
||||
if not is_json:
|
||||
results = []
|
||||
reader = csv.DictReader(f, restval='')
|
||||
for r in reader:
|
||||
@@ -955,13 +955,7 @@ def read_csv(path, Result, *,
|
||||
and r[k].strip()}
|
||||
| {k: r[prefix+k] for k in fields
|
||||
if prefix+k in r
|
||||
and r[prefix+k].strip()}
|
||||
| ({Result._notes: set(n.strip()
|
||||
for n in r[Result._notes].split(',')
|
||||
if n.strip())}
|
||||
if hasattr(Result, '_notes')
|
||||
and Result._notes in r
|
||||
else {}))))
|
||||
and r[prefix+k].strip()})))
|
||||
except TypeError:
|
||||
pass
|
||||
return results
|
||||
@@ -1027,9 +1021,7 @@ def write_csv(path, Result, results, *,
|
||||
writer = csv.DictWriter(f, list(
|
||||
co.OrderedDict.fromkeys(it.chain(
|
||||
by,
|
||||
(prefix+k for k in fields),
|
||||
[Result._notes] if hasattr(Result, '_notes')
|
||||
else [])).keys()))
|
||||
(prefix+k for k in fields))).keys()))
|
||||
writer.writeheader()
|
||||
for r in results:
|
||||
# note this allows by/fields to overlap
|
||||
@@ -1039,12 +1031,7 @@ def write_csv(path, Result, results, *,
|
||||
if getattr(r, k) is not None}
|
||||
| {prefix+k: getattr(r, k).__csv__()
|
||||
for k in fields
|
||||
if getattr(r, k) is not None}
|
||||
| ({Result._notes: ','.join(
|
||||
getattr(r, Result._notes))}
|
||||
if hasattr(Result, '_notes')
|
||||
and getattr(r, Result._notes)
|
||||
else {}))
|
||||
if getattr(r, k) is not None})
|
||||
|
||||
# write json?
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user