-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathojrunnerlinux.py
53 lines (44 loc) · 1.6 KB
/
ojrunnerlinux.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
import lorun
import os
import codecs
import random
import subprocess
import config
import sys
RESULT_MAP = [
2, 10, 5, 4, 3, 6, 11, 7, 12
]
class Runner:
def __init__(self):
return
def compile(self, judger, srcPath, outPath):
cmd = config.langCompile[judger.lang] % {'root': sys.path[0], 'src': srcPath, 'target': outPath}
p = subprocess.Popen(cmd, shell = True,
stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.STDOUT)
retval = p.wait()
return (retval, p.stdout.read())
def judge(self, judger, srcPath, outPath, inFile, ansFile, memlimit, timelimit):
cmd = config.langRun[judger.lang] % {'src': srcPath, 'target': outPath}
fout_path = "".join([sys.path[0], "/", "%s/%d.out" % (config.dataPath["tempPath"], random.randint(0, 65536))])
if os.path.exists(fout_path):
os.remove(fout_path)
fin = open(inFile, 'rU')
fout = open(fout_path, 'w')
runcfg = {
'args': cmd.split(" "),
'fd_in': fin.fileno(),
'fd_out': fout.fileno(),
'timelimit': int(timelimit),
'memorylimit': int(memlimit)
}
rst = lorun.run(runcfg)
fin.close()
fout.close()
if rst['result'] == 0:
fans = open(ansFile, 'rU')
fout = open(fout_path, 'rU')
crst = lorun.check(fans.fileno(), fout.fileno())
fout.close()
fans.close()
return (RESULT_MAP[crst], int(rst['memoryused']), int(rst['timeused']))
return (RESULT_MAP[rst['result']], 0, 0)