mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-15 03:43:57 +02:00
Added screw threads to most things that are threaded.
Added a mechanism for tests.py and views.py to have command line options.
This commit is contained in:
@@ -24,7 +24,7 @@ from __future__ import print_function
|
||||
|
||||
import subprocess, sys
|
||||
|
||||
def _run(args, silent):
|
||||
def run_list(args, silent = False):
|
||||
cmd = ["openscad"] + args
|
||||
if not silent:
|
||||
for arg in cmd:
|
||||
@@ -39,7 +39,7 @@ def _run(args, silent):
|
||||
sys.exit(rc)
|
||||
|
||||
def run(*args):
|
||||
_run(list(args), False)
|
||||
run_list(list(args), False)
|
||||
|
||||
def run_silent(*args):
|
||||
_run(list(args), True);
|
||||
run_list(list(args), True);
|
||||
|
49
scripts/options.py
Normal file
49
scripts/options.py
Normal file
@@ -0,0 +1,49 @@
|
||||
#
|
||||
# NopSCADlib Copyright Chris Palmer 2020
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
# Set command line options from enviroment variables and check if they have changed
|
||||
|
||||
import json, os, deps
|
||||
|
||||
def check_options(dir = '.'):
|
||||
global options, options_mtime
|
||||
options = { "show_threads": str(os.getenv("SHOW_THREADS")) }
|
||||
options_fname = dir + '/options.json'
|
||||
try:
|
||||
with open(options_fname) as json_file:
|
||||
last_options = json.load(json_file)
|
||||
except:
|
||||
last_options = {}
|
||||
if last_options != options:
|
||||
with open(options_fname, 'w') as outfile:
|
||||
json.dump(options, outfile, indent = 4)
|
||||
options_mtime = deps.mtime(options_fname)
|
||||
|
||||
def have_changed(changed, target):
|
||||
if not changed and deps.mtime(target) < options_mtime:
|
||||
return "command line options changed"
|
||||
return changed
|
||||
|
||||
def list():
|
||||
result = []
|
||||
for name in options.keys():
|
||||
value = options[name]
|
||||
if value != 'None':
|
||||
result.append('-D$' + name + '=' + value)
|
||||
return result
|
@@ -27,6 +27,7 @@ import openscad
|
||||
import subprocess
|
||||
import bom
|
||||
import times
|
||||
import options
|
||||
import time
|
||||
import json
|
||||
import shutil
|
||||
@@ -96,6 +97,7 @@ def tests(tests):
|
||||
index = {}
|
||||
bodies = {}
|
||||
times.read_times()
|
||||
options.check_options(deps_dir)
|
||||
#
|
||||
# Make cover pic if does not exist as very slow. Delete it to force an update.
|
||||
#
|
||||
@@ -190,11 +192,12 @@ def tests(tests):
|
||||
oldest = png_name if mtime(png_name) < mtime(bom_name) else bom_name
|
||||
changed = check_deps(oldest, dname)
|
||||
changed = times.check_have_time(changed, scad_name)
|
||||
changed = options.have_changed(changed, oldest)
|
||||
if changed:
|
||||
print(changed)
|
||||
t = time.time()
|
||||
tmp_name = 'tmp.png'
|
||||
openscad.run("-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)
|
||||
do_cmd(["magick", tmp_name, "-trim", "-resize", "1000x600", "-bordercolor", background, "-border", "10", tmp_name])
|
||||
update_image(tmp_name, png_name)
|
||||
|
@@ -28,6 +28,7 @@ import openscad
|
||||
from tests import do_cmd, update_image, colour_scheme, background
|
||||
import time
|
||||
import times
|
||||
import options
|
||||
from deps import *
|
||||
import os
|
||||
import json
|
||||
@@ -102,6 +103,7 @@ def views(target, do_assemblies = None):
|
||||
os.makedirs(deps_dir)
|
||||
|
||||
times.read_times(target_dir)
|
||||
options.check_options(deps_dir)
|
||||
bounds_fname = top_dir + 'stls/bounds.json'
|
||||
with open(bounds_fname) as json_file:
|
||||
bounds_map = json.load(json_file)
|
||||
@@ -163,11 +165,12 @@ def views(target, do_assemblies = None):
|
||||
png_name = png_name.replace('_assembly', '_assembled')
|
||||
changed = check_deps(png_name, dname)
|
||||
changed = times.check_have_time(changed, png_name)
|
||||
changed = options.have_changed(changed, png_name)
|
||||
tmp_name = 'tmp.png'
|
||||
if changed:
|
||||
print(changed)
|
||||
t = time.time()
|
||||
openscad.run("-D$show_threads=1", "-D$pose=1", "-D$explode=%d" % explode, colour_scheme, "--projection=p", "--imgsize=4096,4096", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, png_maker_name);
|
||||
openscad.run_list(options.list() + ["-D$pose=1", "-D$explode=%d" % explode, colour_scheme, "--projection=p", "--imgsize=4096,4096", "--autocenter", "--viewall", "-d", dname, "-o", tmp_name, png_maker_name]);
|
||||
times.add_time(png_name, t)
|
||||
do_cmd(["magick", tmp_name, "-trim", "-resize", "1004x1004", "-bordercolor", background, "-border", "10", tmp_name])
|
||||
update_image(tmp_name, png_name)
|
||||
|
Reference in New Issue
Block a user