Skip to content

Commit 9a2dbb7

Browse files
Move generate_static.py to use new Shelf classes
1 parent 098975c commit 9a2dbb7

File tree

4 files changed

+46
-129
lines changed

4 files changed

+46
-129
lines changed

generate_static.py

+30-114
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
direct download without them needing to be committed to the repository
88
"""
99
import os
10+
import json
1011

1112
from cadorchestrator.generate import generate_components
12-
from cadorchestrator.components import GeneratedMechanicalComponent
13-
from nimble_build_system.orchestration.paths import BUILD_DIR, REL_MECH_DIR
13+
14+
from nimble_build_system.orchestration.paths import BUILD_DIR
15+
16+
from nimble_build_system.cad.shelf import create_shelf_for
1417

1518
def generate():
1619
"""
@@ -28,100 +31,20 @@ def get_component_list():
2831
shelves
2932
"""
3033

31-
components = []
32-
33-
components.append(
34-
generate_leg(
35-
length=294,
36-
mounting_holes_dia=3.6,
37-
name="Rack leg with 21 holes",
38-
out_file="./printed_components/beam-21holes.stl"
39-
)
40-
)
41-
components.append(
42-
generate_leg(
43-
length=168,
44-
mounting_holes_dia=3.6,
45-
name="Rack leg with 12 holes",
46-
out_file="./printed_components/beam-12holes.stl"
47-
)
48-
)
49-
50-
components.append(
51-
generate_leg(
52-
length=294,
53-
mounting_holes_dia=5.8,
54-
name="Rack leg with 21 M6 holes",
55-
out_file="./printed_components/beam-M6-21holes.stl"
56-
)
57-
)
58-
59-
components.append(
60-
generate_leg(
61-
length=168,
62-
mounting_holes_dia=5.8,
63-
name="Rack leg with 12 M6 holes",
64-
out_file="./printed_components/beam-M6-12holes.stl"
65-
)
66-
)
67-
68-
for (shelf_type, height_in_u) in [
69-
("stuff", 3),
70-
("stuff-thin", 3),
71-
("nuc", 3),
72-
("nuc", 4),
73-
("usw-flex", 3),
74-
("usw-flex-mini", 2),
75-
("anker-powerport5", 2),
76-
("anker-a2123", 2),
77-
("anker-atom3slim", 2),
78-
("hdd35", 2),
79-
("dual-ssd", 2),
80-
("raspi", 2)]:
81-
82-
components.append(generate_shelf(shelf_type, height_in_u))
83-
84-
return components
85-
86-
87-
def generate_leg(length, mounting_holes_dia, name, out_file):
88-
"""
89-
Helper function to generate a leg. Returns a GeneratedMechanicalComponent
90-
object which contains the data for the leg.
91-
"""
92-
source = os.path.join(REL_MECH_DIR, "components/cadquery/rack_leg.py")
93-
key = name.lower().replace(' ', '_')
94-
return GeneratedMechanicalComponent(
95-
key=key,
96-
name=name,
97-
description='A leg for a nimble rack',
98-
output_files=[out_file],
99-
source_files=[source],
100-
parameters={
101-
"length": length,
102-
"mounting_holes_dia": mounting_holes_dia
103-
},
104-
application="cadquery"
105-
)
106-
107-
108-
def generate_shelf(shelf_type, height_in_u):
109-
"""
110-
Helper function to generate a shelf/tray. Returns a GeneratedMechanicalComponent
111-
object which contains the data for the shelf.
112-
"""
113-
out_file = f"./printed_components/shelf_6in_{shelf_type}u_{height_in_u}.stl"
114-
source = os.path.join(REL_MECH_DIR, "components/cadquery/tray_6in.py")
115-
device_name = shelf_type.replace('-', ' ')
116-
return GeneratedMechanicalComponent(
117-
key=f"{shelf_type}_{height_in_u}u",
118-
name=f"Tray for {device_name}",
119-
description=f"Tray for {device_name}, height = {height_in_u}u",
120-
output_files=[out_file],
121-
source_files=[source],
122-
parameters={'shelf_type': shelf_type, 'height_in_u': height_in_u},
123-
application="cadquery"
124-
)
34+
component_list = []
35+
36+
#Loop through the options dictionary that the web ui uses for config options
37+
with open('OrchestratorConfigOptions.json', encoding="utf-8") as config_options_file:
38+
conf_options = json.load(config_options_file)
39+
40+
for device_category_dict in conf_options['options'][0]['add-options']:
41+
for device in device_category_dict['items']:
42+
device_id = device['value']
43+
shelf = create_shelf_for(device_id)
44+
component_list.append(shelf.shelf_component)
45+
#return a list of GeneratedMechanicalComponent objects
46+
return component_list
47+
12548

12649
def output_static_site(components):
12750
"""
@@ -139,37 +62,30 @@ def output_static_site(components):
13962
</style>
14063
</head>
14164
<body>
142-
65+
14366
<h1>
144-
Nimble STL files
67+
Nimble downloads
14568
</h1>
14669
70+
<h2>Auto-generated documentation:</h3>
14771
<p>
148-
Nimble is going through a transition towards live generation of all files and documentation
149-
for hardware configuration. We call this "Smart Doc". For more details on Nimble see
150-
<a href="https://github.com/Wakoma/nimble">https://github.com/Wakoma/nimble</a>
72+
We are working on a system to automatically generate documentation for any
73+
nimble configuration. This is an example of the <a href="assembly-docs">
74+
automatically generated documentation</a> for a specific configuration.
15175
</p>
15276
77+
<h2>Shelf STL files:</h3>
15378
<p>
154-
Smart Doc" is not yet finished, but the code already generates a number of nimble components
155-
that may be useful to you. You can find them below.
79+
While we work on builing the nimble configurator you can download all
80+
nimble shelves from the list below
15681
</p>
157-
15882
""")
15983

160-
f.write("<h3>Generated files:</h3>")
84+
f.write("")
16185
f.write("<ul>")
16286
for component in components:
163-
f.write(f"<li><a href='{component.output_files[0]}'>{component.name}</a></li>")
87+
f.write(f"<li><a href='{component.stl_representation}'>{component.name}</a></li>")
16488
f.write("</ul>")
165-
f.write(
166-
"""
167-
<h3>Example documentation:</h3>
168-
<p>
169-
Partially complete automatically generated documentation
170-
<a href="assembly-docs">is also available</a>.
171-
</p>
172-
""")
17389

17490
f.write("</body></html>")
17591

mechanical/components/cadquery/tray_6in.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
the nimble_build_system.cad ShelfBuilder.
66
"""
77

8-
import json
9-
import cadscript as cad
108

9+
import cadscript as cad
1110

1211
from nimble_build_system.cad.shelf import create_shelf_for
1312

nimble_build_system/cad/shelf.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import posixpath
3+
import warnings
34

45
import yaml
56
from cadorchestrator.components import AssembledComponent, GeneratedMechanicalComponent
@@ -39,16 +40,18 @@ def create_shelf_for(device_id: str,
3940

4041
if shelf_type in SHELF_TYPES:
4142
shelf_class, kwargs = SHELF_TYPES[shelf_type]
42-
return shelf_class(
43-
device,
44-
assembly_key,
45-
position,
46-
color,
47-
rack_params,
48-
**kwargs
49-
)
50-
raise ValueError(f"Unknown shelf type {shelf_type}")
51-
43+
else:
44+
warnings.warn(RuntimeWarning(f"Unknown shelf type {shelf_type}"))
45+
shelf_class = Shelf
46+
kwargs = {}
47+
return shelf_class(
48+
device,
49+
assembly_key,
50+
position,
51+
color,
52+
rack_params,
53+
**kwargs
54+
)
5255

5356
class Shelf():
5457
"""
@@ -539,4 +542,3 @@ def generate_assembly_model(self,
539542
"dual-ssd": (DualSSDShelf, {}),
540543
"raspi": (RaspberryPiShelf, {})
541544
}
542-

nimble_build_system/orchestration/device.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ def shelf_key(self):
9999
def clean_name(name):
100100
name = name.lower()
101101
name = name.replace(' ', '_')
102-
unsafe_char = re.findall(r'[a-zA-Z0-9-_]', name)
102+
unsafe_char = re.findall(r'[^a-zA-Z0-9-_]', name)
103103
for char in set(unsafe_char):
104-
name.replace(char, '')
104+
name = name.replace(char, '')
105105
return name
106106
return f"shelf_h{self.height_in_u}_--{clean_name(self.shelf_type)}"
107107

0 commit comments

Comments
 (0)