3
#***************************************************************************
5
#* Copyright (c) 2009 Yorik van Havre <yorik@uncreated.net> *
7
#* This program is free software; you can redistribute it and/or modify *
8
#* it under the terms of the GNU Lesser General Public License (LGPL) *
9
#* as published by the Free Software Foundation; either version 2 of *
10
#* the License, or (at your option) any later version. *
11
#* for detail see the LICENCE text file. *
13
#* This program is distributed in the hope that it will be useful, *
14
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
#* GNU Library General Public License for more details. *
18
#* You should have received a copy of the GNU Library General Public *
19
#* License along with this program; if not, write to the Free Software *
20
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
23
#***************************************************************************
25
__title__="wiki2qhelp"
26
__author__ = "Yorik van Havre <yorik@uncreated.net>"
27
__url__ = "http://www.freecadweb.org"
30
This script builds qhrlp files from a local copy of the wiki
33
import sys, os, re, tempfile, getopt, shutil
34
from urllib2 import urlopen, HTTPError
36
# CONFIGURATION #################################################
38
FOLDER = "./localwiki"
39
INDEX = "Online_Help_Toc" # the start page from where to crawl the wiki
40
VERBOSE = True # to display what's going on. Otherwise, runs totally silent.
41
QHELPCOMPILER = 'qhelpgenerator'
42
QCOLLECTIOMGENERATOR = 'qcollectiongenerator'
45
# END CONFIGURATION ##############################################
50
"downloads an entire wiki site"
52
# tests ###############################################
54
if os.system(QHELPCOMPILER +' -v'):
55
print "Error: QAssistant not fully installed, exiting."
57
if os.system(QCOLLECTIOMGENERATOR +' -v'):
58
print "Error: QAssistant not fully installed, exiting."
61
# run ########################################################
64
qhcp = createCollProjectFile()
65
if generate(qhcp) or compile(qhp):
66
print "Error at compiling"
68
if VERBOSE: print "All done!"
69
i=raw_input("Copy the files to their correct location in the source tree? y/n (default=no) ")
70
if i.upper() in ["Y","YES"]:
71
shutil.copy("localwiki/freecad.qch","../../Doc/freecad.qch")
72
shutil.copy("localwiki/freecad.qhc","../../Doc/freecad.qhc")
74
print 'Files are in localwiki. Test with "assistant -collectionFile localwiki/freecad.qhc"'
78
"compiles the whole html doc with qassistant"
79
qchfile = FOLDER + os.sep + "freecad.qch"
80
if not os.system(QHELPCOMPILER + ' '+qhpfile+' -o '+qchfile):
81
if VERBOSE: print "Successfully created",qchfile
84
def generate(qhcpfile):
85
"generates qassistant-specific settings like icon, title, ..."
87
<center>FreeCAD """+RELEASE+""" help files<br/>
88
<a href="http://www.freecadweb.org">http://www.freecadweb.org</a></center>
90
about=open(FOLDER + os.sep + "about.txt","w")
93
qhcfile = FOLDER + os.sep + "freecad.qhc"
94
if not os.system(QCOLLECTIOMGENERATOR+' '+qhcpfile+' -o '+qhcfile):
95
if VERBOSE: print "Successfully created ",qhcfile
98
def createCollProjectFile():
99
qprojectfile = '''<?xml version="1.0" encoding="UTF-8"?>
100
<QHelpCollectionProject version="1.0">
102
<title>FreeCAD User Manual</title>
103
<applicationIcon>64px-FreeCAD05.svg.png</applicationIcon>
104
<cacheDirectory>freecad/freecad</cacheDirectory>
105
<startPage>qthelp://org.freecad.usermanual/doc/Online_Help_Startpage.html</startPage>
107
<text>About FreeCAD</text>
110
<file>about.txt</file>
112
<icon>images/icon.png</icon>
114
<icon>64px-FreeCAD05.svg.png</icon>
116
<enableDocumentationManager>true</enableDocumentationManager>
117
<enableAddressBar>true</enableAddressBar>
118
<enableFilterFunctionality>true</enableFilterFunctionality>
123
<input>freecad.qhp</input>
124
<output>freecad.qch</output>
128
<file>freecad.qch</file>
131
</QHelpCollectionProject>
133
if VERBOSE: print "Building project file..."
134
qfilename = FOLDER + os.sep + "freecad.qhcp"
135
f = open(qfilename,'w')
136
f.write(qprojectfile)
138
if VERBOSE: print "Done writing qhcp file",qfilename
143
gets the table of contents page and parses its
144
contents into a clean lists structure
147
qhelpfile = '''<?xml version="1.0" encoding="UTF-8"?>
148
<QtHelpProject version="1.0">
149
<namespace>org.freecad.usermanual</namespace>
150
<virtualFolder>doc</virtualFolder>
152
<customFilter name="FreeCAD '''+RELEASE+'''">
153
<filterAttribute>FreeCAD</filterAttribute>
154
<filterAttribute>'''+RELEASE+'''</filterAttribute>
159
<filterAttribute>FreeCAD</filterAttribute>
160
<filterAttribute>'''+RELEASE+'''</filterAttribute>
174
line = re.compile('<li>').sub('',line)
175
line = re.compile('</li>').sub('',line)
179
title = re.findall('<a[^>]*>(.*?)</a>',line)[0].strip()
180
link = re.findall('href="(.*?)"',line)[0].strip()
181
if not link: link = 'default.html'
184
if VERBOSE: print "Building table of contents..."
185
f = open(FOLDER+os.sep+INDEX+'.html')
187
for line in f: html += line
189
html = html.replace("\n"," ")
190
html = html.replace("> <","><")
191
html = re.findall("<ul.*/ul>",html)[0]
192
items = re.findall('<li[^>]*>.*?</li>|</ul></li>',html)
193
inserttoc = '<section title="FreeCAD Documentation" ref="Online_Help_Toc.html">\n'
196
if not ("<ul>" in item):
197
if ("</ul>" in item):
198
inserttoc += '</section>\n'
201
title,link=getname(item)
204
insertkeywords += ('<keyword name="'+title+link+'"/>\n')
205
inserttoc += ('<section title="'+title+link+'"></section>\n')
207
subitems = item.split("<ul>")
208
for i in range(len(subitems)):
210
title,link=getname(subitems[i])
213
insertkeywords += ('<keyword name="'+title+link+'"/>\n')
215
if i == len(subitems)-1: trail = '</section>'
216
inserttoc += ('<section title="'+title+link+'">'+trail+'\n')
217
inserttoc += '</section>\n'
219
insertfiles = "<files>\n"
220
for fil in os.listdir(FOLDER):
221
insertfiles += ("<file>"+fil+"</file>\n")
222
insertfiles += "</files>\n"
224
qhelpfile = re.compile('<insertkeywords>').sub(insertkeywords,qhelpfile)
225
qhelpfile = re.compile('<inserttoc>').sub(inserttoc,qhelpfile)
226
qhelpfile = re.compile('<insertfiles>').sub(insertfiles,qhelpfile)
227
qfilename = FOLDER + os.sep + "freecad.qhp"
228
f = open(qfilename,'wb')
231
if VERBOSE: print "Done writing qhp file",qfilename
234
if __name__ == "__main__":