-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbugsinpy.py
executable file
·108 lines (95 loc) · 2.93 KB
/
bugsinpy.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
108
#!/usr/bin/env python3
import sys
import os
import glob
import filecmp
import shutil
import re
BEFORE_FOLDER_NAME = "before"
AFTER_FOLDER_NAME = "after"
def main():
print("Starting checkout")
print("Projects : ")
print(projects())
for project in projects():
process(project)
def process(project):
print("Processing " + project)
bugs = active_bugs(project)
print(f"Found {str(bugs)} active bugs")
for bug in range(1, bugs + 1):
print(f"Checking bug {str(bug)}")
bug_before_path = f"{out_path}/{BEFORE_FOLDER_NAME}/{project}"/"{str(bug)}"
bug_after_path = f"{out_path}/{AFTER_FOLDER_NAME}/{project}"/"{str(bug)}"
if os.path.exists(bug_before_path) or os.path.exists(bug_after_path):
print(f"Bug {str(bug)} already processed, skipping")
continue
code = os.system(f"{b4p_bin}-info -p {project} -i {str(bug)}")
if code != 0:
print(f"Bug {str(bug)} is deprecated, skipping")
continue
os.system(f"mkdir -p {bug_before_path}")
os.system(f"mkdir -p {bug_after_path}")
os.system(f"{b4p_bin}-checkout -p {project} -v 0 -i {str(bug)} -w {tmp_path} /{BEFORE_FOLDER_NAME}")
os.system(f"{b4p_bin}-checkout -p {project} -v 1 -i {str(bug)} -w {tmp_path} /{AFTER_FOLDER_NAME}")
changed_files = compare(f"{tmp_path}/{BEFORE_FOLDER_NAME}/{project}", f"{tmp_path}/{AFTER_FOLDER_NAME}/{project}")
for changed_file in changed_files:
print(f"Copying {str(changed_file)}")
before_source = changed_file[1]
before_dest = f"{bug_before_path}/{changed_file[0].replace('/','_')}"
shutil.copyfile(before_source, before_dest)
after_source = changed_file[2]
after_dest = f"{bug_after_path}/{changed_file[0].replace('/','_')}"
shutil.copyfile(after_source, after_dest)
def active_bugs(project):
stream = os.popen(f"{b4p_bin}-info -p {project} | grep 'Number of bugs'")
output = stream.read()
match = re.search(r'Number of bugs\s+:\s+(\d+)', output.splitlines()[0])
return int(match.group(1))
def compare(before, after):
comparison = []
for file in glob.glob(f"{BEFORE_FOLDER_NAME}/**/*.py", recursive = True):
base = file[len(before) + 1:]
other = f"{after}/{base}"
if os.path.exists(other):
if filecmp.cmp(file, other) == False:
comparison.append((base, file, other))
return comparison
def projects():
projects = '''sanic
spacy
tornado
youtube-dl
ansible
cookiecutter
httpie
luigi
pandas
scrapy
thefuck
tqdm'''
return projects.splitlines()
def backup_projects():
projects = '''PySnooper
black
fastapi
keras
matplotlib
sanic
spacy
tornado
youtube-dl
ansible
cookiecutter
httpie
luigi
pandas
scrapy
thefuck
tqdm'''
return projects.splitlines()
if __name__ == '__main__':
b4p_bin = sys.argv[1]
out_path = sys.argv[2]
tmp_path = sys.argv[3]
main()