From 835c002b4a9da9139837ddc6fdb31630ffee0de2 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 1 Oct 2019 18:39:32 +0200 Subject: Taking advantage of pybcdd's option to write only JFR double-dummy fields --- dealconvert/__init__.py | 9 +++++---- dealconvert/formats/__init__.py | 3 ++- dealconvert/formats/cds.py | 2 +- dealconvert/formats/dup.py | 2 +- dealconvert/formats/pbn.py | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) (limited to 'dealconvert') diff --git a/dealconvert/__init__.py b/dealconvert/__init__.py index 530990f..229e4ce 100644 --- a/dealconvert/__init__.py +++ b/dealconvert/__init__.py @@ -1,23 +1,24 @@ from .formats import * class DealConverter(object): - def __init__(self, input_file=None): + def __init__(self, input_file=None, jfr_only=False): self.input = input_file self.formats = {} + print jfr_only if input_file is not None: - self.parser = self.detect_format(self.input) + self.parser = self.detect_format(self.input, jfr_only=jfr_only) def output(self, output_files): deal_set = sorted(self.parser.parse(self.input), key=lambda d:d.number) for output in output_files: self.detect_format(output).output(output, deal_set, True) - def detect_format(self, filename, interactive=True): + def detect_format(self, filename, interactive=True, jfr_only=False): for deal_format in globals()['formats'].__all__: if deal_format not in self.formats: self.formats[deal_format] = getattr( globals()[deal_format], - deal_format.upper() + 'Format')(interactive) + deal_format.upper() + 'Format')(interactive, jfr_only) if self.formats[deal_format].match_file(filename): return self.formats[deal_format] raise RuntimeError('Unrecognized file extension: %s' % filename) diff --git a/dealconvert/formats/__init__.py b/dealconvert/formats/__init__.py index 2d3d983..9ac48e3 100644 --- a/dealconvert/formats/__init__.py +++ b/dealconvert/formats/__init__.py @@ -4,8 +4,9 @@ import glob class DealFormat(object): cards = 'AKQJT98765432' - def __init__(self, interactive=True): + def __init__(self, interactive=True, jfr_only=False): self.interactive = interactive + self.jfr_only = jfr_only def parse(self, input_file): with open(input_file, 'rb') as content: diff --git a/dealconvert/formats/cds.py b/dealconvert/formats/cds.py index c7eeb5a..6137c4d 100644 --- a/dealconvert/formats/cds.py +++ b/dealconvert/formats/cds.py @@ -9,7 +9,7 @@ class CDSFormat(DealFormat): def suffix(self): return '.cds' - def __init__(self, interactive=True): + def __init__(self, *args, **kwargs): self.rzd_format = RZDFormat() def parse_content(self, content): diff --git a/dealconvert/formats/dup.py b/dealconvert/formats/dup.py index 19dca0f..3e34f2c 100644 --- a/dealconvert/formats/dup.py +++ b/dealconvert/formats/dup.py @@ -10,7 +10,7 @@ class DUPFormat(DealFormat): def suffix(self): return '.dup' - def __init__(self, interactive=True): + def __init__(self, *args, **kwargs): self.bri = BRIFormat() self.dge = DGEFormat() diff --git a/dealconvert/formats/pbn.py b/dealconvert/formats/pbn.py index 750d57d..04db8a2 100644 --- a/dealconvert/formats/pbn.py +++ b/dealconvert/formats/pbn.py @@ -144,8 +144,8 @@ class PBNFormat(DealFormat): dd_board = PBNBoard(lines) dd_table = DDTable(dd_board).get_dd_table(self.interactive) dd_contract = ParScore(dd_board).get_par_contract(dd_table) - dd_board.save_dd_table(dd_table) - dd_board.save_par_contract(dd_contract) + dd_board.save_dd_table(dd_table, jfr_only=self.jfr_only) + dd_board.save_par_contract(dd_contract, jfr_only=self.jfr_only) lines = [field.raw_field for field in dd_board.fields] except Exception as e: warnings.warn('unable to determine double-dummy data: %s' % e) -- cgit v1.2.3