-
Notifications
You must be signed in to change notification settings - Fork 8
/
check_quality_files.py
80 lines (56 loc) · 2.78 KB
/
check_quality_files.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import logging
import os.path
from _private.Profile import Profile
from _private.parameters import ParameterDefinitions
from _private.validate_parameters import validate_global_quality_values, validate_extruder_quality_values
def get_parameter_definitions() -> ParameterDefinitions:
logging.info("Reading fdmprinter.def.json")
definition_file_path = os.path.join("resources", "fdmprinter.def.json")
definition_file_path = os.path.abspath(definition_file_path)
parameter_definitions = ParameterDefinitions()
with open(definition_file_path, "r") as f:
serialized = f.read()
parameter_definitions.deserialize(serialized)
return parameter_definitions
def check_quality_dir(quality_dir: str) -> None:
for filename in os.listdir(quality_dir):
quality_path = os.path.join(quality_dir, filename)
logging.info("Processing quality file: %s", quality_path)
with open(quality_path, "r") as f:
serialized = f.read()
profile = Profile("Unknown")
profile.deserialize(serialized)
is_global_quality = profile.metadata["global_quality"] == "True"
if is_global_quality:
profile.set_global(True)
validate_global_quality_values(profile)
else:
profile.set_global(False)
validate_extruder_quality_values(profile)
# write it back
with open(quality_path, "w") as f:
serialized = profile.serialize()
f.write(serialized)
def main():
logging.basicConfig(level=logging.DEBUG)
logging.info("Checking quality files...")
parameter_definitions = get_parameter_definitions()
logging.info("%s parameters in total", len(parameter_definitions.parameters))
logging.info("Checking Snapmaker J1...")
plugin_profile_root_dir = os.path.join("resources", "snapmaker_j1_profiles")
plugin_profile_root_dir = os.path.abspath(plugin_profile_root_dir)
plugin_quality_dir = os.path.join(plugin_profile_root_dir, "quality", "snapmaker_j1")
check_quality_dir(plugin_quality_dir)
logging.info("Checking Snapmaker Artisan...")
plugin_profile_root_dir = os.path.join("resources", "snapmaker_artisan")
plugin_profile_root_dir = os.path.abspath(plugin_profile_root_dir)
plugin_quality_dir = os.path.join(plugin_profile_root_dir, "quality", "snapmaker_artisan")
check_quality_dir(plugin_quality_dir)
logging.info("Checking Snapmaker 2.0...")
plugin_profile_root_dir = os.path.join("resources", "snapmaker_2_dual_extruder")
plugin_profile_root_dir = os.path.abspath(plugin_profile_root_dir)
plugin_quality_dir = os.path.join(plugin_profile_root_dir, "quality", "snapmaker_2_dual_extruder")
check_quality_dir(plugin_quality_dir)
logging.info("Done.")
if __name__ == "__main__":
main()