bottleclip: Do not require write access to the bottle-clip dir

This commit is contained in:
polyfloyd 2025-05-09 17:32:09 +02:00
parent deced2d3a7
commit 7011c67e2e

View file

@ -19,20 +19,26 @@ def list_icons() -> List[str]:
def create_stl(label: str, icon: str, ears: bool) -> NamedTemporaryFile: def create_stl(label: str, icon: str, ears: bool) -> NamedTemporaryFile:
icon_path = abspath(join(resource_dir(), "icons", icon)) icon_path = abspath(join(resource_dir(), "icons", icon))
ears_str = "true" if ears else "false" ears_str = "true" if ears else "false"
font_path = abspath(join(resource_dir(), "write/orbitron.dxf"))
scad = NamedTemporaryFile(dir=resource_dir(), suffix=".scad") scad = NamedTemporaryFile(suffix=".scad")
with open(join(resource_dir(), "bottle-clip.scad"), "rb") as f: with open(join(resource_dir(), "bottle-clip.scad"), "rb") as f:
scad.write(f.read()) scad.write(f.read())
scad.write(b"\n\n") scad.write(b"\n\n")
scad.write( scad.write(
f'bottle_clip(name="{label}", logo="{icon_path}", ears={ears_str});'.encode( f'bottle_clip(name="{label}", logo="{icon_path}", ears={ears_str}, font="{font_path}");'.encode(
"utf-8" "utf-8"
) )
) )
scad.flush() scad.flush()
stl = NamedTemporaryFile(suffix=".scad") stl = NamedTemporaryFile(suffix=".scad")
subprocess.run(["openscad", scad.name, "--export-format", "binstl", "-o", stl.name]) subprocess.run(
["openscad", scad.name, "--export-format", "binstl", "-o", stl.name],
env={
"OPENSCADPATH": resource_dir(),
},
)
stl.seek(0) stl.seek(0)
return stl return stl