forked from eclipseo/image-comparison-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_files_json.py
executable file
·41 lines (35 loc) · 1.29 KB
/
generate_files_json.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
#!/usr/bin/python3
import os
import json
import glob
data = {}
data["comparisonfiles"] = {}
for subset in next(os.walk("comparisonfiles/"))[1]:
data["comparisonfiles"][subset] = {}
data["comparisonfiles"][subset]["format"] = []
format_list = [
format for format in next(os.walk("comparisonfiles/" + subset + "/large"))[1]
]
for format in format_list:
extension = [
os.path.splitext(os.path.basename(fn))[1][1:]
for fn in glob.glob("comparisonfiles/" + subset + "/large/" + format + "/*")
if os.path.splitext(os.path.basename(fn))[1] != ".png"
][0]
data["comparisonfiles"][subset]["format"].append(
{"extension": extension, "name": format}
)
data["comparisonfiles"][subset]["format"].append(
{"extension": "png", "name": "Original"}
)
filenames_list = [
os.path.splitext(os.path.basename(files))[0]
for files in next(os.walk("comparisonfiles/" + subset + "/Original/"))[2]
]
data["comparisonfiles"][subset]["files"] = []
for filename in filenames_list:
data["comparisonfiles"][subset]["files"].append(
{"title": "", "filename": filename}
)
with open("comparisonfiles.json", "w") as outfile:
json.dump(data, outfile, indent=4)