Skip to content

Commit

Permalink
Refs #6101. Autogenerate fit function index.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Jan 30, 2013
1 parent a100544 commit d051a95
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 1,011 deletions.
13 changes: 9 additions & 4 deletions Code/Mantid/docs/qtassistant/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ if (QT_QCOLLECTIONGENERATOR_EXECUTABLE)
img/Mantid_Logo_Transparent.png
img/MantidPlot_Icon_32offset.png
src/about.txt
src/fitfunctions.html
#src/fitfunctions.html
src/mantidgeneral.qhp
)

add_custom_command(OUTPUT generated/algorithms_index.html generated/algorithms.qhp
DEPENDS make_algorithms_help.py
DEPENDS make_algorithms_help.py qhpfile.py
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_algorithms_help.py -m ${CMAKE_BINARY_DIR}
)

add_custom_command(OUTPUT generated/fitfunctions_index.html generated/fitfunctions.qhp
DEPENDS make_fitfunctions_help.py qhpfile.py
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_fitfunctions_help.py -m ${CMAKE_BINARY_DIR}
)

add_custom_command(OUTPUT mantid.qhc algorithms.qch mantidgeneral.qch
DEPENDS generated/algorithms_index.html generated/algorithms.qhp ${HELP_QHCP_SOURCE}
DEPENDS generated/algorithms_index.html generated/algorithms.qhp generated/fitfunctions_index.html generated/fitfunctions.qhp ${HELP_QHCP_SOURCE}
COMMAND ${QT_QCOLLECTIONGENERATOR_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mantid.qhcp
)

add_custom_target ( qtassistant
DEPENDS MantidPlot generated/algorithms.qhp mantid.qhc
DEPENDS MantidPlot generated/algorithms.qhp generated/fitfunctions.qhp mantid.qhc
)

# install ( FILES mantid.qhc algorithms.qch mantidgeneral.qch
Expand Down
14 changes: 7 additions & 7 deletions Code/Mantid/docs/qtassistant/make_algorithms_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def genCatElement(category):
return lxml.html.fragment_fromstring(text)

def genAlgoElement(name, versions):
text = '<a href="%s">%s' % (WEB_BASE+name, name)
text = '<li><a href="%s">%s' % (WEB_BASE+name, name)
text += ' v%d</a>' % versions[-1]

if len(versions) > 1:
text += ' v' + str(versions[-1])
text += '</a>'
text += ', ' + ', '.join(['v'+str(version) for version in versions[:-1]])
text += '</li>'
return lxml.html.fragment_fromstring(text)

def processCategories(categories, qhp, outputdir):
Expand Down Expand Up @@ -67,8 +69,7 @@ def processCategories(categories, qhp, outputdir):
#body.append(lh.H2(subcategory))
ul = le.SubElement(body, "ul")
for (name, versions) in categories[subcategory]:
li = le.SubElement(ul, "li")
li.append(genAlgoElement(name, versions))
ul.append(genAlgoElement(name, versions))

filename = "AlgoCat_%s.html" % page_name
qhp.addFile(filename, page_name+" Algorithm Category")
Expand Down Expand Up @@ -139,8 +140,7 @@ def process(algos, qhp, outputdir):

ul = le.SubElement(div_alpha, "ul")
for (name, versions) in letter_groups[letter]:
li = le.SubElement(ul, "li")
li.append(genAlgoElement(name, versions))
ul.append(genAlgoElement(name, versions))

# print an index within the page
div_alpha.append( lxml.html.fragment_fromstring(para_text))
Expand Down
130 changes: 130 additions & 0 deletions Code/Mantid/docs/qtassistant/make_fitfunctions_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python
import argparse
from lxml import etree as le # python-lxml on rpm based systems
import lxml.html
from lxml.html import builder as lh
import os
from qhpfile import QHPFile
from string import split,join
import sys

OUTPUTDIR = "generated"
WEB_BASE = "http://www.mantidproject.org/"

def addWikiDir(helpsrcdir):
"""
Add the location of the wiki tools to the python path.
"""
wikitoolsloc = os.path.join(helpsrcdir, "../../Build")
wikitoolsloc = os.path.abspath(wikitoolsloc)
sys.path.append(wikitoolsloc)

def genFuncElement(name):
text = '<a href="%s">%s</a>' % (WEB_BASE+name, name)
return lxml.html.fragment_fromstring(text)

def processCategories(categories, qhp, outputdir):
# determine the list of html pages
grouped_categories = {}
for key in categories.keys():
shortkey = key.split('/')[0]
if not shortkey in grouped_categories:
grouped_categories[shortkey] = []
grouped_categories[shortkey].append(key)
pages = grouped_categories.keys()
pages.sort()

for page_name in pages:

root = le.Element("html")
head = le.SubElement(root, "head")
head.append(lh.META(lh.TITLE(page_name + " Algorithm Category")))
body = le.SubElement(root, "body")
body.append(lh.CENTER(lh.H1(page_name)))

subcategories = grouped_categories[page_name]
subcategories.sort()
for subcategory in subcategories:
anchor = subcategory.split('/')
anchor = '_'.join(anchor[1:])
temp = le.SubElement(body, "h2")
le.SubElement(temp, 'a', **{"name":anchor})
temp.text=subcategory
#body.append(lh.H2(subcategory))
ul = le.SubElement(body, "ul")
for (name, versions) in categories[subcategory]:
li = le.SubElement(ul, "li")
li.append(genAlgoElement(name, versions))

filename = "AlgoCat_%s.html" % page_name
qhp.addFile(filename, page_name+" Algorithm Category")
filename = os.path.join(outputdir, filename)
handle = open(filename, 'w')
handle.write(le.tostring(root, pretty_print=True, xml_declaration=False))

def process(functionsalgos, qhp, outputdir):
import mantid.api

# sort algorithms into categories
categories = {}
for name in functions:
func = mantid.api.FunctionFactory.createFunction(name)
for category in func.categories():
category = category.replace('\\', '/')
if not categories.has_key(category):
categories[category] = []
categories[category].append(name)
categories_list = categories.keys()
categories_list.sort()

##### put together the top of the html document
root = le.Element("html")
head = le.SubElement(root, "head")
head.append(lh.META(lh.TITLE("Fit Functions Index")))
body = le.SubElement(root, "body")
body.append(lh.CENTER(lh.H1("Fit Functions Index")))

##### section for categories
div_cat = le.SubElement(body, "div", **{"id":"function_cats"})
for category in categories_list:
div_cat.append(lh.H2(category + " Category"))
ul = le.SubElement(div_cat, "ul")
funcs = categories[category]
for func in funcs:
li = le.SubElement(ul, "li")
li.append(genFuncElement(func))

filename = os.path.join(outputdir, "fitfunctions_index.html")
handle = open(filename, 'w')
handle.write(le.tostring(root, pretty_print=True, xml_declaration=False))

shortname = os.path.split(filename)[1]
qhp.addFile(shortname, "Fit Functions Index")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate qtassistant docs " \
+ "for the fit functions")
defaultmantidpath = ""
parser.add_argument('-m', '--mantidpath', dest='mantidpath',
default=defaultmantidpath,
help="Full path to the Mantid compiled binary folder. Default: '%s'. This will be saved to an .ini file" % defaultmantidpath)

args = parser.parse_args()

# where to put the generated files
helpsrcdir = os.path.dirname(os.path.abspath(__file__))
helpoutdir = os.path.join(helpsrcdir, OUTPUTDIR)
print helpoutdir
addWikiDir(helpsrcdir)

# initialize mantid
import wiki_tools
wiki_tools.initialize_Mantid(args.mantidpath)
import mantid.api
functions = mantid.api.FunctionFactory.getFunctionNames()

# setup the qhp file
qhp = QHPFile("org.mantidproject.fitfunctions")

process(functions, qhp, helpoutdir)
qhp.write(os.path.join(helpoutdir, "fitfunctions.qhp"))
5 changes: 5 additions & 0 deletions Code/Mantid/docs/qtassistant/mantid.qhcp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
<input>generated/algorithms.qhp</input>
<output>algorithms.qch</output>
</file>
<file>
<input>generated/fitfunctions.qhp</input>
<output>fitfunctions.qch</output>
</file>
</generate>
<register>
<file>mantidgeneral.qch</file>
<file>algorithms.qch</file>
<file>fitfunctions.qch</file>
</register>
</docFiles>
</QHelpCollectionProject>

0 comments on commit d051a95

Please sign in to comment.