diff --git a/src/Tools/offlinedoc/README b/src/Tools/offlinedoc/README deleted file mode 100644 index 621fe07ef4..0000000000 --- a/src/Tools/offlinedoc/README +++ /dev/null @@ -1,41 +0,0 @@ -this suite of tools can be used to retrieve a local copy -from the FreeCAD wiki and then use it to generate qhelp -and pdf files. The downloading of the entire wiki is now -a huge operation, prone to network errors, so it has been -cut into 2 parts, one to retrieve a list of files to -download and another to actually download the files. - -1) run "buildwikiindex.py" to build an index file containing - a list of all the files to download - -2) run "downloadwiki.py". If connection drops, run it again, - the already downloaded files will be skipped. - -2b) Dirty hack: run "fixlinks.py" to fix wrong html links - (downloadwiki.py should be fixed in the future) - -3) run "buildqhelp.py" to generate freecad.qhc and freecad.qch - files - -4) run "buildpdf.py" to generate freecad.pdf (wkhtmltopdf must be installed) - -5) the qhelp files can be tested with "assistant -collectionFile freecad.qhc" - -6) If you have already downloaded the whole wiki, run "update.py" immediately - after, to create a list of revision IDs for each page. - -7) Once the initial revisions list has been created, the "update.py" script - can be ran anytime in the future, to check for pages that have changed - since the stored revision ID. The script is meant to run twice, one to get - a list of pages that have changed, and another one to download the changed - pages (and all their dependencies) again. - -8) To split the generated freecad.qch into parts that are smaller than 50Mb - (github limit): split -d --byte=49M localwiki/freecad.qch localwiki/freecad.qch.part - -9) To join the parts again (for testing): cat localwiki/freecad.qch.part* >> test.qch - Then check that test.qch has the same md5 number than localwiki/freecad.qch - -10) To test: assistant -collectionFile localwiki/freecad.qhc - - diff --git a/src/Tools/offlinedoc/buildpdf.py b/src/Tools/offlinedoc/buildpdf.py deleted file mode 100755 index 8469886268..0000000000 --- a/src/Tools/offlinedoc/buildpdf.py +++ /dev/null @@ -1,322 +0,0 @@ -#!/usr/bin/env python - -#*************************************************************************** -#* * -#* Copyright (c) 2009 Yorik van Havre * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* This program is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Library General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with this program; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#*************************************************************************** - -__title__="buildpdf" -__author__ = "Yorik van Havre " -__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 -Installing -Getting_started -Mouse_Model -Document_structure -Property_editor -Import_Export -Workbenches - -WorkbenchesList - -Interface_Customization -Preferences_Editor -Macros -Introduction_to_Python -Python_scripting_tutorial -Topological_data_scripting -Mesh_Scripting -Mesh_to_Part -Scenegraph -Pivy - -begin - -PySide -PySide_Beginner_Examples -PySide_Medium_Examples -PySide_Advanced_Examples - -end - -Scripted_objects -Embedding_FreeCAD -Embedding_FreeCADGui -Code_snippets""" - -import sys, os, shutil, time -from urllib.request import urlopen - -# CONFIGURATION ################################################# - -INDEX = "Online_Help_Toc" # the start page from where to crawl the wiki -PDFCONVERTOR = 'wkhtmltopdf' # can be 'pisa', 'htmldoc', 'wkhtmltopdf' or 'firefox' -VERBOSE = True # set true to get output messages -INCLUDECOMMANDS = True # if true, the command pages of each workbench are included after each WB page -OVERWRITE = False # if true, pdf files are recreated even if already existing -FIREFOXPDFFOLDER = os.path.expanduser("~")+os.sep+"PDF" # if firefox is used, set this to where it places its pdf files by default -COVER = "http://www.freecadweb.org/wiki/images/7/79/Freecad-pdf-cover.svg" - -# END CONFIGURATION ############################################## - - -FOLDER = "./localwiki" - -fcount = dcount = 0 - -def crawl(): - "creates a pdf file from the localwiki folder" - - # tests ############################################### - - if PDFCONVERTOR == 'pisa': - try: - import ho.pisa as pisa - except Exception: - "Error: Python-pisa not installed, exiting." - return 1 - elif PDFCONVERTOR == 'htmldoc': - if os.system('htmldoc --version'): - print("Error: Htmldoc not found, exiting.") - return 1 - try: - from PyPDF2 import PdfFileReader,PdfFileWriter - except Exception: - print("Error: Python-pypdf2 not installed, exiting.") - - # run ######################################################## - - buildpdffiles() - joinpdf() - - if VERBOSE: print("All done!") - return 0 - - -def buildpdffiles(): - "scans a folder for html files and converts them all to pdf" - templist = os.listdir(FOLDER) - if PDFCONVERTOR == 'wkhtmltopdf': - makeStyleSheet() - global fileslist - fileslist = [] - for i in templist: - if i[-5:] == '.html': - fileslist.append(i) - print("converting ",len(fileslist)," pages") - i = 1 - for f in fileslist: - print(i," : ",f) - if PDFCONVERTOR == 'pisa': - createpdf_pisa(f[:-5]) - elif PDFCONVERTOR == 'wkhtmltopdf': - createpdf_wkhtmltopdf(f[:-5]) - elif PDFCONVERTOR == 'firefox': - createpdf_firefox(f[:-5]) - else: - createpdf_htmldoc(f[:-5]) - i += 1 - - -def fetch_resources(uri, rel): - """ - Callback to allow pisa/reportlab to retrieve Images,Stylesheets, etc. - 'uri' is the href attribute from the html link element. - 'rel' gives a relative path, but it's not used here. - - Note from Yorik: Not working!! - """ - path = os.path.join(FOLDER,uri.replace("./", "")) - return path - -def createpdf_pisa(pagename): - "creates a pdf file from a saved page using pisa (python module)" - import ho.pisa as pisa - if (not exists(pagename+".pdf",image=True)) or OVERWRITE: - infile = open(FOLDER + os.sep + pagename+'.html','ro') - outfile = open(FOLDER + os.sep + pagename+'.pdf','wb') - if VERBOSE: print("Converting " + pagename + " to pdf...") - pdf = pisa.CreatePDF(infile,outfile,FOLDER,link_callback=fetch_resources) - outfile.close() - if pdf.err: - return pdf.err - return 0 - - -def createpdf_firefox(pagename): - "creates a pdf file from a saved page using firefox (needs command line printing extension)" - # the default printer will be used, so make sure it is set to pdf - # command line printing extension http://forums.mozillazine.org/viewtopic.php?f=38&t=2729795 - if (not exists(pagename+".pdf",image=True)) or OVERWRITE: - infile = FOLDER + os.sep + pagename+'.html' - outfile = FOLDER + os.sep + pagename+'.pdf' - os.system('firefox -print ' + infile) - time.sleep(6) - if os.path.exists(FIREFOXPDFFOLDER + os.sep + pagename + ".pdf"): - shutil.move(FIREFOXPDFFOLDER+os.sep+pagename+".pdf",outfile) - else: - print("-----------------------------------------> Couldn't find print output!") - - -def createpdf_htmldoc(pagename): - "creates a pdf file from a saved page using htmldoc (external app, but supports images)" - if (not exists(pagename+".pdf",image=True)) or OVERWRITE: - infile = FOLDER + os.sep + pagename+'.html' - outfile = FOLDER + os.sep + pagename+'.pdf' - return os.system('htmldoc --webpage --textfont sans --browserwidth 840 -f '+outfile+' '+infile) - - -def createpdf_wkhtmltopdf(pagename): - "creates a pdf file from a saved page using htmldoc (external app, but supports images)" - if (not exists(pagename+".pdf",image=True)) or OVERWRITE: - infile = FOLDER + os.sep + pagename+'.html' - outfile = FOLDER + os.sep + pagename+'.pdf' - cmd = 'wkhtmltopdf -L 5mm --user-style-sheet '+FOLDER+os.sep+'wkhtmltopdf.css '+infile+' '+outfile - print(cmd) - #return os.system(cmd) - else: - print("skipping") - - -def joinpdf(): - "creates one pdf file from several others, following order from the cover" - from PyPDF2 import PdfFileReader,PdfFileWriter - if VERBOSE: print("Building table of contents...") - - result = PdfFileWriter() - createCover() - inputfile = PdfFileReader(open(FOLDER+os.sep+'Cover.pdf','rb')) - result.addPage(inputfile.getPage(0)) - count = 1 - - tocfile = createTOC() - parent = False - for page in tocfile: - page = page.strip() - if page: - if page[0] == "#": - continue - if page == "begin": - parent = True - continue - if page == "end": - parent = False - continue - if VERBOSE: print('Appending ',page, " at position ",count) - title = page.replace("_"," ") - pdffile = page + ".pdf" - if exists(pdffile,True): - inputfile = PdfFileReader(open(FOLDER + os.sep + pdffile,'rb')) - numpages = inputfile.getNumPages() - for i in range(numpages): - result.addPage(inputfile.getPage(i)) - if parent == True: - parent = result.addBookmark(title,count) - elif parent == False: - result.addBookmark(title,count) - else: - result.addBookmark(title,count,parent) - count += numpages - else: - print("page ",pdffile," not found, aborting.") - sys.exit() - - if VERBOSE: print("Writing...") - outputfile = open(FOLDER+os.sep+"freecad.pdf",'wb') - result.write(outputfile) - outputfile.close() - if VERBOSE: - print(' ') - 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: - return FOLDER + os.sep + page - else: - return FOLDER + os.sep + page + '.html' - - -def exists(page,image=False): - "checks if given page/image already exists" - path = local(page,image) - if os.path.exists(path): return True - return False - - -def makeStyleSheet(): - "Creates a stylesheet for wkhtmltopdf" - outputfile = open(FOLDER+os.sep+"wkhtmltopdf.css",'wb') - outputfile.write(""" -.printfooter { - display:none !important; -} -""") - outputfile.close() - - -def createCover(): - "downloads and creates a cover page" - if VERBOSE: print("fetching " + COVER) - data = (urlopen(COVER).read()) - path = FOLDER + os.sep + "Cover.svg" - fil = open(path,'wb') - fil.write(data) - fil.close() - os.system('inkscape --export-pdf='+FOLDER+os.sep+'Cover.pdf'+' '+FOLDER+os.sep+'Cover.svg') - - -if __name__ == "__main__": - crawl() diff --git a/src/Tools/offlinedoc/buildqhelp.py b/src/Tools/offlinedoc/buildqhelp.py deleted file mode 100755 index 5608154d7b..0000000000 --- a/src/Tools/offlinedoc/buildqhelp.py +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/env python3 - -#*************************************************************************** -#* * -#* Copyright (c) 2009 Yorik van Havre * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* This program is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Library General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with this program; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#*************************************************************************** - -__title__="wiki2qhelp" -__author__ = "Yorik van Havre " -__url__ = "http://www.freecadweb.org" - -""" -This script builds qhrlp files from a local copy of the wiki -""" - -import os, re, shutil - -# CONFIGURATION ################################################# - -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' -RELEASE = '0.19' - -# END CONFIGURATION ############################################## - -fcount = dcount = 0 - -def crawl(): - "downloads an entire wiki site" - - # tests ############################################### - - if os.system(QHELPCOMPILER +' -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): - 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 freecad.qch and freecad.qhc are in localwiki. Test with "assistant -collectionFile localwiki/freecad.qhc"') - return 0 - -def compile(qhpfile): - "compiles the whole html doc with qassistant" - qchfile = FOLDER + os.sep + "freecad.qch" - 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, ..." - txt=""" -
FreeCAD """+RELEASE+""" help files
-http://www.freecadweb.org
- """ - about=open(FOLDER + os.sep + "about.txt","w") - about.write(txt) - about.close() - qhcfile = FOLDER + os.sep + "freecad.qhc" - if not os.system(QHELPCOMPILER+' '+qhcpfile+' -o '+qhcfile): - if VERBOSE: print ("Successfully created ",qhcfile) - return 0 - return 1 - -def createCollProjectFile(): - qprojectfile = ''' - - - FreeCAD User Manual - freecad-icon-64.png - freecad/freecad - qthelp://org.freecad.usermanual/doc/Online_Help_Startpage.html - - About FreeCAD - - - about.txt - freecad-icon-64.png - - true - true - true - - - - - freecad.qhp - freecad.qch - - - - freecad.qch - - - -''' - if VERBOSE: print ("Building project file...") - qfilename = FOLDER + os.sep + "freecad.qhcp" - f = open(qfilename,'w') - f.write(qprojectfile) - f.close() - if VERBOSE: print ("Done writing qhcp file:",qfilename) - return qfilename - -def buildtoc(): - ''' - gets the table of contents page and parses its - contents into a clean lists structure - ''' - - qhelpfile = ''' - - org.freecad.usermanual - doc - - - - - - - - - - - - -''' - - def getname(line): - line = re.compile('
  • ').sub('',line) - line = re.compile('
  • ').sub('',line) - title = line.strip() - link = '' - if "]*>(.*?)',line)[0].strip() - link = re.findall('href="(.*?)"',line)[0].strip() - if link: - if not link.endswith(".html"): - link = link + ".html" - if link.startswith("/"): - link = link[1:] - if not link: link = 'default.html' - if title.startswith(" <","><") - html = re.findall("",html)[0] - items = re.findall(']*>.*?|',html) - inserttoc = '
    \n' - insertkeywords = '' - for item in items: - if not ("
      " in item): - if ("
    " in item): - inserttoc += '
    \n' - else: - link = '' - title,link=getname(item) - if link: - link='" ref="'+link - insertkeywords += ('\n') - if link and title: - inserttoc += ('
    \n') - else: - subitems = item.split("
      ") - for i in range(len(subitems)): - link = '' - title,link=getname(subitems[i]) - if link: - link='" ref="'+link - insertkeywords += ('\n') - trail = '' - if i == len(subitems)-1: trail = '' - if link and title: - inserttoc += ('
      '+trail+'\n') - inserttoc += '
      \n' - - insertfiles = "\n" - for fil in os.listdir(FOLDER): - insertfiles += (""+fil+"\n") - insertfiles += "\n" - - qhelpfile = re.compile('').sub(insertkeywords,qhelpfile) - qhelpfile = re.compile('').sub(inserttoc,qhelpfile) - qhelpfile = re.compile('').sub(insertfiles,qhelpfile) - qfilename = FOLDER + os.sep + "freecad.qhp" - f = open(qfilename,'w') - f.write(qhelpfile) - f.close() - if VERBOSE: print ("Done writing qhp file:",qfilename) - return qfilename - -if __name__ == "__main__": - crawl() - diff --git a/src/Tools/offlinedoc/buildwikiindex.py b/src/Tools/offlinedoc/buildwikiindex.py deleted file mode 100755 index 34f7730110..0000000000 --- a/src/Tools/offlinedoc/buildwikiindex.py +++ /dev/null @@ -1,222 +0,0 @@ -#!/usr/bin/env python - -#*************************************************************************** -#* * -#* Copyright (c) 2009 Yorik van Havre * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* This program is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Library General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with this program; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#*************************************************************************** - -from __future__ import print_function - -__title__="buildwikiindex.py" -__author__ = "Yorik van Havre " -__url__ = "http://www.freecadweb.org" - -""" -This script parses the contents of a wiki site and saves a file containing -names of pages and images to be downloaded. -""" - -import sys, os, re -from urllib2 import urlopen, HTTPError - -# CONFIGURATION ################################################# - -URL = "https://www.freecadweb.org/wiki" #default URL if no URL is passed -INDEX = "Online_Help_Toc" # the start page from where to crawl the wiki -NORETRIEVE = ['Manual','Developer_hub','Power_users_hub','Users_hub','Source_documentation', - 'User_hub','Main_Page','About_this_site','Interesting_links','Syndication_feeds', - 'FreeCAD:General_disclaimer','FreeCAD:About','FreeCAD:Privacy_policy','WikiPages'] # pages that won't be fetched (kept online) -NORETRIEVE += ['Constraint_Concentric','Constraint_EqualLength','Constraint_ExternalAngle', - 'Constraint_Horizontal','Constraint_HorizontalDistance','Constraint_Internal_Alignment', - 'Constraint_InternalAngle','Constraint_Length','Constraint_Lock','Constraint_Parallel', - 'Constraint_Perpendicular','Constraint_PointOnEnd','Constraint_PointOnMidPoint', - 'Constraint_PointOnObject','Constraint_PointOnPoint','Constraint_PointOnStart', - 'Constraint_PointToObject','Constraint_Radius','Constraint_SnellsLaw', - 'Constraint_Symmetric','Constraint_Tangent','Constraint_TangentToEnd', - '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. -WRITETHROUGH = True # if true, fetched files are constantly written to disk, in case of failure. - -# END CONFIGURATION ############################################## - -wikiindex = "/index.php?title=" - -def crawl(pagename=[]): - "downloads an entire wiki site" - todolist = [] - processed = [] - count = 1 - if pagename: - if not isinstance(pagename,list): - pagename = [pagename] - todolist = pagename - else: - if os.path.exists("wikifiles.txt"): - f = open("wikifiles.txt","r") - if VERBOSE: print ("Reading existing list...") - for l in f.readlines(): - if l.strip() != "": - if VERBOSE: print ("Adding ",l) - processed.append(l.strip()) - f.close() - if os.path.exists("todolist.txt"): - f = open("todolist.txt","r") - if VERBOSE: print ("Reading existing todo list...") - for l in f.readlines(): - if l.strip() != "": - todolist.append(l.strip()) - f.close() - else: - indexpages,imgs = get(INDEX) - todolist.extend(indexpages) - while todolist: - targetpage = todolist.pop() - if (not targetpage in NORETRIEVE): - if VERBOSE: print (count, ": Scanning ", targetpage) - pages,images = get(targetpage) - count += 1 - processed.append(targetpage) - processed.extend(images) - if VERBOSE: print ("got",len(pages),"links") - for p in pages: - if (not (p in todolist)) and (not (p in processed)): - todolist.append(p) - if WRITETHROUGH: - writeList(processed) - writeList(todolist,"todolist.txt") - if VERBOSE: print ("Fetched ", count, " pages") - if not WRITETHROUGH: - writeList(processed) - if pagename: - return processed - return 0 - -def get(page): - "downloads a single page, returns the other pages it links to" - html = fetchpage(page) - html = cleanhtml(html) - pages = getlinks(html) - images = getimagelinks(html) - return pages,images - -def cleanhtml(html): - "cleans given html code from dirty script stuff" - html = html.replace('\n','Wlinebreak') # removing linebreaks for regex processing - html = re.compile('(.*)]+column-content+[^>]+>').sub('',html) # stripping before content - html = re.compile(']+column-one+[^>]+>.*').sub('',html) # stripping after content - html = re.compile('').sub('',html) # removing comment tags - html = re.compile(']*>.*?').sub('',html) # removing script tags - html = re.compile('').sub('',html) # removing IE tags - html = re.compile('
      ]*>.*?
      ').sub('',html) # removing nav div - html = re.compile('

      ]*>.*?

      ').sub('',html) # removing print subtitle - html = re.compile('Retrieved from').sub('Online version:',html) # changing online title - html = re.compile('