diff options
author | emkael <emkael@tlen.pl> | 2024-01-15 18:14:34 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2024-01-15 18:14:34 +0100 |
commit | 20ee8fce32373710be9da19b5be5bcb99fae3f44 (patch) | |
tree | 04bf276c9b1efc7c80c9fddd51953c9979902ecd | |
parent | 7f1a1d696567052993c7095598ce20575e99557b (diff) |
Add phase and publish commands
-rw-r--r-- | pysquaredeal.py | 30 | ||||
-rw-r--r-- | squaredeal/__init__.py | 15 |
2 files changed, 43 insertions, 2 deletions
diff --git a/pysquaredeal.py b/pysquaredeal.py index 25d1df1..b26801d 100644 --- a/pysquaredeal.py +++ b/pysquaredeal.py @@ -1,6 +1,6 @@ import argparse, sys -from squaredeal import SquareDeal +from squaredeal import SquareDeal, SquareDealError argparser = argparse.ArgumentParser(prog='pysquaredeal.py') @@ -20,6 +20,14 @@ argparser_name.add_argument('event_name', metavar='EVENT_NAME', help='event name argparser_di = subparsers.add_parser('set_di', help='edit event delayed information (or its value)') argparser_di.add_argument('delayed_information', metavar='DELAYED_INFO', help='(description of) delayed information') +argparser_publish = subparsers.add_parser('publish', help='mark SQD as published') + +argparser_phase = subparsers.add_parser('add_phase', help='add event phase') +argparser_phase.add_argument('sessions', metavar='NO_SESSIONS', help='number of sessions in phase', type=int) +argparser_phase.add_argument('boards', metavar='NO_BOARDS', help='number of boards in each session', type=int) +argparser_phase.add_argument('prefix', metavar='PREFIX', help='ouput file prefix ("#" will be replaced by session number)') +argparser_phase.add_argument('--description', required=False, metavar='DESCRIPTION', help='phase description') + arguments = argparser.parse_args() if arguments.command == 'create': @@ -30,6 +38,8 @@ if arguments.command == 'create': elif arguments.command == 'set_name': sd = SquareDeal() 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, sqkpath=arguments.sqk_file) elif arguments.command == 'set_di': @@ -37,3 +47,21 @@ elif arguments.command == 'set_di': sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file) sd.delayed_info = arguments.delayed_information sd.tofile(arguments.sqd_file, sqkpath=arguments.sqk_file) +elif arguments.command == 'publish': + sd = SquareDeal() + sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file) + if not sd.name: + raise SquareDealError('Cannot mark as published: event name is not set') + if not sd.delayed_info: + raise SquareDealError('Cannot mark as published: delayed information is not set') + if not sd.phases: + raise SquareDealError('Cannot mark as published: no phases are defined') + sd.published = True + sd.tofile(arguments.sqd_file, sqkpath=arguments.sqk_file) +elif arguments.command == 'add_phase': + sd = SquareDeal() + sd.fromfile(arguments.sqd_file, sqkpath=arguments.sqk_file) + if sd.published: + raise SquareDealError('Cannot add phase: event already published') + sd.add_phase(arguments.sessions, arguments.boards, arguments.prefix, description=arguments.description) + sd.tofile(arguments.sqd_file, sqkpath=arguments.sqk_file) diff --git a/squaredeal/__init__.py b/squaredeal/__init__.py index c08f946..742b28d 100644 --- a/squaredeal/__init__.py +++ b/squaredeal/__init__.py @@ -1,4 +1,4 @@ -import hashlib, os, shutil +import hashlib, os, random, string, shutil class SquareDealError(Exception): @@ -129,3 +129,16 @@ class SquareDeal(object): sqd_contents.append('PU\n') with open(sqdpath, 'w') as sqdfile: sqdfile.writelines(sqd_contents) + + def _generate_session_key(self): + return ''.join(random.choices(string.ascii_letters + string.digits, k=60)) + + def add_phase(self, session_count, board_count, file_prefix, description=None): + phase = SquareDealPhase() + phase.sessions = session_count + phase.boards = board_count + phase.prefix = file_prefix + phase.info = description + for i in range(0, phase.sessions): + phase.s_keys.append(self._generate_session_key()) + self.phases.append(phase) |