1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-06 23:46:30 +02:00

Add the ability to have a target specific top level module in place of main_assembly().

This commit is contained in:
Chris Palmer
2021-06-03 11:58:10 +01:00
parent 3027b942a6
commit 823f3b936e
3 changed files with 33 additions and 37 deletions

View File

@@ -46,6 +46,18 @@ def find_scad_file(mname):
return filename
return None
def main_assembly(target):
file = None
if target:
assembly = target + "_assembly"
file = find_scad_file(assembly)
if not file:
assembly = "main_assembly"
file = find_scad_file(assembly)
if not file:
raise Exception("can't find source for " + assembly)
return assembly, file
class Part:
def __init__(self, args):
self.count = 1
@@ -221,28 +233,20 @@ def parse_bom(file = "openscad.log", name = None):
return main
def usage():
print("\nusage:\n\tbom [target_config] [<accessory_name>_assembly] - Generate BOMs for a project or an accessory to a project.")
print("\nusage:\n\tbom [target_config] - Generate BOMs for a project.")
sys.exit(1)
def boms(target = None, assembly = None):
def boms(target = None):
try:
bom_dir = set_config(target, usage) + "bom"
if assembly:
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)
if os.path.isdir(bom_dir):
shutil.rmtree(bom_dir)
sleep(0.1)
os.makedirs(bom_dir)
#
# Find the scad file that makes the module
# Find the scad file that makes the main assembly
#
scad_file = find_scad_file(assembly)
if not scad_file:
raise Exception("can't find source for " + assembly)
assembly, scad_file = main_assembly(target)
#
# make a file to use the module
#
@@ -259,8 +263,7 @@ def boms(target = None, assembly = None):
main = parse_bom("openscad.echo", 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:
with open(bom_dir + "/" + ass + ".txt", "wt") as f:
@@ -278,20 +281,8 @@ def boms(target = None, assembly = None):
sys.exit(1)
if __name__ == '__main__':
if len(sys.argv) > 3: usage()
if len(sys.argv) > 2: usage()
if len(sys.argv) == 3:
target, assembly = sys.argv[1], sys.argv[2]
else:
if len(sys.argv) == 2:
if sys.argv[1][-9:] == "_assembly":
target, assembly = None, sys.argv[1]
else:
target, assembly = sys.argv[1], None
else:
target, assembly = None, None
target = sys.argv[1] if len(sys.argv) == 2 else None
if assembly:
if assembly[-9:] != "_assembly": usage()
boms(target, assembly)
boms(target)

View File

@@ -161,6 +161,7 @@ def views(target, do_assemblies = None):
# Find all the scad files
#
main_blurb = None
main_assembly, main_file = bom.main_assembly(target)
pngs = []
for dir in source_dirs(bom_dir):
if os.path.isdir(dir):
@@ -232,7 +233,7 @@ def views(target, do_assemblies = None):
update_image(tmp_name, tn_name)
done_assemblies.append(real_name)
else:
if module == 'main_assembly':
if module == main_assembly:
main_blurb = blurb.scrape_module_blurb(lines[:line_no])
line_no += 1
#
@@ -246,9 +247,6 @@ def views(target, do_assemblies = None):
project = ' '.join(word[0].upper() + word[1:] for word in os.path.basename(os.getcwd()).split('_'))
print('<a name="TOP"></a>', file = doc_file)
print('# %s' % project, file = doc_file)
main_file = bom.find_scad_file('main_assembly')
if not main_file:
raise Exception("can't find source for main_assembly")
text = blurb.scrape_blurb(source_dir + '/' + main_file)
blurbs = blurb.split_blurb(text)
if len(text):