diff options
author | emkael <emkael@tlen.pl> | 2019-05-23 01:42:08 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-05-23 01:42:08 +0200 |
commit | c5608c4cdb67aca4d154541a09d5ebb88bf232ec (patch) | |
tree | a3f9ecba1206c3bfe6aa936ce43f238b34d4c315 /dealconvert/formats/dup.py | |
parent | 3e2102f3038be32c85e98c2bd6a6023c63fae070 (diff) |
Proper error/warning handling
Diffstat (limited to 'dealconvert/formats/dup.py')
-rw-r--r-- | dealconvert/formats/dup.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/dealconvert/formats/dup.py b/dealconvert/formats/dup.py index 53b790b..1a2e1ba 100644 --- a/dealconvert/formats/dup.py +++ b/dealconvert/formats/dup.py @@ -1,4 +1,4 @@ -import sys +import warnings from . import DealFormat from .bri import BRIFormat @@ -20,18 +20,19 @@ class DUPFormat(DealFormat): boards.append(content.read(156)) if len(boards[-1]) < 156: if len(boards[-1]) > 0: - print 'WARNING: truncated .dup content: %s' % (boards[-1]) + warnings.warn('truncated .dup content: %s' % (boards[-1])) boards = boards[0:-1] break boards = [(board[0:78], board[78:146], board[146:]) for board in boards] if boards[0][2][0] == chr(0): - print 'ERROR: .dup file header not found' - sys.exit() + raise RuntimeError('.dup file header not found') start_board = int(boards[0][2][2:4].strip()) board_count = int(boards[0][2][7:9].strip()) board_numbers = range(start_board, start_board+board_count) if boards[0][2][1].upper() != 'N': - print 'WARNING: .dup file header has "reverse" flag set, nobody knows what to do with it, so it\'s time to panic' + warnings.warn( + '.dup file header has "reverse" flag set, ' + + 'nobody knows what to do with it, so it\'s time to panic') dealset = [] for idx, board in enumerate(boards): deal = dto.Deal() @@ -48,8 +49,8 @@ class DUPFormat(DealFormat): board_count = len(dealset) for board in range(first_board, first_board+board_count): if board not in board_numbers: - print 'ERROR: .dup format requires consequent board numbers' - sys.exit() + raise RuntimeError( + '.dup format requires consequent board numbers') header = 'YN%s 0 %02d ' % (str(first_board).ljust(2, ' '), board_count) for deal in dealset: out_file.write(self.bri.single_deal_output(deal)) |