Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 9be1731

Browse files
committed
Added support for --max-depth for searching the task in the parent chain
It defaults to 2 because for ioi_format the maximum usual depth is for testo/asy_taskname
1 parent bcb4240 commit 9be1731

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

python/args.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def add_generic_group(parser: argparse.ArgumentParser):
4848
"--task-dir",
4949
help="Directory of the task to build",
5050
default=os.getcwd())
51+
group.add_argument(
52+
"--max-depth",
53+
help="Look at most for this number of parents to search the task",
54+
type=int,
55+
default=2)
5156
group.add_argument(
5257
"--ui",
5358
help="UI to use (%s)" % ("|".join(UIS.keys())),

python/detect_format.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
#!/usr/bin/env python3
22

3-
import os.path
3+
from os.path import join, isdir, dirname
44

55

6-
def detect_format():
7-
ioi = is_ioi_format()
8-
terry = is_terry_format()
6+
def find_task_dir(task_dir: str, max_depth: int):
7+
if task_dir.endswith("/"):
8+
task_dir = task_dir[:-1]
9+
current_format = detect_format(task_dir)
10+
if current_format or max_depth == 0:
11+
return task_dir, current_format
12+
return find_task_dir(dirname(task_dir), max_depth - 1)
13+
14+
15+
def detect_format(task_dir: str):
16+
ioi = is_ioi_format(task_dir)
17+
terry = is_terry_format(task_dir)
918
if ioi and not terry:
1019
return "ioi"
1120
elif terry and not ioi:
1221
return "terry"
1322
return None
1423

1524

16-
def is_ioi_format():
17-
if os.path.isdir("gen") or os.path.isdir("input"):
25+
def is_ioi_format(task_dir: str):
26+
if isdir(join(task_dir, "gen")) or isdir(join(task_dir, "input")):
1827
return True
1928
return False
2029

2130

22-
def is_terry_format():
23-
if os.path.isdir("managers"):
31+
def is_terry_format(task_dir: str):
32+
if isdir(join(task_dir, "managers")):
2433
return True
25-
return False
34+
return False

python/task_maker.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from python import ioi_format, terry_format
1010
from python.args import get_parser, UIS
11-
from python.detect_format import detect_format
11+
from python.detect_format import find_task_dir
1212
from python.manager import get_manager, became_manager, became_server, \
1313
became_worker
1414

@@ -56,39 +56,40 @@ def main() -> None:
5656
if args.kill_manager or args.quit_manager:
5757
return
5858

59-
os.chdir(args.task_dir)
60-
61-
if not args.format:
62-
args.format = detect_format()
63-
if not args.format:
59+
task_dir, format = find_task_dir(args.task_dir, args.max_depth)
60+
if not format:
61+
raise ValueError(
62+
"Cannot detect format! It's probable that the task is ill-formed")
63+
if args.format is not None and format != args.format:
6464
raise ValueError(
65-
"Cannot autodetect format! Try to pass --format to explicitly set "
66-
"it. It's probable that the task is ill-formed")
65+
"Detected format mismatch the required one: %s" % format)
66+
67+
os.chdir(task_dir)
6768

6869
if args.clean:
69-
if args.format == "ioi":
70+
if format == "ioi":
7071
ioi_format_clean(args)
71-
elif args.format == "terry":
72+
elif format == "terry":
7273
terry_format_clean(args)
7374
else:
74-
raise ValueError("Format %s not supported" % args.format)
75+
raise ValueError("Format %s not supported" % format)
7576
return
7677

7778
manager = get_manager(args)
7879

79-
if args.format == "ioi":
80+
if format == "ioi":
8081
request = ioi_format.get_request(args)
8182
solutions = [os.path.basename(sol.path) for sol in request.solutions]
82-
elif args.format == "terry":
83+
elif format == "terry":
8384
request = terry_format.get_request(args)
8485
solutions = [os.path.basename(sol.solution.path) for sol in
8586
request.solutions]
8687
else:
87-
raise ValueError("Format %s not supported" % args.format)
88+
raise ValueError("Format %s not supported" % format)
8889

89-
ui = UIS[args.ui](solutions, args.format)
90+
ui = UIS[args.ui](solutions, format)
9091

91-
if args.format == "ioi":
92+
if format == "ioi":
9293
ui.set_task_name("%s (%s)" % (request.task.title, request.task.name))
9394
ui.set_time_limit(request.task.time_limit)
9495
ui.set_memory_limit(request.task.memory_limit_kb)
@@ -100,11 +101,11 @@ def main() -> None:
100101
sorted(subtask.testcases.keys()))
101102
ui.set_max_score(sum(subtask.max_score for subtask in
102103
request.task.subtasks.values()))
103-
elif args.format == "terry":
104+
elif format == "terry":
104105
ui.set_task_name("%s (%s)" % (request.task.title, request.task.name))
105106
ui.set_max_score(request.task.max_score)
106107
else:
107-
raise ValueError("Format %s not supported" % args.format)
108+
raise ValueError("Format %s not supported" % format)
108109

109110
eval_id = None
110111

@@ -117,12 +118,12 @@ def stop_server(signum: int, _: Any) -> None:
117118
signal.signal(signal.SIGINT, stop_server)
118119
signal.signal(signal.SIGTERM, stop_server)
119120

120-
if args.format == "ioi":
121+
if format == "ioi":
121122
events = manager.EvaluateTask(request)
122-
elif args.format == "terry":
123+
elif format == "terry":
123124
events = manager.EvaluateTerryTask(request)
124125
else:
125-
raise NotImplementedError("Format %s not supported" % args.format)
126+
raise NotImplementedError("Format %s not supported" % format)
126127

127128
for event in events:
128129
event_type = event.WhichOneof("event_oneof")

0 commit comments

Comments
 (0)