plateup.py now saves the used files to speed up processing when a part hasn't changed.

Added times to plateup.py.
This commit is contained in:
Chris Palmer 2021-02-11 09:10:15 +00:00
parent da825b17ab
commit 0a84bf0927
1 changed files with 41 additions and 16 deletions

View File

@ -28,13 +28,13 @@ from set_config import *
from deps import * from deps import *
import shutil import shutil
import re import re
from colorama import init 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" }
def plateup(target, part_type, usage = None): def plateup(target, part_type, usage = None):
init()
# #
# Make the target directory # Make the target directory
# #
@ -43,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
@ -74,33 +77,46 @@ def plateup(target, part_type, usage = None):
cwd_def = ['-D$cwd="%s"' % os.getcwd().replace('\\', '/')] 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)
t = time.time()
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_list(["-D$bom=1"] + target_def + cwd_def + ["-o", log_name, src_file], silent = True) 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):
@ -116,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)