Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make output of import contest more readable. #2777

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions misc-tools/import-contest.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Part of the DOMjudge Programming Contest Jury System and licensed
under the GNU GPL. See README and COPYING for details.
'''

import json
from os import listdir
from typing import List
import json
import os.path
import re
import subprocess
import sys
from typing import List
import yaml

sys.path.append('@domserver_libdir@')
Expand Down Expand Up @@ -213,19 +214,46 @@ if os.path.exists('problems.yaml') or os.path.exists('problems.json') or os.path

confirmIndividually = dj_utils.confirm("Confirm individually for every problem", False)
for problem in problems:
print(f'Preparing problem \'{problem}\'.')
print(f'\nPreparing problem \'{problem}\'.')
if os.path.exists(f'{problem}.zip'):
os.unlink(f'{problem}.zip')
if not os.path.isdir(problem) or not os.path.isfile(f'{problem}/problem.yaml'):
print('Problem directory not found or doesn\'t contain a problem.yaml.')
exit(3)
os.system(f'cd {problem} && zip -r \'../{problem}\' -- .timelimit *')
zip_command = f"zip -r '../{problem}' -- .timelimit *"
process = subprocess.Popen(zip_command, cwd=problem, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, shell=True)

lastLine = None
for line in process.stdout:
if lastLine:
sys.stdout.write("\r" + " " * len(lastLine))
sys.stdout.write(f"\r{line.strip()}")
sys.stdout.flush()
lastLine = line

exit_code = process.wait()
if exit_code == 0:
if lastLine:
sys.stdout.write("\r" + " " * len(lastLine) + "\r")
else:
print(f"\nZipping problem failed with exit code: {exit_code}")

if ((not confirmIndividually) or dj_utils.confirm(f'Ready to import problem \'{problem}\' to problem={problem}. Continue?', True)):
print(f'Uploading problem \'{problem}\', please be patient, this may take a while.')
response = dj_utils.upload_file(
f'contests/{cid}/problems', 'zip', f'{problem}.zip', {'problem': problem})
print(json.dumps(response, indent=4))
if response and 'problem_id' in response:
print(f'Problem imported with ID {response["problem_id"]}:')
if 'messages' in response:
messages = response['messages']
types = {'info': '🛈 ', 'warning': '⚠️ ', 'danger': '🚨'}
for t,e in types.items():
if t in messages and messages[t]:
print(f' {e} {t.capitalize()}:')
for message in messages[t]:
print(f' - {message}')
else:
print(json.dumps(response, indent=4))
else:
print('Skipping contest import.')
else:
Expand Down
Loading