diff options
author | emkael <emkael@tlen.pl> | 2019-10-01 18:39:32 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-10-01 18:39:32 +0200 |
commit | 835c002b4a9da9139837ddc6fdb31630ffee0de2 (patch) | |
tree | 600b6f0571eefb93f44d6b07071380cb512917e1 | |
parent | ad546b63fb6fada2a87f60b21f0a41d2d6bd419e (diff) |
Taking advantage of pybcdd's option to write only JFR double-dummy fields
-rw-r--r-- | deal-converter.py | 4 | ||||
-rw-r--r-- | dealconvert/__init__.py | 9 | ||||
-rw-r--r-- | dealconvert/formats/__init__.py | 3 | ||||
-rw-r--r-- | dealconvert/formats/cds.py | 2 | ||||
-rw-r--r-- | dealconvert/formats/dup.py | 2 | ||||
-rw-r--r-- | dealconvert/formats/pbn.py | 4 | ||||
m--------- | pybcdd | 0 |
7 files changed, 14 insertions, 10 deletions
diff --git a/deal-converter.py b/deal-converter.py index ad5fc20..ee0c3d5 100644 --- a/deal-converter.py +++ b/deal-converter.py @@ -12,6 +12,8 @@ parser = argparse.ArgumentParser( epilog='Supported formats: BER BHG BRI CDS CSV DGE DLM DUP PBN RZD.\n' + \ 'Formats are auto-detected based on file extension.\n' + \ 'To display deals on STDOUT, provide "-" as an output file name.') +parser.add_argument('--jfr', action='store_true', + help='For PBN file, write only JFR DD fields') parser.add_argument('input', metavar='INPUT_FILE', help='Input file path') parser.add_argument('output', metavar='OUTPUT_FILE', nargs='*', @@ -24,7 +26,7 @@ def _warning(msg, *args, **kwargs): warnings.showwarning = _warning try: - converter = DealConverter(arguments.input) + converter = DealConverter(arguments.input, jfr_only=arguments.jfr) converter.output(arguments.output) except RuntimeError as e: print('ERROR: %s' % (str(e)), file=sys.stderr) 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) diff --git a/pybcdd b/pybcdd -Subproject bc2a83ad9ac5dd506866af1dd903cbd428701a5 +Subproject c1df2239c5d09a03768439714550dd01ebe917c |