Fix #219: catch BrokenPipeError

This commit is contained in:
Arun Prakash Jana 2017-10-11 18:09:30 +05:30
parent fd49d30a3e
commit 98fd16f075
No known key found for this signature in database
GPG Key ID: A75979F35C080412

65
buku.py
View File

@ -3231,33 +3231,37 @@ def print_rec_with_filter(records, field_filter=0):
Integer indicating which fields to print. Integer indicating which fields to print.
""" """
if field_filter == 0: try:
for row in records: if field_filter == 0:
print_single_rec(row) for row in records:
elif field_filter == 1: print_single_rec(row)
for row in records: elif field_filter == 1:
print('%s\t%s' % (row[0], row[1])) for row in records:
elif field_filter == 2: print('%s\t%s' % (row[0], row[1]))
for row in records: elif field_filter == 2:
print('%s\t%s\t%s' % (row[0], row[1], row[3][1:-1])) for row in records:
elif field_filter == 3: print('%s\t%s\t%s' % (row[0], row[1], row[3][1:-1]))
for row in records: elif field_filter == 3:
print('%s\t%s' % (row[0], row[2])) for row in records:
elif field_filter == 4: print('%s\t%s' % (row[0], row[2]))
for row in records: elif field_filter == 4:
print('%s\t%s\t%s\t%s' % (row[0], row[1], row[2], row[3][1:-1])) for row in records:
elif field_filter == 10: print('%s\t%s\t%s\t%s' % (row[0], row[1], row[2], row[3][1:-1]))
for row in records: elif field_filter == 10:
print(row[1]) for row in records:
elif field_filter == 20: print(row[1])
for row in records: elif field_filter == 20:
print('%s\t%s' % (row[1], row[3][1:-1])) for row in records:
elif field_filter == 30: print('%s\t%s' % (row[1], row[3][1:-1]))
for row in records: elif field_filter == 30:
print(row[2]) for row in records:
elif field_filter == 40: print(row[2])
for row in records: elif field_filter == 40:
print('%s\t%s\t%s' % (row[1], row[2], row[3][1:-1])) for row in records:
print('%s\t%s\t%s' % (row[1], row[2], row[3][1:-1]))
except BrokenPipeError:
sys.stdout = os.fdopen(1)
sys.exit(1)
def print_single_rec(row, idx=0): # NOQA def print_single_rec(row, idx=0): # NOQA
"""Print a single DB record. """Print a single DB record.
@ -3293,8 +3297,11 @@ def print_single_rec(row, idx=0): # NOQA
if row[3] != DELIM: if row[3] != DELIM:
str_list.append(TAG_str % (row[3][1:-1])) str_list.append(TAG_str % (row[3][1:-1]))
print(''.join(str_list)) try:
print(''.join(str_list))
except BrokenPipeError:
sys.stdout = os.fdopen(1)
sys.exit(1)
def format_json(resultset, single_record=False, field_filter=0): def format_json(resultset, single_record=False, field_filter=0):
"""Return results in json format. """Return results in json format.