1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-09-04 04:35:29 +02:00

Compare commits

...

14 Commits

Author SHA1 Message Date
Chris Palmer
0a84bf0927 plateup.py now saves the used files to speed up processing when a part hasn't changed.
Added times to plateup.py.
2021-02-11 09:10:15 +00:00
Chris Palmer
da825b17ab Added colorama.init() to plateup.py to handle new coloured changed messages. 2021-02-10 10:22:38 +00:00
Chris Palmer
ca153c971d Fixed platters and panels not working in the GUI, a regression.
set_config() now puts $cwd in target.scad.
use_stl() and use_dxf() included again instead of used.
2021-02-10 10:17:03 +00:00
Chris Palmer
60350eb228 Updated gallery.py for new page break format. 2021-02-09 23:44:03 +00:00
Chris Palmer
4f9729cf86 Now shows what changed to trigger an openscad invocation in cyan. 2021-02-09 23:32:53 +00:00
Chris Palmer
26f1338ca2 Fixed removal of old deps 2021-02-09 14:34:27 +00:00
Chris Palmer
fc44b43638 Temporary files used during make_all and tests now in tmp dir. 2021-02-09 09:52:26 +00:00
Chris Palmer
182f39876a Moved deps directories to separate stl deps from views deps. 2021-02-09 09:18:30 +00:00
Chris Palmer
055e90cbb3 /stls/ and /dxfs/ excluded from deps to prevent circular dependencies. 2021-02-08 22:44:21 +00:00
Chris Palmer
832380f893 Fixed set_config always writing to target.scad. 2021-02-08 20:31:10 +00:00
Chris Palmer
929d082b25 openscad.py now quits if there are errors or warnings in the log.
This is because the exit status is not always set correctly.
2021-02-08 16:03:59 +00:00
Chris Palmer
57212b5701 set_config.py now defines $target. 2021-02-08 15:00:44 +00:00
Chris Palmer
1c3f136657 Fixed $cwd and $target not defined during silent run. 2021-02-08 15:00:01 +00:00
Chris Palmer
cfd2fd32a1 Now checks openscad.echo for warnings when used instead of openscad.log. 2021-02-08 14:58:50 +00:00
15 changed files with 180 additions and 79 deletions

View File

@@ -1,40 +1,30 @@
# A gallery of projects made with NopSCADlib # A gallery of projects made with NopSCADlib
<a name="TOP"></a>
## ArduinoThermostat ## ArduinoThermostat
Arduino thermostat to control a beer fridge to use it as an environmental chamber. Arduino thermostat to control a beer fridge to use it as an environmental chamber.
![](ArduinoThermostat.png) ![](ArduinoThermostat.png)
<a name="TOP"></a>
## EnviroPlus ## EnviroPlus
Environmental monitor using Enviro+ sensor board and a Raspberry Pi Zero. Environmental monitor using Enviro+ sensor board and a Raspberry Pi Zero.
![](EnviroPlus.png) ![](EnviroPlus.png)
<a name="TOP"></a>
## FilamentDryBox ## FilamentDryBox
A small fan oven with a spool holder to keep the filament warm and dry. A small fan oven with a spool holder to keep the filament warm and dry.
![](FilamentDryBox.png) ![](FilamentDryBox.png)
<a name="TOP"></a>
## HydraBot ## HydraBot
Current state of HydraRaptor after being modified for laser engraving. Current state of HydraRaptor after being modified for laser engraving.
![](HydraBot.png) ![](HydraBot.png)
<a name="TOP"></a>
## IOT 50V PSU ## IOT 50V PSU
WiFi controllable PSU WiFi controllable PSU
![](IOT_50V_PSU.png) ![](IOT_50V_PSU.png)
<a name="TOP"></a>
## Lab ATX PSU ## Lab ATX PSU
Bench power supply built around an ATX PSU. Bench power supply built around an ATX PSU.
@@ -47,15 +37,11 @@ Bench power supply built around an ATX PSU.
<a name="TOP"></a>
## Laser Load ## Laser Load
15kV dummy load for testing CO2 laser PSUs 15kV dummy load for testing CO2 laser PSUs
![](Laser_load.png) ![](Laser_load.png)
<a name="TOP"></a>
## MainsBreakOutBox ## MainsBreakOutBox
13A socket break out box with 4mm jacks to measure voltage and / or load current and earth leakage current. 13A socket break out box with 4mm jacks to measure voltage and / or load current and earth leakage current.
@@ -72,8 +58,6 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
![](MainsBreakOutBox.png) ![](MainsBreakOutBox.png)
<a name="TOP"></a>
## Mains Box ## Mains Box
Mains isolated and variable supply with metering. Mains isolated and variable supply with metering.
@@ -81,15 +65,11 @@ Mains isolated and variable supply with metering.
<a name="TOP"></a>
## SunBot ## SunBot
A solar tracker to keep a solar panel pointing at the sun. A solar tracker to keep a solar panel pointing at the sun.
![](SunBot.png) ![](SunBot.png)
<a name="TOP"></a>
## Turntable ## Turntable
WiFi enabled remote control turntable for photography WiFi enabled remote control turntable for photography
@@ -97,8 +77,6 @@ WiFi enabled remote control turntable for photography
Was actually made from DiBond but shown made with carbon fibre here. Was actually made from DiBond but shown made with carbon fibre here.
<a name="TOP"></a>
## Variac ## Variac
Motorised variac with WiFi control, see [hydraraptor.blogspot.com/2018/04/esp8266-spi-spy](https://hydraraptor.blogspot.com/2018/04/esp8266-spi-spy.html) Motorised variac with WiFi control, see [hydraraptor.blogspot.com/2018/04/esp8266-spi-spy](https://hydraraptor.blogspot.com/2018/04/esp8266-spi-spy.html)
@@ -106,4 +84,3 @@ Motorised variac with WiFi control, see [hydraraptor.blogspot.com/2018/04/esp826

View File

@@ -18,6 +18,7 @@
# #
import os import os
from set_config import source_dir from set_config import source_dir
from colorama import Fore
def mtime(file): def mtime(file):
if os.path.isfile(file): if os.path.isfile(file):
@@ -41,13 +42,13 @@ def read_deps(dname):
def check_deps(target, dname): def check_deps(target, dname):
target_mtime = mtime(target) target_mtime = mtime(target)
if not target_mtime: if not target_mtime:
return target + " missing" return Fore.CYAN + target + " missing" + Fore.WHITE
if not os.path.isfile(dname): if not os.path.isfile(dname):
return "no deps" return Fore.CYAN + "no deps" + Fore.WHITE
deps = read_deps(dname) deps = read_deps(dname)
for dep in deps: for dep in deps:
if mtime(dep) > target_mtime: if mtime(dep) > target_mtime:
return dep + ' changed' return Fore.CYAN + dep + ' changed' + Fore.WHITE
return None return None
def source_dirs(bom_dir): def source_dirs(bom_dir):

View File

@@ -28,7 +28,10 @@ from set_config import *
import time import time
import times import times
from deps import * from deps import *
from tmpdir import *
import json import json
import shutil
from colorama import Fore, init
def bom_to_parts(bom_dir, part_type, assembly = None): def bom_to_parts(bom_dir, part_type, assembly = None):
# #
@@ -43,7 +46,7 @@ def bom_to_parts(bom_dir, part_type, assembly = None):
if words: if words:
last_word = words[-1] last_word = words[-1]
if last_word.endswith(suffix): if last_word.endswith(suffix):
part_files.append(last_word[:-4] + '.' + part_type) part_files.append(last_word[:-4] + '.' + part_type)
return part_files return part_files
def usage(t): def usage(t):
@@ -62,12 +65,20 @@ def make_parts(target, part_type, parts = None):
# #
top_dir = set_config(target, lambda: usage(part_type)) top_dir = set_config(target, lambda: usage(part_type))
target_dir = top_dir + part_type + 's' target_dir = top_dir + part_type + 's'
deps_dir = top_dir + "deps" deps_dir = target_dir + "/deps"
bom_dir = top_dir + "bom" bom_dir = top_dir + "bom"
tmp_dir = mktmpdir(top_dir)
if not os.path.isdir(target_dir): if not os.path.isdir(target_dir):
os.makedirs(target_dir) os.makedirs(target_dir)
if not os.path.isdir(deps_dir): if not os.path.isdir(deps_dir):
os.makedirs(deps_dir) os.makedirs(deps_dir)
old_deps = top_dir + 'deps' #old location
if os.path.isdir(old_deps):
shutil.rmtree(old_deps)
times.read_times(target_dir) times.read_times(target_dir)
# #
# Decide which files to make # Decide which files to make
@@ -120,15 +131,15 @@ def make_parts(target, part_type, parts = None):
changed = check_deps(part_file, dname) changed = check_deps(part_file, dname)
changed = times.check_have_time(changed, part) changed = times.check_have_time(changed, part)
if part_type == 'stl' and not changed and not part in bounds_map: if part_type == 'stl' and not changed and not part in bounds_map:
changed = "No bounds" changed = Fore.CYAN + "No bounds" + Fore.WHITE
if changed: if changed:
print(changed) print(changed)
# #
# make a file to use the module # make a file to use the module
# #
part_maker_name = part_type + ".scad" part_maker_name = tmp_dir + '/' + part_type + ".scad"
with open(part_maker_name, "w") as f: with open(part_maker_name, "w") as f:
f.write("use <%s/%s>\n" % (dir, filename)) f.write("use <%s/%s>\n" % (reltmp(dir, target), filename))
f.write("%s();\n" % module); f.write("%s();\n" % module);
t = time.time() t = time.time()
openscad.run("-D$bom=1", "-d", dname, "-o", part_file, part_maker_name) openscad.run("-D$bom=1", "-d", dname, "-o", part_file, part_maker_name)
@@ -145,6 +156,10 @@ def make_parts(target, part_type, parts = None):
with open(bounds_fname, 'w') as outfile: with open(bounds_fname, 'w') as outfile:
json.dump(bounds_map, outfile, indent = 4) json.dump(bounds_map, outfile, indent = 4)
# #
# Remove tmp dir
#
rmtmpdir(tmp_dir)
#
# List the ones we didn't find # List the ones we didn't find
# #
if targets: if targets:

View File

@@ -68,9 +68,10 @@ def gallery(force):
match = re.match(r"^(#+).*$", line) match = re.match(r"^(#+).*$", line)
if match: if match:
line = '#' + line line = '#' + line
if line == '---\n': if line == '---\n' or line == '<span></span>\n':
break; break
print(line[:-1], file = output_file) if line != '<a name="TOP"></a>\n':
print(line[:-1], file = output_file)
else: else:
print(Fore.MAGENTA + "Can't find", document, Fore.WHITE); print(Fore.MAGENTA + "Can't find", document, Fore.WHITE);
with open(target_dir + "/readme.html", "wt") as html_file: with open(target_dir + "/readme.html", "wt") as html_file:

View File

@@ -32,12 +32,18 @@ def run_list(args, silent = False, verbose = False):
print() print()
with open("openscad.log", "w") as log: with open("openscad.log", "w") as log:
rc = subprocess.call(cmd, stdout = log, stderr = log) rc = subprocess.call(cmd, stdout = log, stderr = log)
for line in open("openscad.log", "rt"): log_file = "openscad.echo" if "openscad.echo" in cmd else "openscad.log"
bad = False
for line in open(log_file, "rt"):
if verbose or 'ERROR:' in line or 'WARNING:' in line: if verbose or 'ERROR:' in line or 'WARNING:' in line:
bad = True
print(line[:-1]) print(line[:-1])
if rc: if rc:
sys.exit(rc) sys.exit(rc)
if bad:
sys.exit(1)
def run(*args): def run(*args):
run_list(list(args), False) run_list(list(args), False)

View File

@@ -20,6 +20,7 @@
# Set command line options from enviroment variables and check if they have changed # Set command line options from enviroment variables and check if they have changed
import json, os, deps import json, os, deps
from colorama import Fore, init
def check_options(dir = '.'): def check_options(dir = '.'):
global options, options_mtime global options, options_mtime
@@ -37,7 +38,7 @@ def check_options(dir = '.'):
def have_changed(changed, target): def have_changed(changed, target):
if not changed and deps.mtime(target) < options_mtime: if not changed and deps.mtime(target) < options_mtime:
return "command line options changed" return Fore.CYAN + "command line options changed" + Fore.WHITE
return changed return changed
def list(): def list():

View File

@@ -26,8 +26,10 @@ import sys
import c14n_stl import c14n_stl
from set_config import * from set_config import *
from deps import * from deps import *
from shutil import copyfile import shutil
import re import re
import time
import times
source_dirs = { "stl" : "platters", "dxf" : "panels" } source_dirs = { "stl" : "platters", "dxf" : "panels" }
target_dirs = { "stl" : "printed", "dxf" : "routed" } target_dirs = { "stl" : "printed", "dxf" : "routed" }
@@ -41,11 +43,14 @@ def plateup(target, part_type, usage = None):
target_dir = parts_dir + '/' + target_dirs[part_type] target_dir = parts_dir + '/' + target_dirs[part_type]
source_dir1 = source_dirs[part_type] source_dir1 = source_dirs[part_type]
source_dir2 = top_dir + source_dirs[part_type] source_dir2 = top_dir + source_dirs[part_type]
times.read_times(target_dir)
# #
# Loop through source directories # Loop through source directories
# #
used = [] all_used = []
all_sources = [] all_sources = []
all_parts = []
for dir in [source_dir1, source_dir2]: for dir in [source_dir1, source_dir2]:
if not os.path.isdir(dir): if not os.path.isdir(dir):
continue continue
@@ -54,9 +59,12 @@ def plateup(target, part_type, usage = None):
# #
# Make the deps dir # Make the deps dir
# #
deps_dir = dir + "/deps" deps_dir = parts_dir + "/deps"
if not os.path.isdir(deps_dir): if not os.path.isdir(deps_dir):
os.makedirs(deps_dir) os.makedirs(deps_dir)
if os.path.isdir(dir + '/deps'): #old deps
shutil.rmtree(dir + '/deps')
# #
# Decide which files to make # Decide which files to make
# #
@@ -65,42 +73,55 @@ def plateup(target, part_type, usage = None):
# #
# Run OpenSCAD on the source files to make the targets # Run OpenSCAD on the source files to make the targets
# #
target_def = ['-D$target="%s"' % target] if target else []
cwd_def = ['-D$cwd="%s"' % os.getcwd().replace('\\', '/')]
for src in sources: for src in sources:
src_file = dir + '/' + src src_file = dir + '/' + src
part_file = target_dir + '/' + src[:-4] + part_type part = src[:-4] + part_type
all_parts.append(part)
part_file = target_dir + '/' + part
uses_file = deps_dir + '/' + src[:-4] + 'txt'
dname = deps_name(deps_dir, src) dname = deps_name(deps_dir, src)
changed = check_deps(part_file, dname) oldest = part_file if mtime(part_file) < mtime(uses_file) else uses_file
changed = check_deps(oldest, dname)
used = []
if changed: if changed:
print(changed) print(changed)
target_def = ['-D$target="%s"' % target] if target else [] t = time.time()
cwd_def = ['-D$cwd="%s"' % os.getcwd().replace('\\', '/')]
openscad.run_list(["-D$bom=1"] + target_def + cwd_def + ["-d", dname, "-o", part_file, src_file]) openscad.run_list(["-D$bom=1"] + target_def + cwd_def + ["-d", dname, "-o", part_file, src_file])
if part_type == 'stl': if part_type == 'stl':
c14n_stl.canonicalise(part_file) c14n_stl.canonicalise(part_file)
times.add_time(part, t)
log_name = 'openscad.log' log_name = 'openscad.log'
#
# Add the files on the BOM to the used list
#
with open(log_name) as file:
for line in file.readlines():
match = re.match(r'^ECHO: "~(.*?\.' + part_type + r').*"$', line)
if match:
used.append(match.group(1))
with open(uses_file, "wt") as file:
for part in used:
print(part, file = file)
else: else:
log_name = 'openscad.echo' with open(uses_file, "rt") as file:
openscad.run_silent("-D$bom=1", "-o", log_name, src_file) for line in file:
# used.append(line[:-1])
# Add the files on the BOM to the used list all_used += used
#
with open(log_name) as file:
for line in file.readlines():
match = re.match(r'^ECHO: "~(.*?\.' + part_type + r').*"$', line)
if match:
used.append(match.group(1))
copied = [] copied = []
if all_sources: if all_sources:
# #
# Copy files that are not included # Copy files that are not included
# #
for file in os.listdir(parts_dir): for file in os.listdir(parts_dir):
if file.endswith('.' + part_type) and not file in used: if file.endswith('.' + part_type) and not file in all_used:
src = parts_dir + '/' + file src = parts_dir + '/' + file
dst = target_dir + '/' + file dst = target_dir + '/' + file
if mtime(src) > mtime(dst): if mtime(src) > mtime(dst):
print("Copying %s to %s" % (src, dst)) print("Copying %s to %s" % (src, dst))
copyfile(src, dst) shutil.copyfile(src, dst)
copied.append(file) copied.append(file)
# #
# Remove any cruft # Remove any cruft
@@ -111,3 +132,12 @@ def plateup(target, part_type, usage = None):
if not file in targets and not file in copied: if not file in targets and not file in copied:
print("Removing %s" % file) print("Removing %s" % file)
os.remove(target_dir + '/' + file) os.remove(target_dir + '/' + file)
targets = [file[:-4] + 'txt' for file in all_sources]
for file in os.listdir(deps_dir):
if file.endswith('.' + 'txt'):
if not file in targets:
print("Removing %s" % file)
os.remove(deps_dir + '/' + file)
times.print_times(all_parts)

View File

@@ -30,6 +30,7 @@ from tests import do_cmd, update_image, colour_scheme, background
from deps import mtime from deps import mtime
from colorama import init from colorama import init
import json import json
from tmpdir import *
def usage(): def usage():
print("\nusage:\n\trender [target_config] - Render images of the stl and dxf files."); print("\nusage:\n\trender [target_config] - Render images of the stl and dxf files.");
@@ -40,6 +41,7 @@ def render(target, type):
# Make the target directory # Make the target directory
# #
top_dir = set_config(target, usage) top_dir = set_config(target, usage)
tmp_dir = mktmpdir(top_dir)
target_dir = top_dir + type + 's' target_dir = top_dir + type + 's'
bom_dir = top_dir + 'bom' bom_dir = top_dir + 'bom'
if not os.path.isdir(target_dir): if not os.path.isdir(target_dir):
@@ -80,7 +82,7 @@ def render(target, type):
# make a file to import the stl # make a file to import the stl
# #
if mtime(part_file) > mtime(png_name): if mtime(part_file) > mtime(png_name):
png_maker_name = "png.scad" png_maker_name = tmp_dir + "/png.scad"
pp1 = [0, 146/255, 0] pp1 = [0, 146/255, 0]
colour = pp1 colour = pp1
if part in colours: if part in colours:
@@ -88,15 +90,19 @@ def render(target, type):
if not '[' in colour: if not '[' in colour:
colour = '"' + colour + '"' colour = '"' + colour + '"'
with open(png_maker_name, "w") as f: with open(png_maker_name, "w") as f:
f.write('color(%s) import("%s");\n' % (colour, part_file)) f.write('color(%s) import("%s");\n' % (colour, reltmp(part_file, target)))
cam = "--camera=0,0,0,70,0,315,500" if type == 'stl' else "--camera=0,0,0,0,0,0,500" cam = "--camera=0,0,0,70,0,315,500" if type == 'stl' else "--camera=0,0,0,0,0,0,500"
render = "--preview" if type == 'stl' or colour != pp1 else "--render" render = "--preview" if type == 'stl' or colour != pp1 else "--render"
tmp_name = 'tmp.png' tmp_name = tmp_dir + '/' + part[:-4] + '.png'
openscad.run(colour_scheme, "--projection=p", "--imgsize=4096,4096", cam, render, "--autocenter", "--viewall", "-o", tmp_name, png_maker_name); openscad.run(colour_scheme, "--projection=p", "--imgsize=4096,4096", cam, render, "--autocenter", "--viewall", "-o", tmp_name, png_maker_name);
do_cmd(("magick "+ tmp_name + " -trim -resize 280x280 -background %s -gravity Center -extent 280x280 -bordercolor %s -border 10 %s" do_cmd(("magick "+ tmp_name + " -trim -resize 280x280 -background %s -gravity Center -extent 280x280 -bordercolor %s -border 10 %s"
% (background, background, tmp_name)).split()) % (background, background, tmp_name)).split())
update_image(tmp_name, png_name) update_image(tmp_name, png_name)
os.remove(png_maker_name) os.remove(png_maker_name)
#
# Remove tmp dir
#
rmtmpdir(tmp_dir)
if __name__ == '__main__': if __name__ == '__main__':
init() init()

View File

@@ -69,17 +69,22 @@ def set_config(target, usage = None):
sys.exit(1) sys.exit(1)
fname = source_dir + "/target.scad" fname = source_dir + "/target.scad"
text = "include <config_%s.scad>\n" % target; text = ['include <config_%s.scad>\n' % target,
line = "" '$target = "%s";\n' % target,
'$cwd="%s";\n' % os.getcwd().replace('\\', '/')
]
lines = [""]
try: try:
with open(fname,"rt") as f: with open(fname,"rt") as f:
line = f.read() lines = f.readlines()
except: except:
pass pass
if line != text: if lines != text:
with open(fname,"wt") as f: with open(fname,"wt") as f:
f. write(text); for t in text:
f. write(t);
return target + "/" return target + "/"
def usage(): def usage():

View File

@@ -34,6 +34,7 @@ import shutil
from deps import * from deps import *
from blurb import * from blurb import *
from colorama import Fore from colorama import Fore
from tmpdir import *
w = 4096 w = 4096
h = w h = w
@@ -94,6 +95,7 @@ def usage():
def tests(tests): def tests(tests):
scad_dir = "tests" scad_dir = "tests"
tmp_dir = mktmpdir(scad_dir + '/')
deps_dir = scad_dir + "/deps" deps_dir = scad_dir + "/deps"
png_dir = scad_dir + "/png" png_dir = scad_dir + "/png"
bom_dir = scad_dir + "/bom" bom_dir = scad_dir + "/bom"
@@ -234,7 +236,7 @@ def tests(tests):
if changed: if changed:
print(changed) print(changed)
t = time.time() t = time.time()
tmp_name = 'tmp.png' tmp_name = tmp_dir + '/tmp.png'
openscad.run_list(options.list() + ["-D$bom=2", colour_scheme, "--projection=p", "--imgsize=%d,%d" % (w, h), "--camera=0,0,0,70,0,315,500", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, scad_name]); openscad.run_list(options.list() + ["-D$bom=2", colour_scheme, "--projection=p", "--imgsize=%d,%d" % (w, h), "--camera=0,0,0,70,0,315,500", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, scad_name]);
times.add_time(scad_name, t) times.add_time(scad_name, t)
do_cmd(["magick", tmp_name, "-trim", "-resize", "1000x600", "-bordercolor", background, "-border", "10", tmp_name]) do_cmd(["magick", tmp_name, "-trim", "-resize", "1000x600", "-bordercolor", background, "-border", "10", tmp_name])
@@ -303,6 +305,11 @@ def tests(tests):
with open(doc_base_name + ".html", "wt") as html_file: with open(doc_base_name + ".html", "wt") as html_file:
do_cmd(("python -m markdown -x tables " + doc_name).split(), html_file) do_cmd(("python -m markdown -x tables " + doc_name).split(), html_file)
times.print_times() times.print_times()
#
# Remove tmp dir
#
rmtmpdir(tmp_dir)
do_cmd(('codespell -L od ' + doc_name).split()) do_cmd(('codespell -L od ' + doc_name).split())
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -44,7 +44,7 @@ def got_time(name):
def check_have_time(changed, name): def check_have_time(changed, name):
if not changed and not got_time(name): if not changed and not got_time(name):
changed = "no previous time" changed = Fore.CYAN + "no previous time" + Fore.WHITE
return changed return changed
def add_time(name, start): def add_time(name, start):

40
scripts/tmpdir.py Normal file
View File

@@ -0,0 +1,40 @@
#
# NopSCADlib Copyright Chris Palmer 2021
# nop.head@gmail.com
# hydraraptor.blogspot.com
#
# This file is part of NopSCADlib.
#
# NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with NopSCADlib.
# If not, see <https://www.gnu.org/licenses/>.
#
"""
Make a directory for tmp files.
"""
import os
import time
def mktmpdir(top_dir):
tmp_dir = top_dir + 'tmp'
if not os.path.isdir(tmp_dir):
os.makedirs(tmp_dir)
else:
for file in os.listdir(tmp_dir):
os.remove(tmp_dir + '/' + file)
return tmp_dir
def reltmp(dir, target):
return dir if os.path.isabs(dir) else '../../' + dir if target else '../' + dir
def rmtmpdir(tmp_dir):
os.rmdir(tmp_dir)
while os.path.isdir(tmp_dir):
time.sleep(0.1)

View File

@@ -38,6 +38,7 @@ import shutil
import re import re
import copy import copy
from colorama import Fore from colorama import Fore
from tmpdir import *
def is_assembly(s): def is_assembly(s):
return s[-9:] == '_assembly' or s[-11:] == '_assemblies' return s[-9:] == '_assembly' or s[-11:] == '_assemblies'
@@ -129,8 +130,9 @@ def views(target, do_assemblies = None):
# Make the target directory # Make the target directory
# #
top_dir = set_config(target, usage) top_dir = set_config(target, usage)
tmp_dir = mktmpdir(top_dir)
target_dir = top_dir + 'assemblies' target_dir = top_dir + 'assemblies'
deps_dir = top_dir + "deps" deps_dir = target_dir + "/deps"
bom_dir = top_dir + "bom" bom_dir = top_dir + "bom"
if not os.path.isdir(target_dir): if not os.path.isdir(target_dir):
os.makedirs(target_dir) os.makedirs(target_dir)
@@ -204,15 +206,15 @@ def views(target, do_assemblies = None):
changed = check_deps(png_name, dname) changed = check_deps(png_name, dname)
changed = times.check_have_time(changed, png_name) changed = times.check_have_time(changed, png_name)
changed = options.have_changed(changed, png_name) changed = options.have_changed(changed, png_name)
tmp_name = 'tmp.png' tmp_name = tmp_dir + '/' + real_name + '.png'
if changed: if changed:
print(changed) print(changed)
# #
# make a file to use the module # make a file to use the module
# #
png_maker_name = 'png.scad' png_maker_name = tmp_dir + '/png.scad'
with open(png_maker_name, "w") as f: with open(png_maker_name, "w") as f:
f.write("use <%s/%s>\n" % (dir, filename)) f.write("use <%s/%s>\n" % (reltmp(dir, target), filename))
f.write("%s();\n" % module); f.write("%s();\n" % module);
t = time.time() t = time.time()
target_def = ['-D$target="%s"' % target] if target else [] target_def = ['-D$target="%s"' % target] if target else []
@@ -439,6 +441,10 @@ def views(target, do_assemblies = None):
dst.write(line) dst.write(line)
i += 1 i += 1
# #
# Remove tmp dir
#
rmtmpdir(tmp_dir)
#
# Spell check # Spell check
# #
do_cmd(('codespell -L od ' + top_dir + 'readme.md').split()) do_cmd(('codespell -L od ' + top_dir + 'readme.md').split())

View File

@@ -146,17 +146,11 @@ module dxf(name) { //! Name a dxf that will appear on the B
} }
} }
module use_stl(name) { //! Import an STL to make a build platter module use_stl(name) //! Import an STL to make a build platter
stl(name); assert(false); // Here for documentation only, real version in core.scad
path = is_undef($target) ? "/stls/" : str("/", $target, "/stls/");
import(str($cwd, path, name, ".stl"));
}
module use_dxf(name) { //! Import a DXF to make a build panel module use_dxf(name) //! Import a DXF to make a build panel
dxf(name); assert(false); // Here for documentation only, real version in core.scad
path = is_undef($target) ? "/dxfs/" : str("/", $target, "/dxfs/");
import(str($cwd, path, name, ".dxf"));
}
function value_string(value) = is_string(value) ? str("\"", value, "\"") : str(value); //! Convert `value` to a string or quote it if it is already a string function value_string(value) = is_string(value) ? str("\"", value, "\"") : str(value); //! Convert `value` to a string or quote it if it is already a string

View File

@@ -25,3 +25,15 @@ include <../../global_defs.scad>
// Global functions and modules // Global functions and modules
// //
use <global.scad> use <global.scad>
module use_stl(name) { //! Import an STL to make a build platter
stl(name);
path = is_undef($target) ? "../stls/" : str($cwd, "/", $target, "/stls/");
import(str(path, name, ".stl"));
}
module use_dxf(name) { //! Import a DXF to make a build panel
dxf(name);
path = is_undef($target) ? "../dxfs/" : str($cwd, "/", $target, "/dxfs/");
import(str(path, name, ".dxf"));
}