-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtps2toj.py
102 lines (87 loc) · 2.81 KB
/
tps2toj.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
import argparse
import json
import logging
import os
import re
import subprocess
from function import makedirs, copyfile
parser = argparse.ArgumentParser(description='cms2toj')
parser.add_argument('inputpath', type=str, help='輸入資料夾')
parser.add_argument('outputpath', type=str, help='輸出的資料夾')
parser.add_argument('-d', '--debug', action='store_const', dest='loglevel', const=logging.DEBUG)
parser.set_defaults(loglevel=logging.INFO)
args = parser.parse_args()
inputpath = args.inputpath
outputpath = args.outputpath
logging.basicConfig(level=args.loglevel, format='%(asctime)s %(levelname)s %(message)s')
with open(os.path.join(inputpath, 'problem.json')) as f:
data = json.load(f)
makedirs(outputpath)
# conf
conf = {
'timelimit': 0,
'memlimit': 0,
'compile': 'g++',
'score': 'rate',
'check': 'diff',
'test': [],
'metadata': {},
}
conf['timelimit'] = int(data['time_limit'] * 1000)
conf['memlimit'] = int(data['memory_limit'] * 1024)
# res/testdata / testcases
makedirs(outputpath, 'res/testdata')
datacasemap = {}
offset = 1
subtasks_json_src = os.path.join(inputpath, 'subtasks.json')
mapping_src = os.path.join(inputpath, 'tests', 'mapping')
mapping_data = {}
with open(subtasks_json_src, 'rt', encoding='utf-8') as json_file:
subtasks_data = json.load(json_file)
for subtask in subtasks_data['subtasks']:
mapping_data[subtask] = []
with open(mapping_src, 'rt', encoding='utf-8') as mapping_file:
for row in mapping_file:
row = row.strip().split(' ')
datacasemap[row[1]] = offset
if len(row) == 2:
mapping_data[row[0]].append(offset)
copyfile(
(inputpath, 'tests', '{}.in'.format(row[1])),
(outputpath, 'res/testdata', '{}.in'.format(offset))
)
copyfile(
(inputpath, 'tests', '{}.out'.format(row[1])),
(outputpath, 'res/testdata', '{}.out'.format(offset))
)
offset += 1
for subtask in mapping_data:
conf['test'].append({
'data': mapping_data[subtask],
'weight': subtasks_data['subtasks'][subtask]['score'],
})
logging.info('Creating config file')
with open(os.path.join(outputpath, 'conf.json'), 'w') as conffile:
json.dump(conf, conffile, indent=4)
# http / statements
makedirs(outputpath, 'http')
statement_path = os.path.join(inputpath, 'statement', 'index.pdf')
if not os.path.exists(statement_path):
logging.info('No statements')
statement = None
else:
logging.info('Copying statements')
copyfile(
(statement_path,),
(outputpath, 'http', 'cont.pdf')
)
p = subprocess.Popen([
'tar',
'-C',
outputpath,
'-cJf',
os.path.join(os.path.dirname(outputpath), '{}.tar.xz'.format(os.path.basename(outputpath))),
'http',
'res',
'conf.json'
])