diff --git a/scripts/plateup.py b/scripts/plateup.py index c5fe952..7c4c137 100644 --- a/scripts/plateup.py +++ b/scripts/plateup.py @@ -28,13 +28,13 @@ from set_config import * from deps import * import shutil import re -from colorama import init +import time +import times source_dirs = { "stl" : "platters", "dxf" : "panels" } target_dirs = { "stl" : "printed", "dxf" : "routed" } def plateup(target, part_type, usage = None): - init() # # Make the target directory # @@ -43,11 +43,14 @@ def plateup(target, part_type, usage = None): target_dir = parts_dir + '/' + target_dirs[part_type] source_dir1 = source_dirs[part_type] source_dir2 = top_dir + source_dirs[part_type] + + times.read_times(target_dir) # # Loop through source directories # - used = [] + all_used = [] all_sources = [] + all_parts = [] for dir in [source_dir1, source_dir2]: if not os.path.isdir(dir): continue @@ -74,33 +77,46 @@ def plateup(target, part_type, usage = None): cwd_def = ['-D$cwd="%s"' % os.getcwd().replace('\\', '/')] for src in sources: 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) - 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: print(changed) + t = time.time() openscad.run_list(["-D$bom=1"] + target_def + cwd_def + ["-d", dname, "-o", part_file, src_file]) if part_type == 'stl': c14n_stl.canonicalise(part_file) + times.add_time(part, t) 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: - log_name = 'openscad.echo' - openscad.run_list(["-D$bom=1"] + target_def + cwd_def + ["-o", log_name, src_file], silent = True) - # - # 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, "rt") as file: + for line in file: + used.append(line[:-1]) + all_used += used + copied = [] if all_sources: # # Copy files that are not included # 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 dst = target_dir + '/' + file if mtime(src) > mtime(dst): @@ -116,3 +132,12 @@ def plateup(target, part_type, usage = None): if not file in targets and not file in copied: print("Removing %s" % 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)