Skip to content

Commit

Permalink
Refs #6101. Splitting QHPfile into a separate python file for reuse.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Jan 30, 2013
1 parent 7bd46ff commit a100544
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 55 deletions.
56 changes: 1 addition & 55 deletions Code/Mantid/docs/qtassistant/make_algorithms_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,13 @@
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/"

class QHPFile:
def __init__(self, namespace, folder="doc"):
self.__root = le.Element("QtHelpProject",
**{"version":"1.0"})

self.__addtxtele(self.__root, "namespace", namespace)
self.__addtxtele(self.__root, "virtualFolder", folder)

self.__filterSect = le.SubElement(self.__root, "filterSection")

self.__keywordsEle = None # should have 'keywords' section
self.__keywords = []
self.__filesEle = None # should have 'files' section
self.__files = []

def addTOC(self, contents):
"""
The contents must all be specified at once. They should be in the
form of [(title1, ref1), (title2, ref2), ...].
"""
toc = le.SubElement(self.__filterSect, "toc")
for (title, ref) in contents:
le.SubElement(toc, "section",
**{"title":title, "ref":ref})

def addFile(self, filename, keyword=None):
if not keyword is None:
if self.__keywordsEle is None:
self.__keywordsEle = le.SubElement(self.__filterSect, "keywords")
if not keyword in self.__keywords:
le.SubElement(self.__keywordsEle, "keyword",
**{"name":keyword, "ref":os.path.split(filename)[1]})
self.__keywords.append(keyword)
if self.__filesEle is None:
self.__filesEle = le.SubElement(self.__filterSect, "files")
if not filename in self.__files:
self.__addtxtele(self.__filesEle, "file", filename)
self.__files.append(filename)

def __addtxtele(self, parent, tag, text):
ele = le.SubElement(parent, tag)
ele.text = text
return ele

def __str__(self):
return le.tostring(self.__root, pretty_print=True)#,
#xml_declaration=True)

def write(self, filename):
"""
Write the help configuration to the given filename.
"""
handle = open(filename, 'w')
handle.write(str(self))

def addWikiDir(helpsrcdir):
"""
Add the location of the wiki tools to the python path.
Expand Down
63 changes: 63 additions & 0 deletions Code/Mantid/docs/qtassistant/qhpfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
from lxml import etree as le # python-lxml on rpm based systems
import lxml.html
from lxml.html import builder as lh
import os

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

class QHPFile:
def __init__(self, namespace, folder="doc"):
self.__root = le.Element("QtHelpProject",
**{"version":"1.0"})

self.__addtxtele(self.__root, "namespace", namespace)
self.__addtxtele(self.__root, "virtualFolder", folder)

self.__filterSect = le.SubElement(self.__root, "filterSection")

self.__keywordsEle = None # should have 'keywords' section
self.__keywords = []
self.__filesEle = None # should have 'files' section
self.__files = []

def addTOC(self, contents):
"""
The contents must all be specified at once. They should be in the
form of [(title1, ref1), (title2, ref2), ...].
"""
toc = le.SubElement(self.__filterSect, "toc")
for (title, ref) in contents:
le.SubElement(toc, "section",
**{"title":title, "ref":ref})

def addFile(self, filename, keyword=None):
if not keyword is None:
if self.__keywordsEle is None:
self.__keywordsEle = le.SubElement(self.__filterSect, "keywords")
if not keyword in self.__keywords:
le.SubElement(self.__keywordsEle, "keyword",
**{"name":keyword, "ref":os.path.split(filename)[1]})
self.__keywords.append(keyword)
if self.__filesEle is None:
self.__filesEle = le.SubElement(self.__filterSect, "files")
if not filename in self.__files:
self.__addtxtele(self.__filesEle, "file", filename)
self.__files.append(filename)

def __addtxtele(self, parent, tag, text):
ele = le.SubElement(parent, tag)
ele.text = text
return ele

def __str__(self):
return le.tostring(self.__root, pretty_print=True)#,
#xml_declaration=True)

def write(self, filename):
"""
Write the help configuration to the given filename.
"""
handle = open(filename, 'w')
handle.write(str(self))

0 comments on commit a100544

Please sign in to comment.