-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_single.py
65 lines (54 loc) · 1.91 KB
/
execute_single.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
import os.path
import subprocess
import sys
from pathlib import Path
from mbta.treatment.representation.files.javafile import JavaFile
from mbta.treatment.representation.files.pythonfile import PythonFile
from mbta.treatment.representation.files.sourcefile import SourceFile
from mbta.treatment.representation.visitor.executorvisitor import ExecutorVisitor
def create_file_representation(path: Path) -> SourceFile:
if path.suffix == ".py":
return PythonFile(path)
elif path.suffix == ".java":
return JavaFile(path)
else:
pass
def unzip_mutant(path: str, mutant):
mutant_path = Path("MuJava/result/" + mutant)
command = f'''
cd {path}
unzip -q -o MuJava.zip "{mutant_path}"
'''
with subprocess.Popen(command, shell=True) as process_object:
process_object.wait()
def zip_results(path: str, mutant):
mutant_path = Path("MuJava/result/" + mutant)
command = f'''
cd {path}
zip -q "{sys.argv[3]}" "{mutant_path.with_suffix(".csv")}"
'''
with subprocess.Popen(command, shell=True) as process_object:
process_object.wait()
def remove_dir(path: str, mutant: str):
mutant_path = Path("MuJava/result/" + mutant)
command = f'''
cd {path}
rm -rf "{mutant_path.parent}"
'''
with subprocess.Popen(command, shell=True) as process_object:
process_object.wait()
try:
file = create_file_representation(Path(os.path.join(sys.argv[1], "MuJava", "result", sys.argv[2])))
if isinstance(file, JavaFile):
unzip_mutant(sys.argv[1], Path(sys.argv[2]).with_suffix(".class"))
else:
unzip_mutant(sys.argv[1], sys.argv[2])
print("Executing " + str(file.source_path))
translate_visitor = ExecutorVisitor(file.source_path.parent.name)
file.accept(translate_visitor)
print("Zipping results...")
zip_results(sys.argv[1], sys.argv[2])
finally:
print("Removing files...")
remove_dir(sys.argv[1], sys.argv[2])
print("Done!")