summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pysquaredeal.py21
-rw-r--r--squaredeal/__init__.py2
-rw-r--r--squaredeal/sqd.py18
3 files changed, 21 insertions, 20 deletions
diff --git a/pysquaredeal.py b/pysquaredeal.py
index be6a3d7..b8632ce 100644
--- a/pysquaredeal.py
+++ b/pysquaredeal.py
@@ -1,6 +1,7 @@
import argparse, os, re, sys
-from squaredeal.sqd import SquareDeal, SquareDealError, SquareDealPhase, generate_session_key, validate_board_range_str
+from squaredeal import SquareDealError
+from squaredeal.sqd import SQD, SQDPhase, generate_session_key, validate_board_range_str
def board_range(arg_str):
@@ -55,30 +56,30 @@ arguments = argparser.parse_args()
# TODO: this should be an interface class, also rename SquareDeal to SQD or sth and this to SquareDeal
if arguments.command == 'create':
- sd = SquareDeal()
+ sd = SQD()
sd.name = arguments.event_name
sd.delayed_info = arguments.delayed_information
sd.tofile(arguments.sqd_file)
elif arguments.command == 'set_name':
- sd = SquareDeal()
+ sd = SQD()
sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file)
if sd.published:
raise SquareDealError('Cannot change name: event already published')
sd.name = arguments.event_name
sd.tofile(arguments.sqd_file)
elif arguments.command == 'set_di':
- sd = SquareDeal()
+ sd = SQD()
sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file)
if sd.published:
raise SquareDealError('Cannot change delayed information description: event already published')
sd.delayed_info = arguments.delayed_information
sd.tofile(arguments.sqd_file)
elif arguments.command == 'add_phase':
- sd = SquareDeal()
+ sd = SQD()
sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file)
if sd.published:
raise SquareDealError('Cannot add phase: event already published')
- sdphase = SquareDealPhase()
+ sdphase = SQDPhase()
sdphase.sessions = arguments.sessions
sdphase.boards = arguments.boards
sdphase.prefix = arguments.prefix
@@ -86,7 +87,7 @@ elif arguments.command == 'add_phase':
sd.phases.append(sdphase)
sd.tofile(arguments.sqd_file)
elif arguments.command == 'publish':
- sd = SquareDeal()
+ sd = SQD()
sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file)
if sd.published:
raise SquareDealError('Cannot mark as published: event already published')
@@ -101,7 +102,7 @@ elif arguments.command == 'publish':
sd.published = True
sd.tofile(arguments.sqd_file, sqkpath=arguments.sqk_file)
elif arguments.command == 'set_dv':
- sd = SquareDeal()
+ sd = SQD()
sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file)
if not sd.published:
raise SquareDealError('Cannot set delayed information value: event not published')
@@ -110,8 +111,8 @@ elif arguments.command == 'set_dv':
elif arguments.command == 'generate':
if arguments.bigdealx_path is None:
arguments.bigdealx_path = os.environ.get('BIGDEALX_PATH', None)
- SquareDeal.BIGDEALX_PATH = arguments.bigdealx_path
- sd = SquareDeal()
+ SQD.BIGDEALX_PATH = arguments.bigdealx_path
+ sd = SQD()
sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file)
if not sd.published:
raise SquareDealError('Cannot generate PBN files: event info is not marked as published')
diff --git a/squaredeal/__init__.py b/squaredeal/__init__.py
index e69de29..163be72 100644
--- a/squaredeal/__init__.py
+++ b/squaredeal/__init__.py
@@ -0,0 +1,2 @@
+class SquareDealError(Exception):
+ pass
diff --git a/squaredeal/sqd.py b/squaredeal/sqd.py
index a2768bb..b1ea783 100644
--- a/squaredeal/sqd.py
+++ b/squaredeal/sqd.py
@@ -1,5 +1,7 @@
import base64, hashlib, os, random, re, shutil, string, subprocess
+from squaredeal import SquareDealError
+
def generate_session_key():
return ''.join(random.choices(string.ascii_letters + string.digits, k=60))
@@ -33,11 +35,7 @@ def validate_board_range_str(range_str):
raise ValueError('Invalid board range definition: %s' % (range_str))
-class SquareDealError(Exception):
- pass
-
-
-class SquareDealPhase(object):
+class SQDPhase(object):
def __init__(self):
self.sessions = 0
self.boards = 0
@@ -77,8 +75,8 @@ class SquareDealPhase(object):
return output_ranges[0:self.sessions]
def generate(self, session, delayed_info, reserve=False, output_path=None):
- if not SquareDeal.BIGDEALX_PATH:
- raise SquareDealError('Path to BigDeal is not set, initialize SquareDeal.BIGDEALX_PATH value')
+ if not SQD.BIGDEALX_PATH:
+ raise SquareDealError('Path to BigDeal is not set, initialize SQD.BIGDEALX_PATH value')
delayed_info = base64.b64encode(delayed_info.encode('utf-8')).decode()
sessions_to_generate = parse_range_str(session, self.sessions)
board_ranges = self._parse_board_ranges(self.boards)
@@ -88,7 +86,7 @@ class SquareDealPhase(object):
session_left = session_key[0:session_key_len]
session_right = session_key[session_key_len:]
reserve_info = 'reserve' if reserve else 'original'
- args = [SquareDeal.BIGDEALX_PATH,
+ args = [SQD.BIGDEALX_PATH,
'-W', session_left,
'-e', session_right,
'-e', delayed_info,
@@ -102,7 +100,7 @@ class SquareDealPhase(object):
-class SquareDeal(object):
+class SQD(object):
BIGDEALX_PATH=None
@@ -132,7 +130,7 @@ class SquareDeal(object):
self.hash = linecontents
self.published = True
elif linetype == 'SN':
- phase = SquareDealPhase()
+ phase = SQDPhase()
phase.fromstring(linecontents)
self.phases.append(phase)
else: