From 442b1a5db5c4ab0e9bbdf9014ea687370935ed63 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 22 Feb 2021 14:07:33 +0100 Subject: [PATCH] Tools: Updated offline doc scripts --- src/Tools/offlinedoc/buildpdf.py | 293 +++---------------------- src/Tools/offlinedoc/buildqhelp.py | 53 ++--- src/Tools/offlinedoc/buildwikiindex.py | 6 +- src/Tools/offlinedoc/downloadwiki.py | 26 +-- 4 files changed, 73 insertions(+), 305 deletions(-) diff --git a/src/Tools/offlinedoc/buildpdf.py b/src/Tools/offlinedoc/buildpdf.py index d6aac196f9..24d65a2158 100755 --- a/src/Tools/offlinedoc/buildpdf.py +++ b/src/Tools/offlinedoc/buildpdf.py @@ -30,6 +30,8 @@ __url__ = "http://www.freecadweb.org" This script builds a pdf file from a local copy of the wiki """ +Workbenches=["Part","PartDesign","Sketcher","Constraints","Draft","Path","Fem","Arch","TechDraw","Raytracing","OpenSCAD","Robot","Mesh"] + TOC="""Online_Help_Startpage About_FreeCAD Feature_list @@ -41,269 +43,7 @@ Property_editor Import_Export Workbenches -begin - -Part_Workbench -Part_Box -Part_Cone -Part_Cylinder -Part_Sphere -Part_Torus -Part_CreatePrimitives -Part_Plane -Part_Prism -Part_Wedge -Part_Helix -Part_Spiral -Part_Circle -Part_Ellipse -Part_Line -Part_Point -Part_RegularPolygon -Part_Booleans -# Part_Common -# Part_Cut -Part_Fuse -# Part_Shapebuilder -Part_Extrude -Part_Fillet -Part_Revolve -Part_SectionCross -Part_Chamfer -Part_Mirror -Part_RuledSurface -Part_Sweep -Part_Loft -Part_Offset -Part_Thickness -Part_RefineShape -Part_CheckGeometry - -begin - -PartDesign_Workbench -PartDesign_Pad -PartDesign_Pocket -PartDesign_Revolution -PartDesign_Groove - -Sketcher_Point -Sketcher_Line -Sketcher_Arc -Sketcher_Circle -Sketcher_Ellipse -Sketcher_Arc_of_Ellipse -Sketcher_Polyline -Sketcher_Rectangle -Sketcher_Triangle -Sketcher_Square -Sketcher_Pentagon -Sketcher_Hexagon -Sketcher_Heptagon -Sketcher_Octagon -Sketcher_Slot -Sketcher_Fillet -Sketcher_Trimming -# Sketcher_Arc3Point -# Sketcher_Circle3Point -# Sketcher_ConicSections -# Sketcher_Ellipse_by_3_Points - -Constraint_PointOnPoint -Constraint_Vertical -Constraint_Horizontal -Constraint_Parallel -Constraint_Perpendicular -Constraint_Tangent -Constraint_EqualLength -Constraint_Symmetric -Constraint_Lock -Constraint_HorizontalDistance -Constraint_VerticalDistance -Constraint_Length -Constraint_Radius -Constraint_InternalAngle -Constraint_SnellsLaw -Constraint_Internal_Alignment -# Constraint_PointOnObject - -Sketcher_MapSketch -Sketcher_Reorient -Sketcher_Validate -Sketcher_Show_Hide_Internal_Geometry -# Sketcher_MergeSketch -Sketcher_CloseShape -Sketcher_ConnectLines -# Sketcher_SelectConstraints -# Sketcher_SelectOrigin -# Sketcher_SelectVerticalAxis -# Sketcher_SelectHorizontalAxis -# Sketcher_SelectRedundantConstraints -# Sketcher_SelectConflictingConstraints -# Sketcher_SelectElementsAssociatedWithConstraints - -PartDesign_Fillet -PartDesign_Chamfer -PartDesign_Draft -PartDesign_Mirrored -PartDesign_LinearPattern -PartDesign_PolarPattern -PartDesign_Scaled -PartDesign_MultiTransform -PartDesign_WizardShaft -PartDesign_InvoluteGear - -Sketcher_Tutorial - -begin - -Draft_Workbench -Draft_Line -Draft_Wire -Draft_Circle -Draft_Arc -Draft_Ellipse -Draft_Polygon -Draft_Rectangle -Draft_Text -Draft_Dimension -Draft_BSpline -Draft_Point -Draft_ShapeString -Draft_Facebinder -Draft_BezCurve -Draft_Move -Draft_Rotate -Draft_Offset -Draft_Trimex -Draft_Upgrade -Draft_Downgrade -Draft_Scale -Draft_Edit -Draft_WireToBSpline -Draft_AddPoint -Draft_DelPoint -Draft_Shape2DView -Draft_Draft2Sketch -Draft_Array -Draft_Clone -Draft_SelectPlane -Draft_VisGroup - -begin - -Arch_Workbench -Arch_Wall -Arch_Structure -Arch_Rebar -Arch_Floor -Arch_Building -Arch_Site -Arch_Window -Arch_SectionPlane -Arch_Axis -Arch_Roof -Arch_Space -Arch_Stairs -Arch_Panel -Arch_Frame -Arch_Equipment -Arch_CutPlane -Arch_Add -Arch_Remove -Arch_Survey -Arch_tutorial - -begin - -Drawing_Workbench -Drawing_Landscape_A3 -Drawing_View -Drawing_Annotation -Drawing_Clip -Drawing_Openbrowser -Drawing_Symbol -Drawing_DraftView -Drawing_Save -Drawing_ProjectShape -# Drawing_Othoviews - -begin - -Raytracing_Workbench -# Raytracing_New -# Raytracing_Lux -# Raytracing_Part -# Raytracing_ResetCamera -# Raytracing_Export -# Raytracing_Render - -begin - -Robot_Workbench -# Robot_createRobot -# Robot_Simulate -# Robot_Export -# Robot_SetHomePos -# Robot_RestoreHomePos -# Robot_CreateTrajectory -# Robot_SetDefaultOrientation -# Robot_InsertWaypoint -# Robot_InsertWaypointPre -# Robot_Edge2Trac -# Robot_TrajectoryDressUp -# Robot_TrajectoryCompound - -begin - -OpenSCAD_Workbench -OpenSCAD_AddOpenSCADElement -# OpenSCAD_ColorCodeShape -# OpenSCAD_ReplaceObject -# OpenSCAD_RemoveSubtree -# OpenSCAD_RefineShapeFeature -# OpenSCAD_IncreaseTolerance -# OpenSCAD_Edgestofaces -# OpenSCAD_ExpandPlacements -# OpenSCAD_ExplodeGroup -# OpenSCAD_MeshBoolean -# OpenSCAD_Hull -# OpenSCAD_Minkowski - -begin - -Fem_Workbench -FEM_Analysis -# FEM_Solver -# FEM_Create -# FEM_Material -# FEM_Calculation -# FEM_DefineNodes -# FEM_FixedConstraint -# FEM_ForceConstraint -# FEM_BearingConstraint -# FEM_GearConstraint -# FEM_PulleyConstraint -# FEM_ShowResult - -begin - -Plot_Module -Plot_Save -Plot_Basic_tutorial -Plot_MultiAxes_tutorial -# Plot_Axes -# Plot_Series -# Plot_Grid -# Plot_Legend -# Plot_Labels -# Plot_Positions - -begin - -Mesh_Workbench - -end +WorkbenchesList Interface_Customization Preferences_Editor @@ -476,7 +216,7 @@ def joinpdf(): result.addPage(inputfile.getPage(0)) count = 1 - tocfile = TOC.split("\n") + tocfile = createTOC() parent = False for page in tocfile: page = page.strip() @@ -517,6 +257,31 @@ def joinpdf(): print('Successfully created '+FOLDER+os.sep+'freecad.pdf') +def createTOC(): + "populates the TOC" + tocfile = TOC.split("\n") + files = [f for f in os.listdir(FOLDER) if f.endswith(".pdf")] + wbpages = [] + for wb in Workbenches: + wbpage += "begin" + if wb+"_Workbench" in files: + wbpages.append(wb+"_Workbench") + for f in files: + if f.lower().startswith(wb.lower()+"_"): + if (not f.lower().endswith("_workbench")) and (not f.lower().endswith("tutorial")): + wb.append(f) + if wb+"_tutorial" in files: + wbpages.append(wb+"_tutorial") + wbpages.append("end") + toc = [] + for i in tocfile: + if i == "WorkbenchesList": + toc.extend(wbpages) + else: + toc.append(i) + return toc + + def local(page,image=False): "returns a local path for a given page/image" if image: diff --git a/src/Tools/offlinedoc/buildqhelp.py b/src/Tools/offlinedoc/buildqhelp.py index ba4ed56000..2d6572fa01 100755 --- a/src/Tools/offlinedoc/buildqhelp.py +++ b/src/Tools/offlinedoc/buildqhelp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 #*************************************************************************** #* * @@ -31,7 +31,7 @@ This script builds qhrlp files from a local copy of the wiki """ import sys, os, re, tempfile, getopt, shutil -from urllib2 import urlopen, HTTPError +from urllib.request import urlopen, HTTPError # CONFIGURATION ################################################# @@ -39,8 +39,7 @@ FOLDER = "./localwiki" INDEX = "Online_Help_Toc" # the start page from where to crawl the wiki VERBOSE = True # to display what's going on. Otherwise, runs totally silent. QHELPCOMPILER = 'qhelpgenerator' -QCOLLECTIOMGENERATOR = 'qcollectiongenerator' -RELEASE = '0.18' +RELEASE = '0.19' # END CONFIGURATION ############################################## @@ -54,25 +53,25 @@ def crawl(): if os.system(QHELPCOMPILER +' -v'): print ("Error: QAssistant not fully installed, exiting.") return 1 - if os.system(QCOLLECTIOMGENERATOR +' -v'): - print ("Error: QAssistant not fully installed, exiting.") - return 1 # run ######################################################## qhp = buildtoc() qhcp = createCollProjectFile() shutil.copy("../../Gui/Icons/freecad-icon-64.png","localwiki/freecad-icon-64.png") - if generate(qhcp) or compile(qhp): - print ("Error at compiling") + if generate(qhcp): + print ("Error while generating") + return 1 + if compile(qhp): + print ("Error while compiling") return 1 if VERBOSE: print ("All done!") - i=raw_input("Copy the files to their correct location in the source tree? y/n (default=no) ") - if i.upper() in ["Y","YES"]: - shutil.copy("localwiki/freecad.qch","../../Doc/freecad.qch") - shutil.copy("localwiki/freecad.qhc","../../Doc/freecad.qhc") - else: - print ('Files are in localwiki. Test with "assistant -collectionFile localwiki/freecad.qhc"') + #i=raw_input("Copy the files to their correct location in the source tree? y/n (default=no) ") + #if i.upper() in ["Y","YES"]: + # shutil.copy("localwiki/freecad.qch","../../Doc/freecad.qch") + # shutil.copy("localwiki/freecad.qhc","../../Doc/freecad.qhc") + #else: + print ('Files freecad.qch and freecad.qhc are in localwiki. Test with "assistant -collectionFile localwiki/freecad.qhc"') return 0 def compile(qhpfile): @@ -81,6 +80,7 @@ def compile(qhpfile): if not os.system(QHELPCOMPILER + ' '+qhpfile+' -o '+qchfile): if VERBOSE: print ("Successfully created",qchfile) return 0 + return 1 def generate(qhcpfile): "generates qassistant-specific settings like icon, title, ..." @@ -92,9 +92,10 @@ def generate(qhcpfile): about.write(txt) about.close() qhcfile = FOLDER + os.sep + "freecad.qhc" - if not os.system(QCOLLECTIOMGENERATOR+' '+qhcpfile+' -o '+qhcfile): + if not os.system(QHELPCOMPILER+' '+qhcpfile+' -o '+qhcfile): if VERBOSE: print ("Successfully created ",qhcfile) return 0 + return 1 def createCollProjectFile(): qprojectfile = ''' @@ -109,9 +110,6 @@ def createCollProjectFile(): about.txt - freecad-icon-64.png true @@ -136,7 +134,7 @@ def createCollProjectFile(): f = open(qfilename,'w') f.write(qprojectfile) f.close() - if VERBOSE: print ("Done writing qhcp file",qfilename) + if VERBOSE: print ("Done writing qhcp file:",qfilename) return qfilename def buildtoc(): @@ -180,6 +178,9 @@ def buildtoc(): title = re.findall(']*>(.*?)',line)[0].strip() link = re.findall('href="(.*?)"',line)[0].strip() if not link: link = 'default.html' + if title.startswith("" in item): if ("" in item): - inserttoc += '\n' + inserttoc += ' \n' else: link = '' title,link=getname(item) if link: link='" ref="'+link insertkeywords += ('\n') - inserttoc += ('
\n') + if link and title: + inserttoc += ('
\n') else: subitems = item.split("
    ") for i in range(len(subitems)): @@ -214,7 +216,8 @@ def buildtoc(): insertkeywords += ('\n') trail = '' if i == len(subitems)-1: trail = '' - inserttoc += ('
    '+trail+'\n') + if link and title: + inserttoc += ('
    '+trail+'\n') inserttoc += '
    \n' insertfiles = "\n" @@ -226,10 +229,10 @@ def buildtoc(): qhelpfile = re.compile('').sub(inserttoc,qhelpfile) qhelpfile = re.compile('').sub(insertfiles,qhelpfile) qfilename = FOLDER + os.sep + "freecad.qhp" - f = open(qfilename,'wb') + f = open(qfilename,'w') f.write(qhelpfile) f.close() - if VERBOSE: print ("Done writing qhp file",qfilename) + if VERBOSE: print ("Done writing qhp file:",qfilename) return qfilename if __name__ == "__main__": diff --git a/src/Tools/offlinedoc/buildwikiindex.py b/src/Tools/offlinedoc/buildwikiindex.py index f30ff43999..5af78f0fa4 100755 --- a/src/Tools/offlinedoc/buildwikiindex.py +++ b/src/Tools/offlinedoc/buildwikiindex.py @@ -50,7 +50,11 @@ NORETRIEVE += ['Constraint_Concentric','Constraint_EqualLength','Constraint_Exte 'Constraint_PointOnObject','Constraint_PointOnPoint','Constraint_PointOnStart', 'Constraint_PointToObject','Constraint_Radius','Constraint_SnellsLaw', 'Constraint_Symmetric','Constraint_Tangent','Constraint_TangentToEnd', - 'Constraint_TangentToStart','Constraint_Vertical'] # pages that have been renamed but still dangle around... + 'Constraint_TangentToStart','Constraint_Vertical', + 'Join_Cutout','Join_Embed','Part_BooleanFragment','Part_Sections','Curves_HelicalSweep', + 'CurvedShapes_FlyingWingS800','CurvedShapes_HortenHIX','CurvedShapes_SurfaceCut', + 'CurvedShapes_InterpolatedMiddle','CurvedShapes_CurvedSegment','Arch_Cell', + 'Std_ClippingPlane','Std_AboutQt'] # pages that have been renamed but still dangle around... GETTRANSLATIONS = False # Set true if you want to get the translations too. MAXFAIL = 3 # max number of retries if download fails VERBOSE = True # to display what's going on. Otherwise, runs totally silent. diff --git a/src/Tools/offlinedoc/downloadwiki.py b/src/Tools/offlinedoc/downloadwiki.py index 7a63870eb3..727445ff42 100755 --- a/src/Tools/offlinedoc/downloadwiki.py +++ b/src/Tools/offlinedoc/downloadwiki.py @@ -60,15 +60,13 @@ FOLDER = "./localwiki" LISTFILE = "wikifiles.txt" URL = DEFAULTURL wikiindex = "/wiki/index.php?title=" +imageprefix = "/wiki/" defaultfile = " " css = """/* Basic CSS for offline wiki rendering */ body { font-family: Fira Sans,Arial,Helvetica,sans-serif; - font-size: 14px; text-align: justify; - /*background: #fff; - color: #000;*/ max-width: 800px; } @@ -99,7 +97,6 @@ li { pre, .mw-code { text-align: left; - /*background: #eee;*/ padding: 5px 5px 5px 20px; font-family: mono; border-radius: 2px; @@ -131,7 +128,6 @@ a:hover { text-align: left; width: 190px; float: right; - /*background: #eee;*/ margin-top: 10px; border-radius: 2px; } @@ -140,7 +136,7 @@ a:hover { margin-left: 15px; padding: 10px; } -#mw-navigation { +#mw-navigation, .mw-jump-link, .docnav, .NavFrame { display:none; /*TODO remove on next build (included below)*/ } """ @@ -168,7 +164,7 @@ def crawl(): indexpages = get(INDEX) while todolist: targetpage = todolist.pop() - if VERBOSE: print (count, ": Fetching ", targetpage) + if VERBOSE: print (count,(3-len(str(count)))*" ", ": Fetching ", targetpage) get(targetpage) count += 1 if VERBOSE: print ("Fetched ", count, " pages") @@ -192,7 +188,7 @@ def get(page): html = cleanimagelinks(html) output(html,page) else: - if VERBOSE: print (" skipping",page) + if VERBOSE: print (" skipping",page) def getlinks(html): "returns a list of wikipage links in html file" @@ -243,7 +239,7 @@ def cleanhtml(html): html = re.compile('