Skip to content
Snippets Groups Projects

Import orgů

Merged Jiří Kalvoda requested to merge jk/import-orgu into devel
Compare and Show latest version
24 files
+ 327
160
Compare changes
  • Side-by-side
  • Inline

Files

bin/create-tasks 0 → 100755
+ 39
0
#!/usr/bin/env python3
import argparse
import mo.db as db
import mo.util
from mo.util import die, init_standalone
parser = argparse.ArgumentParser(description='Založí úlohy pro dané kolo')
parser.add_argument(dest='round', type=str, metavar='YY-C-S[p]', help='kód kola')
parser.add_argument(dest='count', type=int, help='počet úloh')
parser.add_argument('-p', '--points', type=int, default=None, help='maximální počet bodů')
args = parser.parse_args()
init_standalone()
sess = db.get_session()
round_code = mo.util.RoundCode.parse(args.round)
if round_code is None:
die("Chybná syntaxe kódu kola")
round = mo.util.get_round_by_code(round_code)
if round is None:
die("Kolo s tímto kódem neexistuje!")
if round.state != db.RoundState.preparing:
die("Kolo musí být ve stavu 'připravuje se'")
for i in range(1, args.count + 1):
code = f'{round.category}-{round.code or round.seq}-{i}'
task = sess.query(db.Task).filter_by(round=round, code=code).one_or_none()
if task:
print(f'{code}: již existuje')
else:
task = db.Task(round=round, code=code, name=f'Úloha {i}', max_points=args.points)
sess.add(task)
print(f'{code}: zakládám')
sess.commit()
Loading