From 2210396234dc9342dbb6c874a4bba4d6f4ba291c Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Thu, 12 Mar 2020 22:47:27 +0000 Subject: [PATCH] Now uses the dependencies to locate modules for printed parts and assemblies. --- docs/usage.md | 7 +++++++ scripts/bom.py | 2 +- scripts/deps.py | 14 ++++++++++++++ scripts/exports.py | 19 ++++++++----------- scripts/render.py | 6 ++++-- scripts/views.py | 3 +-- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index ca61d69..cad6273 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -243,3 +243,10 @@ Some parametric designs might have several configurations, for example a 3D prin The target config file is selected by generating ```target.scad``` that includes ```config_.scad```. The rest of the project includes ```target.scad``` to use the configuration. Additionally all the generated file directories (assemblies, bom, stls, dxfs, etc.) are placed in a sub-directory called ``````. + +### Other libraries + +The build scripts need to be able to locate the source files where the modules to generate the STL files and assemblies reside. They will search all the scad files +in the project plus any ```printed``` directories outside the project. This covers the printed parts in NopSCADlib but also allows other libraries of printed parts. + +Other libraries of vitamins and utilities can be used provided they follow the same convensions of NopSCADlib. The build scripts don't need to search those. diff --git a/scripts/bom.py b/scripts/bom.py index 6e10e66..8f3f2cf 100755 --- a/scripts/bom.py +++ b/scripts/bom.py @@ -221,7 +221,7 @@ def boms(target = None, assembly = None): # # Run openscad # - openscad.run("-D","$bom=2","-D","$preview=true","-o", "openscad.echo", bom_maker_name) + openscad.run("-D","$bom=2","-D","$preview=true","-o", "openscad.echo", "-d", bom_dir + "/bom.deps", bom_maker_name) os.remove(bom_maker_name) print("Generating bom ...", end=" ") diff --git a/scripts/deps.py b/scripts/deps.py index 599d665..1433b0b 100644 --- a/scripts/deps.py +++ b/scripts/deps.py @@ -48,3 +48,17 @@ def check_deps(target, dname): if mtime(dep) > target_mtime: return dep + ' changed' return None + +def source_dirs(bom_dir): + dirs = set() + lib_dirs = set() + deps = read_deps(bom_dir + '/bom.deps') + cwd = os.getcwd().replace('\\', '/') + for dep in deps: + dir = os.path.dirname(dep) + if dir.startswith(cwd): + dirs.add(dir[len(cwd) + 1:]) + else: + if dir.endswith('/printed'): + lib_dirs.add(dir) + return sorted(dirs) + sorted(lib_dirs) diff --git a/scripts/exports.py b/scripts/exports.py index dab9219..7b76574 100644 --- a/scripts/exports.py +++ b/scripts/exports.py @@ -30,14 +30,14 @@ import times from deps import * import json -def bom_to_parts(target_dir, part_type, assembly = None): +def bom_to_parts(bom_dir, part_type, assembly = None): # # Make a list of all the parts in the BOM # part_files = [] bom = assembly + '.txt' if assembly else "bom.txt" suffix = ".dxf" if part_type == 'svg' else '.' + part_type - with open(target_dir + "/../bom/" + bom, "rt") as f: + with open(bom_dir + '/' + bom, "rt") as f: for line in f.readlines(): words = line.split() if words: @@ -63,6 +63,7 @@ def make_parts(target, part_type, parts = None): top_dir = set_config(target, lambda: usage(part_type)) target_dir = top_dir + part_type + 's' deps_dir = top_dir + "deps" + bom_dir = top_dir + "bom" if not os.path.isdir(target_dir): os.makedirs(target_dir) if not os.path.isdir(deps_dir): @@ -74,7 +75,7 @@ def make_parts(target, part_type, parts = None): if parts: targets = list(parts) #copy the list so we dont modify the list passed in else: - targets = bom_to_parts(target_dir, part_type) + targets = bom_to_parts(bom_dir, part_type) for file in os.listdir(target_dir): if file.endswith('.' + part_type): if not file in targets: @@ -93,12 +94,11 @@ def make_parts(target, part_type, parts = None): # # Find all the scad files # - lib_dirs = [path + '/' + lib + '/printed' for path in os.environ['OPENSCADPATH'].split(os.pathsep) for lib in sorted(os.listdir(path))] module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type - for dir in [source_dir, source_dir + '/printed'] + lib_dirs: - if os.path.isdir(dir): + for dir in source_dirs(bom_dir): + if targets and os.path.isdir(dir): for filename in os.listdir(dir): - if filename[-5:] == ".scad": + if targets and filename[-5:] == ".scad": # # find any modules ending in _ # @@ -148,9 +148,6 @@ def make_parts(target, part_type, parts = None): # if targets: for part in targets: - if part[-4:] != '.' + part_type: - print(part, "is not a", part_type, "file") - else: - print("Could not find a module called", part[:-4] + module_suffix, "to make", part) + print("Could not find a module called", part[:-4] + module_suffix, "to make", part) usage(part_type) times.print_times() diff --git a/scripts/render.py b/scripts/render.py index d160eb3..266b8e2 100755 --- a/scripts/render.py +++ b/scripts/render.py @@ -38,13 +38,15 @@ def render(target, type): # # Make the target directory # - target_dir = set_config(target, usage) + type + 's' + top_dir = set_config(target, usage) + target_dir = top_dir + type + 's' + bom_dir = top_dir + 'bom' if not os.path.isdir(target_dir): os.makedirs(target_dir) # # Find all the parts # - parts = bom_to_parts(target_dir, type) + parts = bom_to_parts(bom_dir, type) # # Remove unused png files # diff --git a/scripts/views.py b/scripts/views.py index b376933..1a127fc 100755 --- a/scripts/views.py +++ b/scripts/views.py @@ -137,8 +137,7 @@ def views(target, do_assemblies = None): # Find all the scad files # main_blurb = None - lib_dirs = [path + '/' + lib + '/printed' for path in os.environ['OPENSCADPATH'].split(os.pathsep) for lib in sorted(os.listdir(path))] - for dir in [source_dir, source_dir + '/printed'] + lib_dirs: + for dir in source_dirs(bom_dir): if os.path.isdir(dir): for filename in os.listdir(dir): if filename.endswith('.scad'):