Skip to content

Commit

Permalink
[rec-] support %sort; continue loading on exception #2022
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Sep 9, 2023
1 parent d7204d8 commit 8c89039
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion visidata/loaders/rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def iterload(self):

fp = iter(self.source)
while next_line is not None:
try:
line, next_line = decode_multiline(next_line, fp)
line = line.lstrip()

Expand All @@ -62,6 +63,7 @@ def iterload(self):

if not sheet or (newRecord and line[0] == '%'):
sheet = RecSheet('', columns=[], rows=[], source=self, comments=comments)
sheet.columns = []
comments = []
yield sheet
newRecord = False
Expand All @@ -81,7 +83,7 @@ def iterload(self):
if colname not in sheet.colnames:
sheet.addColumn(ItemColumn(colname, keycol=i+1))
elif desc in ['sort']:
sheet.orderBy([sheet.column(colname) for colname in rest.split()])
sheet._ordering = [(colname, False) for colname in rest.split()]
elif desc in ['type', 'typedef']:
pass
elif desc in ['auto']: # autoincrement columns should be present already
Expand Down Expand Up @@ -112,6 +114,8 @@ def iterload(self):
row[name].append(rest)
else:
row[name] = rest
except Exception as e:
vd.exceptionCaught(e)

for sheet in Progress(self.rows):
sheet.sort()
Expand Down

0 comments on commit 8c89039

Please sign in to comment.