/
gen.py
30 lines (24 loc) · 751 Bytes
/
gen.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
import glob
import json
from pathlib import Path
from pprint import pprint
root_dir = "./examples"
result = {}
for filename in glob.iglob(root_dir + '**/**', recursive=True):
p = Path(filename)
if p.suffix not in [".env", ".l2"]:
continue
content = open(p).read()
# print(p, "suffix = ", p.suffix)
parts = p.parts
if len(parts) == 2:
if not parts[0] in result:
result[parts[0]] = {}
result[parts[0]][parts[1]] = content
elif len(parts) == 3:
if not parts[0] in result:
result[parts[0]] = {}
if not parts[1] in result[parts[0]]:
result[parts[0]][parts[1]] = {}
result[parts[0]][parts[1]][parts[2]] = content
print(json.dumps(result))