summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2024-02-13 01:26:08 +0100
committeremkael <emkael@tlen.pl>2024-02-13 01:26:08 +0100
commit3c44a072bd3833c34fa6c15553cce0594247aa9d (patch)
tree9c18a0bc9d0f65d25163d0912d7d05eda9941b31
parent9e487aae490aca64f89634ad608729e4094d8847 (diff)
Input file encoding option back functioning
-rw-r--r--pysquaredeal.py2
-rw-r--r--squaredeal/__init__.py15
-rw-r--r--squaredeal/sqd.py4
3 files changed, 12 insertions, 9 deletions
diff --git a/pysquaredeal.py b/pysquaredeal.py
index 12e5dc6..bf24e43 100644
--- a/pysquaredeal.py
+++ b/pysquaredeal.py
@@ -44,5 +44,5 @@ arguments = argparser.parse_args()
SquareDeal.BIGDEALX_PATH = arguments.bigdealx_path
-sq = SquareDeal(arguments.sqd_file, sqk_file=arguments.sqk_file)
+sq = SquareDeal(arguments.sqd_file, sqk_file=arguments.sqk_file, encoding=arguments.encoding)
getattr(sq, arguments.command)(**vars(arguments))
diff --git a/squaredeal/__init__.py b/squaredeal/__init__.py
index ee2b8c2..8ed571f 100644
--- a/squaredeal/__init__.py
+++ b/squaredeal/__init__.py
@@ -44,10 +44,11 @@ class SquareDeal(object):
BIGDEALX_PATH = None
- def __init__(self, sqd_file, sqk_file=None):
+ def __init__(self, sqd_file, sqk_file=None, encoding=None):
self.sqd = SQD()
self.sqd_file = sqd_file
self.sqk_file = sqk_file
+ self.sqd_encoding = encoding
def create(self, event_name=None, delayed_information=None, overwrite=False, **kwargs):
self.sqd.name = event_name
@@ -59,7 +60,7 @@ class SquareDeal(object):
self.sqd.tofile(self.sqd_file)
def set_name(self, event_name, **kwargs):
- self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file)
+ self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file, encoding=self.sqd_encoding)
if self.sqd.published:
raise SquareDealError('Cannot change name: event already published')
@@ -69,7 +70,7 @@ class SquareDeal(object):
self.sqd.tofile(self.sqd_file)
def set_di(self, delayed_information, **kwargs):
- self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file)
+ self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file, encoding=self.sqd_encoding)
if self.sqd.published:
raise SquareDealError('Cannot change delayed information description: event already published')
@@ -79,7 +80,7 @@ class SquareDeal(object):
self.sqd.tofile(self.sqd_file)
def add_phase(self, sessions, boards, prefix, description='', **kwargs):
- self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file)
+ self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file, encoding=self.sqd_encoding)
if self.sqd.published:
raise SquareDealError('Cannot add phase: event already published')
@@ -94,7 +95,7 @@ class SquareDeal(object):
self.sqd.tofile(self.sqd_file)
def publish(self, **kwargs):
- self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file)
+ self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file, encoding=self.sqd_encoding)
if self.sqd.published:
raise SquareDealError('Cannot mark as published: event already published')
@@ -112,7 +113,7 @@ class SquareDeal(object):
self.sqd.tofile(self.sqd_file, sqkpath=self.sqk_file)
def set_dv(self, delayed_information, **kwargs):
- self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file)
+ self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file, encoding=self.sqd_encoding)
if not self.sqd.published:
raise SquareDealError('Cannot set delayed information value: event not published')
@@ -125,7 +126,7 @@ class SquareDeal(object):
if not SquareDeal.BIGDEALX_PATH:
raise SquareDealError('Path to BigDeal is not set, initialize SquareDeal.BIGDEALX_PATH value')
- self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file)
+ self.sqd.fromfile(self.sqd_file, sqkpath=self.sqk_file, encoding=self.sqd_encoding)
if not self.sqd.published:
raise SquareDealError('Cannot generate PBN files: event info is not marked as published')
diff --git a/squaredeal/sqd.py b/squaredeal/sqd.py
index 3de3f34..60ef4a3 100644
--- a/squaredeal/sqd.py
+++ b/squaredeal/sqd.py
@@ -68,7 +68,9 @@ class SQD(object):
self.published = False
self.sqd_path = None
- def fromfile(self, sqdpath, sqkpath=None, encoding='utf-8'):
+ def fromfile(self, sqdpath, sqkpath=None, encoding=None):
+ if not encoding:
+ encoding = 'utf-8'
with open(sqdpath, encoding=encoding) as sqdfile:
contents = [line.strip() for line in sqdfile.readlines()]
self._init_values()