-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefects4j_checkout.py
More file actions
executable file
·108 lines (86 loc) · 2.53 KB
/
defects4j_checkout.py
File metadata and controls
executable file
·108 lines (86 loc) · 2.53 KB
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
108
#!/usr/bin/env python3
#projects = {'Chart': 26,
# 'Closure': 176,
# 'Lang': 65,
# 'Math': 106,
# 'Mockito': 38,
# 'Time': 27 }
#vers = ['b', 'f']
projects = {'Chart': 1,
'Lang': 1, }
vers = ['f']
# DO NOT PASS.
import sys, os, subprocess, shutil
defects4j = 'defects4j'
fail_ok = False
user_choices = []
failed = {name : [] for name in projects}
def exit(rc):
global failed
if any(failed.values()):
print('Failed checkouts:')
for name, revs in failed.items():
if not revs:
continue
print(' {}'.format(name), end=' ')
for rev in revs:
print('{}'.format(rev[0]), end=' ')
print()
user = input('\n>> Remove revision? [Y/n] ')
if user == '' or user.lower() == 'y':
for rev in revs:
shutil.rmtree(rev[1])
sys.exit(rc)
def usage():
print('usage: {} [-f] proj_name...'.format(sys.argv[0]))
if not shutil.which(defects4j):
print("error: cannot find executable '{}'".format(defects4j))
exit(1)
if len(sys.argv) == 1:
usage()
exit(1)
for i in range(1, len(sys.argv)):
arg = sys.argv[i]
if arg == '-f':
fail_ok = True
elif arg == '-h':
usage()
exit(0)
else:
if arg not in projects:
print("error: bad project name '{}'".format(arg))
exit(1)
else:
user_choices.append(arg)
if not user_choices:
usage()
exit(1)
for key in list(projects.keys()):
if key not in user_choices:
projects.pop(key)
base = os.path.join('data', 'in')
os.makedirs(base, exist_ok=True)
for name, count in projects.items():
for num in range(1, count+1):
for ver in vers:
num = str(num)
rev = num + ver
d = os.path.join(base, name, rev)
os.makedirs(d, exist_ok=True)
cmd = [defects4j,
'checkout',
'-p', name,
'-v', rev,
'-w', d, ]
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
failed[name].append((rev, d))
if not fail_ok:
user = input('\n\n>> Failed to checkout {} {}. Continue? [Y/n] '.format(name, rev))
if user == '' or user.lower() == 'y':
pass
else:
exit(1)
print()
exit(0)