-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_csvs.py
60 lines (51 loc) · 2.23 KB
/
generate_csvs.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
# ECSTATIC: Extensible, Customizable STatic Analysis Tester Informed by Configuration
#
# Copyright (c) 2022.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import argparse
import os
import sys
from pathlib import Path
from typing import Iterable, List
def main(file: str):
def find_all_violation_files(root: Path) -> Iterable[Path]:
for root, dirs, files in os.walk(root):
for f in files:
if f.endswith('.json'):
yield Path(root) / f
def generate_comma_separated_record(file: Path) -> str:
def reduce1(tokens: List[str]) -> str:
match tokens:
# Change 'results' to whatever your results folder is named.
case ['results', *rest]:
try:
return f"{rest[0]},{rest[1]},{int(rest[2])},{reduce(rest[3:])}"
except ValueError as ve:
return f"{rest[0]},{rest[1]},NONE,{reduce(rest[2:])}"
case [_, *rest]:
return reduce1(rest)
def reduce(tokens: List[str]) -> str:
match tokens:
case [head, *rest] if 'campaign' in head:
return f"{head},{reduce(rest)}"
case ['violations', *rest]:
return ','.join([*rest[:4], '/'.join(rest[4:-1]), rest[-1]])
case [head, *rest]:
return reduce(rest)
return reduce1(str(file).split('/'))
return generate_comma_separated_record(Path(file).absolute()).strip()
if __name__ == "__main__":
for file in sys.stdin:
print(main(file))