chiark / gitweb /
Cleanup whitespace
[cura.git] / scripts / create_lulzbot_profiles.py
1 #!/usr/bin/python
2
3 import glob
4 import os
5 import sys
6
7
8 CURA_QUICKPRINT_DIR="resources/quickprint/"
9 PROFILES_DIR="lulzbot_profiles"
10
11 dir_map = {
12     'Mini_single_extruder_v2': ('lulzbot_mini',),
13     'Mini_flexystruder_v2': ('lulzbot_mini_flexystruder',),
14     'TAZ_single_extruder_0.35nozzle': ('lulzbot_TAZ_4_SingleV1',
15                                        'lulzbot_TAZ_5_SingleV1',
16                                        'lulzbot_TAZ_4_035nozzle',
17                                        'lulzbot_TAZ_5_035nozzle'),
18     'TAZ_single_extruder_0.5nozzle': ('lulzbot_TAZ_4_05nozzle',
19                                       'lulzbot_TAZ_5_05nozzle'),
20     'TAZ_dual_extruder_v1': ('lulzbot_TAZ_4_DualV1',
21                              'lulzbot_TAZ_5_DualV1'),
22     'TAZ_dual_extruder_v2': ('lulzbot_TAZ_4_DualV2',
23                              'lulzbot_TAZ_5_DualV2'),
24     'TAZ_flexystruder_v1': ('lulzbot_TAZ_4_FlexystruderV1',
25                             'lulzbot_TAZ_5_FlexystruderV1'),
26     'TAZ_flexystruder_v2': ('lulzbot_TAZ_4_FlexystruderV2',
27                             'lulzbot_TAZ_5_FlexystruderV2'),
28     'TAZ_flexy_dually_v1': ('lulzbot_TAZ_4_FlexyDuallyV1',
29                             'lulzbot_TAZ_5_FlexyDuallyV1'),
30     'TAZ_flexy_dually_v2': ('lulzbot_TAZ_4_FlexyDuallyV2',
31                             'lulzbot_TAZ_5_FlexyDuallyV2'),
32 }
33
34 material_map = {
35     'ABS': 'ABS',
36     'PLA': 'PLA',
37     'HIPS': 'HIPS',
38     'ninjaflex': 'NinjaFlex',
39     'semiflex': 'SemiFlex',
40     'ABS_ninjaflex': 'ABS & NinjaFlex',
41     'ABS_semiflex': 'ABS & SemiFlex',
42     'PLA_PVA': 'PLA & PVA',
43     'ABS_dual_color': 'ABS & ABS',
44     'PLA_dual_color': 'PLA & PLA',
45     'PLA_PVA_support': 'PLA & PVA',
46 }
47
48 material_order = {
49     'ABS': 2,
50     'PLA': 1,
51     'HIPS': 0,
52     'ninjaflex': 0,
53     'semiflex': 1,
54     'ABS_ninjaflex': 0,
55     'ABS_semiflex': 1,
56     'PLA_PVA': 2,
57     'ABS_dual_color': 0, 
58     'PLA_dual_color': 1,
59     'PLA_PVA_support': 2,
60 }
61
62 profile_map = {
63     'high-quality': 'Fine',
64     'medium-quality': 'Normal',
65     'high-speed': 'Fast',
66 }
67
68 profile_order = {
69     'high-quality': 0,
70     'medium-quality': 1,
71     'high-speed': 2,
72 }
73
74 disable_materials = {
75     'PET': ('High', 'Low', 'Normal', 'Ulti'),
76     'PLA': ('High', 'Low', 'Normal', 'Ulti'),
77     'ABS': ('High', 'Low', 'Normal', 'Ulti')
78 }
79
80 def split_profile(filename):
81     material = None
82     profile = None
83     for m in material_map.keys():
84         if filename.startswith(m):
85             material = m
86             for p in profile_map.keys():
87                 if filename.startswith(m + "_" + p):
88                     profile = p
89                     return (material, profile)
90                     
91     return (material, profile)
92
93 def create_machine_type(machine_type, path, dir):
94     files = glob.glob(os.path.join(path, "*.ini"))
95     path = os.path.join(CURA_QUICKPRINT_DIR, machine_type)
96     for file in files:
97         filename = os.path.basename(file)
98         (material, profile) = split_profile(filename)
99         if material is None or profile is None:
100             continue
101         profile_file = os.path.join("..", "..", "..", PROFILES_DIR, dir, filename)
102         if not os.path.exists(os.path.join(path, material, profile)):
103             os.makedirs(os.path.join(path, material, profile))
104         with open(os.path.join(path, material, 'material.ini'), 'w') as f:
105             f.write("[info]\n")
106             f.write("name = %s\n" % material_map[material])
107             f.write("order = %d\n" % material_order[material])
108         with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
109             f.write("[info]\n")
110             f.write("name = %s\n" % profile_map[profile])
111             f.write("order = %d\n" % profile_order[profile])
112             f.write("profile_file = %s\n" % profile_file)
113     for material in disable_materials.keys():
114         if os.path.exists(os.path.join(path, material)):
115             for profile in disable_materials[material]:
116                 if not os.path.exists(os.path.join(path, material, profile)):
117                     os.makedirs(os.path.join(path, material, profile))
118                     with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
119                         f.write("[info]\n")
120                         f.write("disabled = true\n")
121         else:
122             os.makedirs(os.path.join(path, material))
123             with open(os.path.join(path, material, 'material.ini'), 'w') as f:
124                 f.write("[info]\n")
125                 f.write("disabled = true\n")
126                 
127
128 def main():
129     if not os.path.exists(CURA_QUICKPRINT_DIR):
130         print "Cura path is wrong"
131     return -1
132
133     dirs = glob.glob(os.path.join(CURA_QUICKPRINT_DIR, PROFILES_DIR, "*"))
134
135     for d in dirs:
136         dir = os.path.basename(d)
137     if dir_map.has_key(dir):
138         for machine_type in dir_map[dir]:
139             create_machine_type(machine_type, d, dir)
140
141
142 if __name__ == '__main__':
143     main()