-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathprocess.py
More file actions
77 lines (64 loc) · 2.25 KB
/
Copy pathprocess.py
File metadata and controls
77 lines (64 loc) · 2.25 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
import argparse
import csv
import pandas as pd
from os import listdir
from os.path import isfile, join
def devign(root_folder, projects):
files = [f for f in listdir(projects) if isfile(join(projects, f))]
df = pd.concat([pd.read_csv(f"{projects}/{file}") for file in files])
df = df[df["vulnerability"] == 1]
df.drop("vulnerability", inplace=True, axis=1)
df.to_csv(f"{root_folder}/github-devign-patches.csv", index=False)
def big_vul(root_folder, fin, fout):
df = pd.read_csv(f"{root_folder}/{fin}")
df = df.rename(columns={"ref_link": "refs"})
df["refs"] = df["refs"].apply(lambda ref: set([ref]))
df.to_csv(
f"{root_folder}/{fout}",
quoting=csv.QUOTE_NONNUMERIC,
escapechar="\\",
doublequote=False,
index=False,
)
def sap(root_folder, fin, fout):
df = pd.read_csv(f"{root_folder}/{fin}")
df["refs"] = df.apply(lambda x: f"{x['project']}/commit/{x['sha']}", axis=1)
df.to_csv(f"{root_folder}/{fout}", index=False)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Research Datasets Processor")
parser.add_argument(
"--root-folder",
type=str,
metavar="input folder",
help="folder where the data is available",
)
parser.add_argument(
"--fin", type=str, metavar="input file", help="file where the data is available"
)
parser.add_argument(
"--fout",
type=str,
metavar="input file",
help="file where the data is available",
)
parser.add_argument(
"--projects",
type=str,
metavar="projects folder",
help="folder where the data is available",
)
parser.add_argument(
"--name",
type=str,
metavar="research dataset name",
help="research dataset name",
)
args = parser.parse_args()
if args.root_folder and args.projects and args.name == "devign":
devign(args.root_folder, args.projects)
elif args.root_folder and args.fin and args.name == "big_vul":
big_vul(args.root_folder, args.fin, args.fout)
elif args.root_folder and args.fin and args.fout and args.name == "sap":
sap(args.root_folder, args.fin, args.fout)
else:
print("Something is wrong.")