forked from yosupo06/library-checker-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
executable file
·107 lines (89 loc) · 3.5 KB
/
generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
import sys
import argparse
import os
import platform
import shutil
import hashlib
import json
from datetime import datetime
from logging import Logger, basicConfig, getLogger, INFO
from os import getenv
from pathlib import Path
from subprocess import (DEVNULL, PIPE, STDOUT, CalledProcessError,
TimeoutExpired, call, check_call, check_output, run)
from tempfile import TemporaryDirectory
from typing import Any, Iterator, List, MutableMapping, Union, Optional
from enum import Enum
import toml
from problem import Problem, find_problem_dir
logger: Logger = getLogger(__name__)
def main(args: List[str]):
try:
import colorlog
except ImportError:
basicConfig(
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt="%H:%M:%S",
level=getenv('LOG_LEVEL', 'INFO'),
)
logger.warn('Please install colorlog: pip3 install colorlog')
else:
handler = colorlog.StreamHandler()
formatter = colorlog.ColoredFormatter(
"%(log_color)s%(asctime)s [%(levelname)s] %(message)s",
datefmt="%H:%M:%S",
log_colors={
'DEBUG': 'cyan',
'INFO': 'white',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
})
handler.setFormatter(formatter)
basicConfig(
level=getenv('LOG_LEVEL', 'INFO'),
handlers=[handler]
)
parser = argparse.ArgumentParser(description='Testcase Generator')
parser.add_argument('toml', nargs='*', help='Toml File')
parser.add_argument('-p', '--problem', nargs='*',
help='Generate problem', default=[])
parser.add_argument('--dev', action='store_true', help='Developer Mode')
parser.add_argument('--test', action='store_true', help='CI Mode')
parser.add_argument('--clean', action='store_true', help='Clean in/out')
parser.add_argument('--compile-checker',
action='store_true', help='Deprecated: Compile Checker')
opts = parser.parse_args(args)
if opts.dev + opts.test + opts.clean >= 2:
raise ValueError('at most one of --dev, --test, --clean can be used')
if opts.compile_checker:
logger.warning(
'--compile-checker is deprecated. Checker is compiled in default')
rootdir: Path = Path(__file__).parent
problems: List[Problem] = list()
for tomlpath in opts.toml:
problems.append(Problem(rootdir, Path(tomlpath).parent))
for problem_name in opts.problem:
problem_dir = find_problem_dir(rootdir, problem_name)
if problem_dir is None:
raise ValueError('Cannot find problem: {}'.format(problem_name))
problems.append(Problem(rootdir, problem_dir))
if len(problems) == 0:
logger.warning('No problems')
# suppress the annoying dialog appears when an application crashes on Windows
if platform.uname().system == 'Windows':
import ctypes
SEM_NOGPFAULTERRORBOX = 2 # https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx
ctypes.windll.kernel32.SetErrorMode(SEM_NOGPFAULTERRORBOX)
mode = Problem.Mode.DEFAULT
if opts.dev:
mode = Problem.Mode.DEV
if opts.test:
mode = Problem.Mode.TEST
if opts.clean:
mode = Problem.Mode.CLEAN
for problem in problems:
problem.generate(mode)
if __name__ == '__main__':
main(sys.argv[1:])