-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildStore.py
More file actions
110 lines (89 loc) · 2.36 KB
/
buildStore.py
File metadata and controls
110 lines (89 loc) · 2.36 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
109
110
import csv
import json
import os
from dataclasses import dataclass
from pathlib import Path
OUTPUT_DIR = "release"
OUTPUT_FILE = "sudoFrameworks.json"
INPUT_FILE = "data/quillFrameworks.csv"
VERSION = "v.0.1.0"
@dataclass
class FrameworkVersion:
id: str
release_date: str
stable: bool
def to_dict(self) -> dict:
info = {
"id": self.id,
"release_date": self.release_date,
"stable": self.stable,
}
return info
@dataclass
class FramworkEntry:
name: str
publisher: str
url: str
version: FrameworkVersion
def to_dict(self) -> dict:
info = {
"name": self.name,
"publisher": self.publisher,
"url": self.url,
"version": self.version.to_dict(),
}
return info
@staticmethod
def from_row(info: list):
return FramworkEntry(
name=info[0],
publisher=info[1],
url=info[2],
version=FrameworkVersion(
id=info[3],
release_date=info[4],
stable=True if info[5] == "true" else False,
),
)
def read_file() -> list[FramworkEntry]:
entries = []
with open(
INPUT_FILE,
"r",
newline="",
) as csvFile:
frameworkReader = csv.reader(csvFile, delimiter=",")
# skip header row
next(frameworkReader)
for eachRow in frameworkReader:
entry = FramworkEntry.from_row(eachRow)
entries.append(entry)
print("list of farmeworks generated")
return entries
def output_file(entries: list[FramworkEntry]):
# ensure our output path exists
path = Path(OUTPUT_DIR)
if path.is_dir():
pass
else:
# create path if it does not yet exist
os.mkdir(OUTPUT_DIR)
frameworks = []
for each in entries:
frameworks.append(each.to_dict())
output_json = {
"version": VERSION,
"frameworks": frameworks,
}
# output file to disk
output_file = path / OUTPUT_FILE
print(f"writing {output_file} to disk")
with open(output_file, "w") as json_file:
json.dump(output_json, json_file)
def main() -> None:
print(f"reading {INPUT_FILE}")
entries = read_file()
print("outputting file to disk")
output_file(entries)
if __name__ == "__main__":
main()