summaryrefslogtreecommitdiff
path: root/dealconvert/__init__.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-05-21 00:00:25 +0200
committeremkael <emkael@tlen.pl>2019-05-21 00:00:25 +0200
commit481b8fc907ab3791483772fbb934cc2d5cddaa58 (patch)
tree73d803183a52dce759c9cc66b877b54e822d2266 /dealconvert/__init__.py
parent1b7ac788ad9499461b679753236e5ab598da7aec (diff)
Converter class
Diffstat (limited to 'dealconvert/__init__.py')
-rw-r--r--dealconvert/__init__.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/dealconvert/__init__.py b/dealconvert/__init__.py
new file mode 100644
index 0000000..f613fac
--- /dev/null
+++ b/dealconvert/__init__.py
@@ -0,0 +1,22 @@
+from .formats import *
+
+class DealConverter(object):
+ def __init__(self, input_file):
+ self.input = input_file
+ self.formats = {}
+ self.parser = self._detect_format(self.input)
+
+ def output(self, output_files):
+ deal_set = self.parser.parse(self.input)
+ for output in output_files:
+ self._detect_format(output).output(output, deal_set)
+
+ def _detect_format(self, filename):
+ 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')()
+ if self.formats[deal_format].match_file(filename):
+ return self.formats[deal_format]
+ raise ValueError('Unrecognized file extension: %s' % filename)