make_all.py now terminates early if there are any errors in bom generation.

This commit is contained in:
Chris Palmer 2020-04-29 15:19:10 +01:00
parent cedaafed3d
commit 828e5ad36e

View File

@ -213,7 +213,7 @@ def parse_bom(file = "openscad.log", name = None):
main.assemblies[stack[-1]].add_part(s) main.assemblies[stack[-1]].add_part(s)
else: else:
if 'ERROR:' in line or 'WARNING:' in line: if 'ERROR:' in line or 'WARNING:' in line:
print(line[:-1]) raise Exception(line[:-1])
return main return main
def usage(): def usage():
@ -221,53 +221,57 @@ def usage():
sys.exit(1) sys.exit(1)
def boms(target = None, assembly = None): def boms(target = None, assembly = None):
bom_dir = set_config(target, usage) + "bom" try:
if assembly: bom_dir = set_config(target, usage) + "bom"
bom_dir += "/accessories" if assembly:
if not os.path.isdir(bom_dir): bom_dir += "/accessories"
if not os.path.isdir(bom_dir):
os.makedirs(bom_dir)
else:
assembly = "main_assembly"
if os.path.isdir(bom_dir):
shutil.rmtree(bom_dir)
sleep(0.1)
os.makedirs(bom_dir) os.makedirs(bom_dir)
else: #
assembly = "main_assembly" # Find the scad file that makes the module
if os.path.isdir(bom_dir): #
shutil.rmtree(bom_dir) scad_file = find_scad_file(assembly)
sleep(0.1) if not scad_file:
os.makedirs(bom_dir) raise Exception("can't find source for " + assembly)
# #
# Find the scad file that makes the module # make a file to use the module
# #
scad_file = find_scad_file(assembly) bom_maker_name = source_dir + "/bom.scad"
if not scad_file: with open(bom_maker_name, "w") as f:
raise Exception("can't find source for " + assembly) f.write("use <%s>\n" % scad_file)
# f.write("%s();\n" % assembly);
# make a file to use the module #
# # Run openscad
bom_maker_name = source_dir + "/bom.scad" #
with open(bom_maker_name, "w") as f: openscad.run("-D", "$bom=2", "-D", "$preview=true", "--hardwarnings", "-o", "openscad.echo", "-d", bom_dir + "/bom.deps", bom_maker_name)
f.write("use <%s>\n" % scad_file) os.remove(bom_maker_name)
f.write("%s();\n" % assembly); print("Generating bom ...", end=" ")
#
# Run openscad
#
openscad.run("-D", "$bom=2", "-D", "$preview=true", "--hardwarnings", "-o", "openscad.echo", "-d", bom_dir + "/bom.deps", bom_maker_name)
os.remove(bom_maker_name)
print("Generating bom ...", end=" ")
main = parse_bom("openscad.echo", assembly) main = parse_bom("openscad.echo", assembly)
if assembly == "main_assembly": if assembly == "main_assembly":
main.print_bom(True, open(bom_dir + "/bom.txt","wt")) main.print_bom(True, open(bom_dir + "/bom.txt","wt"))
for ass in main.assemblies: for ass in main.assemblies:
with open(bom_dir + "/" + ass + ".txt", "wt") as f: with open(bom_dir + "/" + ass + ".txt", "wt") as f:
bom = main.assemblies[ass] bom = main.assemblies[ass]
print(bom.make_name(ass) + ":", file=f) print(bom.make_name(ass) + ":", file=f)
bom.print_bom(False, f) bom.print_bom(False, f)
data = [main.assemblies[ass].flat_data() for ass in main.ordered_assemblies] data = [main.assemblies[ass].flat_data() for ass in main.ordered_assemblies]
with open(bom_dir + "/bom.json", 'w') as outfile: with open(bom_dir + "/bom.json", 'w') as outfile:
json.dump(data, outfile, indent = 4) json.dump(data, outfile, indent = 4)
print("done") print("done")
except Exception as e:
print(str(e))
sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) > 3: usage() if len(sys.argv) > 3: usage()
@ -286,8 +290,4 @@ if __name__ == '__main__':
if assembly: if assembly:
if assembly[-9:] != "_assembly": usage() if assembly[-9:] != "_assembly": usage()
try: boms(target, assembly)
boms(target, assembly)
except Exception as e:
print(str(e))
sys.exit(1)