mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-06 04:09:47 +00:00
Improved docs_gen.py for Function&Module and better error handling.
This commit is contained in:
parent
11e5406951
commit
11c6522358
2 changed files with 39 additions and 27 deletions
|
@ -123,13 +123,11 @@ class ImageProcessing(object):
|
||||||
elif "Big" in extype:
|
elif "Big" in extype:
|
||||||
imgsizes = ["1280,960", "640x480"]
|
imgsizes = ["1280,960", "640x480"]
|
||||||
elif "distribute" in script or "show_anchors" in script:
|
elif "distribute" in script or "show_anchors" in script:
|
||||||
print(script)
|
|
||||||
imgsizes = ["800,600", "400x300"]
|
imgsizes = ["800,600", "400x300"]
|
||||||
else: # Small
|
else: # Small
|
||||||
imgsizes = ["480,360", "240x180"]
|
imgsizes = ["480,360", "240x180"]
|
||||||
|
|
||||||
print("")
|
print(" {}".format(imgfile))
|
||||||
print("{}: {}".format(libfile, imgfile))
|
|
||||||
|
|
||||||
tmpimgs = []
|
tmpimgs = []
|
||||||
if "Spin" in extype:
|
if "Spin" in extype:
|
||||||
|
@ -155,11 +153,18 @@ class ImageProcessing(object):
|
||||||
if "FR" in extype: # Force render
|
if "FR" in extype: # Force render
|
||||||
scadcmd.extend(["--render", ""])
|
scadcmd.extend(["--render", ""])
|
||||||
scadcmd.append(scriptfile)
|
scadcmd.append(scriptfile)
|
||||||
print(" ".join(scadcmd))
|
p = subprocess.Popen(scadcmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
||||||
res = subprocess.call(scadcmd)
|
(stdoutdata, stderrdata) = p.communicate(None)
|
||||||
if res != 0:
|
res = p.returncode
|
||||||
|
if res != 0 or "ERROR:" in stderrdata or "WARNING:" in stderrdata:
|
||||||
|
print("%s"%stderrdata)
|
||||||
|
print("////////////////////////////////////////////////////")
|
||||||
|
print("// {}: {} for {}".format(libfile, scriptfile, imgfile))
|
||||||
|
print("////////////////////////////////////////////////////")
|
||||||
print(script)
|
print(script)
|
||||||
sys.exit(res)
|
print("////////////////////////////////////////////////////")
|
||||||
|
print("")
|
||||||
|
sys.exit(-1)
|
||||||
tmpimgs.append(tmpimgfile)
|
tmpimgs.append(tmpimgfile)
|
||||||
else:
|
else:
|
||||||
tmpimgfile = self.imgroot + "tmp_" + imgfile
|
tmpimgfile = self.imgroot + "tmp_" + imgfile
|
||||||
|
@ -179,11 +184,18 @@ class ImageProcessing(object):
|
||||||
scadcmd.extend(["--render", ""])
|
scadcmd.extend(["--render", ""])
|
||||||
scadcmd.append(scriptfile)
|
scadcmd.append(scriptfile)
|
||||||
|
|
||||||
print(" ".join(scadcmd))
|
p = subprocess.Popen(scadcmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
||||||
res = subprocess.call(scadcmd)
|
(stdoutdata, stderrdata) = p.communicate(None)
|
||||||
if res != 0:
|
res = p.returncode
|
||||||
|
if res != 0 or "ERROR:" in stderrdata or "WARNING:" in stderrdata:
|
||||||
|
print("%s"%stderrdata)
|
||||||
|
print("////////////////////////////////////////////////////")
|
||||||
|
print("// {}: {} for {}".format(libfile, scriptfile, imgfile))
|
||||||
|
print("////////////////////////////////////////////////////")
|
||||||
print(script)
|
print(script)
|
||||||
sys.exit(res)
|
print("////////////////////////////////////////////////////")
|
||||||
|
print("")
|
||||||
|
sys.exit(-1)
|
||||||
tmpimgs.append(tmpimgfile)
|
tmpimgs.append(tmpimgfile)
|
||||||
|
|
||||||
if not self.keep_scripts:
|
if not self.keep_scripts:
|
||||||
|
@ -192,10 +204,9 @@ class ImageProcessing(object):
|
||||||
newimgfile = self.imgroot + "_new_" + imgfile
|
newimgfile = self.imgroot + "_new_" + imgfile
|
||||||
if len(tmpimgs) == 1:
|
if len(tmpimgs) == 1:
|
||||||
cnvcmd = [CONVERT, tmpimgfile, "-resize", imgsizes[1], newimgfile]
|
cnvcmd = [CONVERT, tmpimgfile, "-resize", imgsizes[1], newimgfile]
|
||||||
print(" ".join(cnvcmd))
|
|
||||||
res = subprocess.call(cnvcmd)
|
res = subprocess.call(cnvcmd)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
sys.exit(res)
|
sys.exit(-1)
|
||||||
os.unlink(tmpimgs.pop(0))
|
os.unlink(tmpimgs.pop(0))
|
||||||
else:
|
else:
|
||||||
cnvcmd = [
|
cnvcmd = [
|
||||||
|
@ -211,33 +222,29 @@ class ImageProcessing(object):
|
||||||
]
|
]
|
||||||
cnvcmd.extend(tmpimgs)
|
cnvcmd.extend(tmpimgs)
|
||||||
cnvcmd.append(newimgfile)
|
cnvcmd.append(newimgfile)
|
||||||
print(" ".join(cnvcmd))
|
|
||||||
res = subprocess.call(cnvcmd)
|
res = subprocess.call(cnvcmd)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
sys.exit(res)
|
sys.exit(-1)
|
||||||
for tmpimg in tmpimgs:
|
for tmpimg in tmpimgs:
|
||||||
os.unlink(tmpimg)
|
os.unlink(tmpimg)
|
||||||
|
|
||||||
# Time to compare image.
|
# Time to compare image.
|
||||||
if not os.path.isfile(targimgfile):
|
if not os.path.isfile(targimgfile):
|
||||||
print("NEW IMAGE installed.")
|
print(" NEW IMAGE\n")
|
||||||
os.rename(newimgfile, targimgfile)
|
os.rename(newimgfile, targimgfile)
|
||||||
else:
|
else:
|
||||||
if targimgfile.endswith(".gif"):
|
if targimgfile.endswith(".gif"):
|
||||||
cmpcmd = ["cmp", newimgfile, targimgfile]
|
cmpcmd = ["cmp", newimgfile, targimgfile]
|
||||||
print(" ".join(cmpcmd))
|
|
||||||
res = subprocess.call(cmpcmd)
|
res = subprocess.call(cmpcmd)
|
||||||
issame = res == 0
|
issame = res == 0
|
||||||
else:
|
else:
|
||||||
cmpcmd = [COMPARE, "-metric", "MAE", newimgfile, targimgfile, "null:"]
|
cmpcmd = [COMPARE, "-metric", "MAE", newimgfile, targimgfile, "null:"]
|
||||||
print(" ".join(cmpcmd))
|
|
||||||
p = subprocess.Popen(cmpcmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
|
p = subprocess.Popen(cmpcmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
|
||||||
issame = p.stdout.read().strip() == "0 (0)"
|
issame = p.stdout.read().strip() == "0 (0)"
|
||||||
if issame:
|
if issame:
|
||||||
print("Image unchanged.")
|
|
||||||
os.unlink(newimgfile)
|
os.unlink(newimgfile)
|
||||||
else:
|
else:
|
||||||
print("Image UPDATED.")
|
print(" UPDATED IMAGE\n")
|
||||||
os.unlink(targimgfile)
|
os.unlink(targimgfile)
|
||||||
os.rename(newimgfile, targimgfile)
|
os.rename(newimgfile, targimgfile)
|
||||||
|
|
||||||
|
@ -263,6 +270,8 @@ class LeafNode(object):
|
||||||
return True
|
return True
|
||||||
if line.startswith(prefix + "Function: "):
|
if line.startswith(prefix + "Function: "):
|
||||||
return True
|
return True
|
||||||
|
if line.startswith(prefix + "Function&Module: "):
|
||||||
|
return True
|
||||||
if line.startswith(prefix + "Module: "):
|
if line.startswith(prefix + "Module: "):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -288,6 +297,10 @@ class LeafNode(object):
|
||||||
leaftype, title = line.split(":", 1)
|
leaftype, title = line.split(":", 1)
|
||||||
self.name = title.strip()
|
self.name = title.strip()
|
||||||
self.leaftype = leaftype.strip()
|
self.leaftype = leaftype.strip()
|
||||||
|
if line.startswith("Function&Module:"):
|
||||||
|
leaftype, title = line.split(":", 1)
|
||||||
|
self.name = title.strip()
|
||||||
|
self.leaftype = leaftype.strip()
|
||||||
if line.startswith("Function:"):
|
if line.startswith("Function:"):
|
||||||
leaftype, title = line.split(":", 1)
|
leaftype, title = line.split(":", 1)
|
||||||
self.name = title.strip()
|
self.name = title.strip()
|
||||||
|
@ -317,7 +330,7 @@ class LeafNode(object):
|
||||||
if "=" not in line:
|
if "=" not in line:
|
||||||
print("Error: bad argument line:")
|
print("Error: bad argument line:")
|
||||||
print(line)
|
print(line)
|
||||||
sys.exit(2)
|
sys.exit(-2)
|
||||||
argname, argdesc = line.split("=", 1)
|
argname, argdesc = line.split("=", 1)
|
||||||
argname = argname.strip()
|
argname = argname.strip()
|
||||||
argdesc = argdesc.strip()
|
argdesc = argdesc.strip()
|
||||||
|
@ -328,7 +341,7 @@ class LeafNode(object):
|
||||||
if "=" not in line:
|
if "=" not in line:
|
||||||
print("Error: bad anchor line:")
|
print("Error: bad anchor line:")
|
||||||
print(line)
|
print(line)
|
||||||
sys.exit(2)
|
sys.exit(-2)
|
||||||
anchorname, anchordesc = line.split("=", 1)
|
anchorname, anchordesc = line.split("=", 1)
|
||||||
anchorname = anchorname.strip()
|
anchorname = anchorname.strip()
|
||||||
anchordesc = anchordesc.strip()
|
anchordesc = anchordesc.strip()
|
||||||
|
@ -343,7 +356,7 @@ class LeafNode(object):
|
||||||
title = m.group(4)
|
title = m.group(4)
|
||||||
lines, block = get_comment_block(lines, prefix)
|
lines, block = get_comment_block(lines, prefix)
|
||||||
if not extype:
|
if not extype:
|
||||||
extype = "3D" if self.leaftype == "Module" else "NORENDER"
|
extype = "3D" if self.leaftype in ["Module", "Function&Module"] else "NORENDER"
|
||||||
if not plural:
|
if not plural:
|
||||||
self.add_example(title=title, code=block, extype=extype)
|
self.add_example(title=title, code=block, extype=extype)
|
||||||
else:
|
else:
|
||||||
|
@ -415,8 +428,7 @@ class LeafNode(object):
|
||||||
out.append(" " + line)
|
out.append(" " + line)
|
||||||
out.append("")
|
out.append("")
|
||||||
san_name = re.sub(r"[^A-Za-z0-9_]", "", self.name)
|
san_name = re.sub(r"[^A-Za-z0-9_]", "", self.name)
|
||||||
imgfile = "{}{}{}.{}".format(
|
imgfile = "{}{}.{}".format(
|
||||||
"f_" if self.leaftype == "Function" else "",
|
|
||||||
san_name,
|
san_name,
|
||||||
("_%d" % exnum) if exnum > 1 else "",
|
("_%d" % exnum) if exnum > 1 else "",
|
||||||
"gif" if "Spin" in extype else "png"
|
"gif" if "Spin" in extype else "png"
|
||||||
|
@ -480,7 +492,7 @@ class Section(object):
|
||||||
title = m.group(4)
|
title = m.group(4)
|
||||||
lines, block = get_comment_block(lines, prefix)
|
lines, block = get_comment_block(lines, prefix)
|
||||||
if not figtype:
|
if not figtype:
|
||||||
figtype = "3D" if self.figtype == "Module" else "NORENDER"
|
figtype = "3D" if self.figtype in ["Module", "Function&Module"] else "NORENDER"
|
||||||
if not plural:
|
if not plural:
|
||||||
self.add_figure(title, block, figtype)
|
self.add_figure(title, block, figtype)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
if [[ $# > 0 ]]; then
|
if [[ $# > 0 ]]; then
|
||||||
PREVIEW_LIBS="$@"
|
PREVIEW_LIBS="$@"
|
||||||
else
|
else
|
||||||
PREVIEW_LIBS="compat attachments math arrays vectors matrices coords geometry triangulation quaternions hull constants transforms primitives shapes masks shapes2d paths beziers walls metric_screws threading involute_gears sliders joiners linear_bearings nema_steppers wiring phillips_drive torx_drive polyhedra debug"
|
PREVIEW_LIBS="compat attachments math arrays vectors matrices coords geometry triangulation quaternions hull constants edges transforms primitives shapes masks shapes2d paths beziers walls metric_screws threading involute_gears sliders joiners linear_bearings nema_steppers wiring phillips_drive torx_drive polyhedra debug"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dir="$(basename $PWD)"
|
dir="$(basename $PWD)"
|
||||||
|
|
Loading…
Reference in a new issue