diff --git a/Code/Mantid/Build/wiki_tools.py b/Code/Mantid/Build/wiki_tools.py index e30ea3c4dc4421cc72ac1dc6f82eff268e7684c4..c34a60b2309ecea8d1fdbbfbfbd99e97e7e2e62d 100755 --- a/Code/Mantid/Build/wiki_tools.py +++ b/Code/Mantid/Build/wiki_tools.py @@ -273,7 +273,6 @@ def initialize_wiki(args): #====================================================================== - def flag_if_build_is_debug(mantidpath): """ Check if the given build is a debug build of Mantid diff --git a/Code/Mantid/CMakeLists.txt b/Code/Mantid/CMakeLists.txt index 789b998fec0e140cef2983e3fa33d153d46be4fd..52e1b74f7ac94a4451f2e20d2d0fbd272d713b22 100644 --- a/Code/Mantid/CMakeLists.txt +++ b/Code/Mantid/CMakeLists.txt @@ -184,6 +184,16 @@ if ( ENABLE_CPACK ) else() set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES} qscintilla" ) endif() + + # qt assistant is in different places in every distro + if ( ${UNIX_DIST} MATCHES "RedHatEnterprise" ) + set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES} qt4-x11" ) + elseif ( ${UNIX_DIST} MATCHES "Fedora" ) + set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES} qt4-assistant" ) + elseif ( ${UNIX_DIST} MATCHES "SUSE LINUX" ) + set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES} libqt4-devel-doc" ) + endif ( ${UNIX_DIST} MATCHES "RedHatEnterprise" ) + if( ${UNIX_DIST} STREQUAL "Ubuntu" ) if( ${UNIX_CODENAME} STREQUAL "lucid" ) set ( CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-date-time1.40.0,libboost-regex1.40.0,libboost-signals1.40.0,libpocofoundation9,libpocoutil9,libpoconet9,libpoconetssl9,libpococrypto9,libpocoxml9,libnexus0 (>= 4.2),libgsl0ldbl,libqtcore4 (>= 4.2),libqtgui4 (>= 4.2),libqt4-opengl (>= 4.2),libqt4-xml (>= 4.2),libqt4-svg (>= 4.2),libqt4-qt3support (>= 4.2),libqscintilla2-5,libqwt5-qt4,libqwtplot3d-qt4-0" ) @@ -196,6 +206,7 @@ if ( ENABLE_CPACK ) else() message( WARNING "Mantid does not support packaging of this Ubuntu version: ${UNIX_CODENAME}") endif() + set ( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},qt4-dev-tools" ) # for qt assistant endif() # soft requirement of tcmalloc - if built with it, then require it IF ( USE_TCMALLOC AND TCMALLOC_FOUND ) diff --git a/Code/Mantid/MantidPlot/CMakeLists.txt b/Code/Mantid/MantidPlot/CMakeLists.txt index 66b7b0afc73527a928a19e628b7e7c1ac08a77e7..cc630fc9b37ec964f7c3b006552227a0bdbe1079 100644 --- a/Code/Mantid/MantidPlot/CMakeLists.txt +++ b/Code/Mantid/MantidPlot/CMakeLists.txt @@ -47,6 +47,7 @@ set ( QTIPLOT_SRCS src/ApplicationWindow.cpp src/Graph3D.cpp src/Graph.cpp src/Grid.cpp + src/HelpWindow.cpp src/ImageDialog.cpp src/ImageExportDialog.cpp src/ImageMarker.cpp @@ -277,6 +278,7 @@ set ( QTIPLOT_HDRS src/ApplicationWindow.h src/Graph3D.h src/Graph.h src/Grid.h + src/HelpWindow.h src/ImageDialog.h src/ImageExportDialog.h src/ImageMarker.h diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp index 8f4a909321dc2953574b8faf09a3c8636baae67f..c63654dc3197978cd14ccca8ae9c871d7d7856b8 100644 --- a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp +++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp @@ -14606,7 +14606,9 @@ void ApplicationWindow::showMantidConcepts() } void ApplicationWindow::showalgorithmDescriptions() { - QDesktopServices::openUrl(QUrl("http://www.mantidproject.org/Category:Algorithms")); + if (!m_helpWindow) + m_helpWindow = boost::make_shared<HelpWindow>(); + m_helpWindow->showURL("qthelp://org.mantidproject/doc/html/algorithms_index.html"); } void ApplicationWindow::showSetupParaview() @@ -14630,7 +14632,9 @@ void ApplicationWindow::showFirstTimeSetup() */ void ApplicationWindow::showmantidplotHelp() { - QDesktopServices::openUrl(QUrl("http://www.mantidproject.org/MantidPlot:_Help")); + if (!m_helpWindow) + m_helpWindow = boost::make_shared<HelpWindow>(); + m_helpWindow->showURL("qthelp://org.mantidproject/doc/html/index.html"); } // diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.h b/Code/Mantid/MantidPlot/src/ApplicationWindow.h index 503e5dfaf1d03b85681d4f46a8acfca1ed5e7423..39ce4031494e9ca64d1eb126b6f8651ae8d7bce4 100644 --- a/Code/Mantid/MantidPlot/src/ApplicationWindow.h +++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.h @@ -42,6 +42,7 @@ Description : QtiPlot's main window #include <QSet> #include <QSettings> +#include "HelpWindow.h" #include "Table.h" #include "ScriptingEnv.h" #include "Scripted.h" @@ -1367,6 +1368,8 @@ private: // Flag telling if table values should be automatically recalculated when values in a column are modified. bool d_auto_update_table_values; int d_matrix_undo_stack_size; + /// Smart pointer to the help window + boost::shared_ptr<HelpWindow> m_helpWindow; /// A method to populate the CurveLayout struct on loading a project CurveLayout fillCurveSettings(const QStringList & curve, unsigned int offset = 0); diff --git a/Code/Mantid/MantidPlot/src/HelpWindow.cpp b/Code/Mantid/MantidPlot/src/HelpWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93c715b360eb532f1aac269d8874743988f1e490 --- /dev/null +++ b/Code/Mantid/MantidPlot/src/HelpWindow.cpp @@ -0,0 +1,241 @@ +#include "HelpWindow.h" +#include "MantidKernel/ConfigService.h" +#include <boost/make_shared.hpp> +#include <iostream> +#include <Poco/File.h> +#include <Poco/Path.h> +#include <QByteArray> +#include <QDesktopServices> +#include <stdexcept> +#include <strstream> + +using std::string; + +/// Base url for all of the files in the project +const string BASEURL("qthelp://org.mantidproject/doc/"); + +/** + * Default constructor. + */ +HelpWindow::HelpWindow() : + m_collectionFile(""), + m_cacheFile(""), + m_assistantExe(""), + m_log(Mantid::Kernel::Logger::get("HelpWindow")) +{ + this->determineFileLocs(); + this->start(); +} + +/// Destructor does nothing. +HelpWindow::~HelpWindow() +{ + // do nothing +} + +/** + * Have the help window show a specific url. If the url doesn't exist + * this just pops up the default view for the help. + * + * \param url The url to open. This should start with \link BASEURL. + */ +void HelpWindow::showURL(const string &url) +{ + // make sure the process is going + this->start(); + + m_log.debug() << "open help url \"" << url << "\"\n"; + string temp("setSource " + url + "\n"); + QByteArray ba; + ba.append(QLatin1String(temp.c_str())); + m_process->write(ba); +} + +/** + * Show the help page for a particular algorithm. The page is picked + * using matching naming conventions. + * + * @param name The name of the algorithm to show. + * @param version The version of the algorithm to jump do. The default + * value (-1) will show the top of the page. + */ +void HelpWindow::showAlgorithm(const string &name, const int version) +{ + // TODO jump to the version within the page + (void)version; + + string url(BASEURL + "html/Algo_" + name + ".html"); + this->showURL(url); +} + +/** + * Show the help page for a particular fit function. The page is + * picked using matching naming conventions. + * + * @param name The name of the fit function to show. + */ +void HelpWindow::showFitFunction(const std::string &name) +{ + string url(BASEURL + "html/FitFunc_" + name + ".html"); +} + +/** + * Start up the help browser in a separate process. + * + * This will only do something if the browser is not already + * running. Due to a bug in qt 4.8.1 this will delete the + * cache file every time the browser is started. + */ +void HelpWindow::start() +{ + // check if it is already started + if (this->isRunning()) + { + m_log.debug() << "helpwindow process already running\n"; + return; + } + + // see if chache file exists and remove it + if ((!m_cacheFile.empty()) && (Poco::File(m_cacheFile).exists())) + { + m_log.debug() << "Removing help cache file \"" << m_cacheFile << "\"\n"; + Poco::File(m_cacheFile).remove(); + } + + // start the process + m_process = boost::make_shared<QProcess>(); + QStringList args; + args << QLatin1String("-collectionFile") + << QLatin1String(m_collectionFile.c_str()) + << QLatin1String("-enableRemoteControl"); + m_process->start(QLatin1String(m_assistantExe.c_str()), args); + if (!m_process->waitForStarted()) + return; + m_log.debug() << m_assistantExe + << " " << args.join(QString(" ")).toStdString() + << " (state = " << m_process->state() << ")\n"; +} + +/** + * @return True if the browser is running. + */ +bool HelpWindow::isRunning() +{ + // NULL pointer definitely isn't running + if (!m_process) + return false; + + // ask the process for its state + if (m_process->state() == QProcess::NotRunning) + return false; + else + return true; +} + +/** + * Determine the location of the collection file, "mantid.qhc". This + * checks in multiple locations and can throw an exception. + * + * @param binDir The location of the mantid executable. + */ +void HelpWindow::findCollectionFile(std::string &binDir) +{ + const std::string COLLECTION("mantid.qhc"); + + // try next to the executable + Poco::Path path(binDir, COLLECTION); + m_log.debug() << "Trying \"" << path.absolute().toString() << "\"\n"; + if (Poco::File(path).exists()) + { + m_collectionFile =path.absolute().toString(); + return; + } + + // try where the builds will put it + path = Poco::Path(binDir, "qtassistant/"+COLLECTION); + m_log.debug() << "Trying \"" << path.absolute().toString() << "\"\n"; + if (Poco::File(path).exists()) + { + m_collectionFile = path.absolute().toString(); + return; + } + + // try in a good linux install location + path = Poco::Path(binDir, "../share/doc/" + COLLECTION); + m_log.debug() << "Trying \"" << path.absolute().toString() << "\"\n"; + if (Poco::File(path).exists()) + { + m_collectionFile = path.absolute().toString(); + return; + } + + // all tries have failed + std::strstream msg; + msg << "Failed to find help system collection file \"" << COLLECTION << "\""; + throw std::runtime_error(msg.str()); +} + +/** + * Determine the location of the collection and cache files. + */ +void HelpWindow::determineFileLocs() +{ + // determine collection file location + string binDir = Mantid::Kernel::ConfigService::Instance().getDirectoryOfExecutable(); + this->findCollectionFile(binDir); + m_log.debug() << "using collection file \"" << m_collectionFile << "\"\n"; + + // location for qtassistant +#ifdef __linux__ + // linux it is in system locations + m_assistantExe = "/usr/bin/assistant"; + if (!Poco::File(m_assistantExe).exists()) + { + m_log.debug() << "File \"" << m_assistantExe << "\" does not exist\n"; + m_assistantExe = "/usr/local/bin/assistant"; + if (!Poco::File(m_assistantExe).exists()) + { + m_log.debug() << "File \"" << m_assistantExe << "\" does not exist\n"; + m_assistantExe = "/usr/bin/assistant-qt4"; + if (!Poco::File(m_assistantExe).exists()) + { + m_log.debug() << "File \"" << m_assistantExe + << "\" does not exist. Assuming it is elsewhere in the path.\n"; + m_assistantExe = "assistant"; + } + } + } +#else + // windows it is next to MantidPlot + m_assistantExe = Poco::Path(binDir, "assistant").absolute().toString(); + if (!Poco::File(m_assistantExe).exists()) + { + m_log.debug() << "File \"" << m_assistantExe << "\" does not exist\n"; + } +#endif + if (Poco::File(m_assistantExe).exists()) + m_log.debug() << "Using \"" << m_assistantExe << "\" for viewing help\n"; + + // determine cache file location + m_cacheFile = "mantid.qhc"; + QString dataLoc = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + if (dataLoc.endsWith("mantidproject")) + { + Poco::Path path (dataLoc.toStdString(), m_cacheFile); + m_cacheFile = path.absolute().toString(); + } + else if (dataLoc.endsWith("MantidPlot")) // understood to end in "ISIS/MantidPlot" + { + Poco::Path path(dataLoc.toStdString()); + path = path.parent(); // drop off "MantidPlot" + path = path.parent(); // drop off "ISIS" + path = Poco::Path(path, "mantidproject"); + path = Poco::Path(path, m_cacheFile); + m_cacheFile = path.absolute().toString(); + } + else + { + m_log.debug() << "Failed to determine help cache file location\n"; // REMOVE + m_cacheFile = ""; + } +} diff --git a/Code/Mantid/MantidPlot/src/HelpWindow.h b/Code/Mantid/MantidPlot/src/HelpWindow.h new file mode 100644 index 0000000000000000000000000000000000000000..d3ee7aef87a07330141abb40706c8dee4d550e9c --- /dev/null +++ b/Code/Mantid/MantidPlot/src/HelpWindow.h @@ -0,0 +1,35 @@ +#ifndef HELPWINDOW_H +#define HELPWINDOW_H +#include <boost/shared_ptr.hpp> +#include <QProcess> +#include <string> +#include "MantidKernel/Logger.h" + +class HelpWindow +{ +public: + HelpWindow(); + virtual ~HelpWindow(); + void showURL(const std::string & url); + void showAlgorithm(const std::string &name, const int version=-1); + void showFitFunction(const std::string &name); + +private: + /// Shared pointer to the process running qt assistant. + boost::shared_ptr<QProcess> m_process; + /// The full path of the collection file. + std::string m_collectionFile; + /** The full path of the cache file. If it is not + determined this is an empty string. */ + std::string m_cacheFile; + /// QT assistant executable. + std::string m_assistantExe; + /// The logger for the class. + Mantid::Kernel::Logger& m_log; + + void start(); + bool isRunning(); + void findCollectionFile(std::string & binDir); + void determineFileLocs(); +}; +#endif // HELPWINDOW_H diff --git a/Code/Mantid/docs/CMakeLists.txt b/Code/Mantid/docs/CMakeLists.txt index f8bfeb0b33ab22b7a54787ea9eff025c0ff228f4..8e9d395e00af644298fe0f512022ea1801bf30c1 100644 --- a/Code/Mantid/docs/CMakeLists.txt +++ b/Code/Mantid/docs/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory ( qtassistant EXCLUDE_FROM_ALL ) +add_subdirectory ( qtassistant ) diff --git a/Code/Mantid/docs/qtassistant/CMakeLists.txt b/Code/Mantid/docs/qtassistant/CMakeLists.txt index ba2919bed5e5aede313cc44d4e4a643853d656a7..6d514ff56900d928e76719ce69da482cdb1ab9f1 100644 --- a/Code/Mantid/docs/qtassistant/CMakeLists.txt +++ b/Code/Mantid/docs/qtassistant/CMakeLists.txt @@ -3,54 +3,84 @@ ###################################################################### #QT_QCOLLECTIONGENERATOR_EXECUTABLE if (QT_QCOLLECTIONGENERATOR_EXECUTABLE) - message (STATUS "Adding information for qtassistant: mantid.qhc") + # set directories to follow structure of qt4 on linux + set (HELP_OUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/qtassistant) + set (HELP_QCH_DIR ${HELP_OUT_DIR}/qch) + set (HELP_HTML_DIR ${HELP_OUT_DIR}/html) + set (HELP_IMG_DIR ${HELP_OUT_DIR}/src/images) + + message (STATUS "Adding information for qtassistant") set (HELP_QHCP_SOURCE - ${CMAKE_BINARY_DIR}/qtassistant/mantid.qhcp - img/Mantid_Logo_Transparent.png - img/MantidPlot_Icon_32offset.png - src/about.txt - src/mantidgeneral.qhp + ${HELP_OUT_DIR}/mantid.qhcp + ${HELP_IMG_DIR}/Mantid_Logo_Transparent.png + ${HELP_IMG_DIR}/MantidPlot_Icon_32offset.png + ${HELP_OUT_DIR}/about.txt + ${HELP_OUT_DIR}/mantidgeneral.qhp ) - configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/mantid.qhcp.template - ${CMAKE_BINARY_DIR}/qtassistant/mantid.qhcp ) + add_custom_command( OUTPUT ${HELP_IMG_DIR}/Mantid_Logo_Transparent.png + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/img/Mantid_Logo_Transparent.png + ${HELP_IMG_DIR}/Mantid_Logo_Transparent.png + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/img/Mantid_Logo_Transparent.png ) + add_custom_command( OUTPUT ${HELP_IMG_DIR}/MantidPlot_Icon_32offset.png + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/img/MantidPlot_Icon_32offset.png + ${HELP_IMG_DIR}/MantidPlot_Icon_32offset.png + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/img/MantidPlot_Icon_32offset.png ) + add_custom_command( OUTPUT ${HELP_OUT_DIR}/mantidgeneral.qhp + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/src/mantidgeneral.qhp + ${HELP_OUT_DIR}/mantidgeneral.qhp ) + add_custom_command( OUTPUT ${HELP_OUT_DIR}/about.txt + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/src/about.txt + ${HELP_OUT_DIR}/about.txt ) + + add_custom_command( OUTPUT ${HELP_OUT_DIR}/mantid.qhcp + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/mantid.qhcp + ${HELP_OUT_DIR}/mantid.qhcp ) + + if (WIN32) # copy the assistant executable for windows 32 and 64 + add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/assistant.exe + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${THIRD_PARTY}/assistant.exe + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/assistant.exe ) + install (FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/assistant.exe + DESTINATION ${CMAKE_INSTALL_PREFIX} ) + endif (WIN32) set ( HELP_ALGO_OUT - ${CMAKE_BINARY_DIR}/qtassistant/generated/algorithms.qhp - ${CMAKE_BINARY_DIR}/qtassistant/generated/algorithms_index.html ) + ${HELP_OUT_DIR}/algorithms.qhp + ${HELP_HTML_DIR}/algorithms_index.html ) set ( HELP_FIT_OUT - ${CMAKE_BINARY_DIR}/qtassistant/generated/fitfunctions.qhp - ${CMAKE_BINARY_DIR}/qtassistant/generated/fitfunctions_index.html ) + ${HELP_OUT_DIR}/fitfunctions.qhp + ${HELP_HTML_DIR}/fitfunctions_index.html ) add_custom_command(OUTPUT ${HELP_ALGO_OUT} - DEPENDS make_algorithms_help.py qhpfile.py + DEPENDS make_algorithms_help.py qhpfile.py algorithm_help.py COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_algorithms_help.py - -m ${CMAKE_BINARY_DIR} -o ${CMAKE_BINARY_DIR}/qtassistant/generated + -m ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} -o ${HELP_OUT_DIR} ) add_custom_command(OUTPUT ${HELP_FIT_OUT} - DEPENDS make_fitfunctions_help.py qhpfile.py + DEPENDS make_fitfunctions_help.py qhpfile.py fitfunctions_help.py COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_fitfunctions_help.py - -m ${CMAKE_BINARY_DIR} -o ${CMAKE_BINARY_DIR}/qtassistant/generated + -m ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} -o ${HELP_OUT_DIR} ) - add_custom_command(OUTPUT mantid.qhc algorithms.qch mantidgeneral.qch + add_custom_command(OUTPUT ${HELP_QCH_DIR}/mantid.qhc ${HELP_QCH_DIR}/algorithms.qch ${HELP_QCH_DIR}/fitfunctions.qch ${HELP_QCH_DIR}/mantidgeneral.qch DEPENDS ${HELP_ALGO_OUT} ${HELP_FIT_OUT} ${HELP_QHCP_SOURCE} - COMMAND ${QT_QCOLLECTIONGENERATOR_EXECUTABLE} ${CMAKE_BINARY_DIR}/qtassistant/mantid.qhcp + COMMAND ${QT_QCOLLECTIONGENERATOR_EXECUTABLE} ${HELP_OUT_DIR}/mantid.qhcp ) - add_custom_target ( qtassistant - DEPENDS MantidPlot - ${CMAKE_BINARY_DIR}/qtassistant/generated/algorithms.qhp - ${CMAKE_BINARY_DIR}/qtassistant/generated/fitfunctions.qhp - mantid.qhc + add_custom_target ( qtassistant ALL + DEPENDS MantidPlot ${HELP_QCH_DIR}/mantid.qhc ) -# install ( FILES mantid.qhc algorithms.qch mantidgeneral.qch -# DESTINATION ${GUI_HELP_DEST} <- TODO define this variable -# COMPONENT help ) <- TODO define this component + set ( GUI_HELP_DEST share/doc ) + + install ( DIRECTORY ${HELP_QCH_DIR} ${HELP_HTML_DIR} ${HELP_IMG_DIR} + DESTINATION ${GUI_HELP_DEST} ) + install (FILES ${HELP_OUT_DIR}/mantid.qhc + DESTINATION ${GUI_HELP_DEST} ) else (QT_QCOLLECTIONGENERATOR_EXECUTABLE) - message (status " Did not find QCOLLECTIONGENERATOR - cannot create qtassistant files") + message (FATAL_ERROR " Did not find qcollectiongenerator - cannot create qtassistant files") endif() diff --git a/Code/Mantid/docs/qtassistant/algorithm_help.py b/Code/Mantid/docs/qtassistant/algorithm_help.py index fa3d0041336c6b609ff0beec4aea642d69947b50..2d9f33ce2d89945f67ecdadbe3edb0edd73a924a 100644 --- a/Code/Mantid/docs/qtassistant/algorithm_help.py +++ b/Code/Mantid/docs/qtassistant/algorithm_help.py @@ -1,14 +1,13 @@ -from lxml import etree as le # python-lxml on rpm based systems -import lxml.html -from lxml.html import builder as lhbuilder import os +from xml.dom.minidom import Document +from assistant_common import WEB_BASE, HTML_DIR, addEle, addTxtEle DIRECTION = { 0:"input", 1:"output", 2:"input/output" } -WEB_BASE = "http://www.mantidproject.org/" +from assistant_common import WEB_BASE, HTML_DIR def make_wiki(algo_name, version, latest_version): """ Return wiki text for a given algorithm @@ -115,14 +114,15 @@ def typeStr(property): return "double" return propType -def propToHtml(table, property, number): - row = le.SubElement(table, "tr") - row.append(lhbuilder.TD(str(number+1))) - row.append(lhbuilder.TD(property.name)) - row.append(lhbuilder.TD(DIRECTION[property.direction])) - row.append(lhbuilder.TD(typeStr(property))) - row.append(lhbuilder.TD('???')) # default - row.append(lhbuilder.TD(property.documentation)) +def propToHtml(doc, table, property, number): + # wiki_maker does this better + row = addEle(doc, "tr", table) + addTxtEle(doc, "td", str(number+1), row) + addTxtEle(doc, "td", property.name, row) + addTxtEle(doc, "td", DIRECTION[property.direction], row) + addTxtEle(doc, "td", typeStr(property), row) + addTxtEle(doc, "td", '???', row) + addTxtEle(doc, "td", property.documentation, row) """ property methods ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'allowedValues', 'direction', 'documentation', 'getGroup', 'isDefault', 'isValid', 'name', 'units', 'value', 'valueAsStr'] """ @@ -133,57 +133,57 @@ def process_algorithm(name, versions, qhp, outputdir, **kwargs): # was (args, al versions = list(versions) versions.reverse() - root = le.Element("html") - head = le.SubElement(root, "head") - head.append(lhbuilder.META(lhbuilder.TITLE(name))) - body = le.SubElement(root, "body") - body.append(lhbuilder.CENTER(lhbuilder.H1(name))) - text = '<a href="%s">wiki help</a>' % (WEB_BASE+name) - body.append(lxml.html.fragment_fromstring(text)) - body.append(lhbuilder.HR()) + doc = Document() + root = addEle(doc, "html", doc) + head = addEle(doc, "head", root) + addTxtEle(doc, "title", name, head) + body = addEle(doc, "body", root) + temp = addEle(doc, "center", body) + addTxtEle(doc, "h1", name, temp) + addTxtEle(doc, "a", "wiki help", body, {"href":WEB_BASE+name}) + addEle(doc, "hr", body) + num_versions = len(versions) for version in versions: - section = le.SubElement(body, "div", **{"id":"version_"+str(version)}) + section = addEle(doc, "div", body, {"id":"version_"+str(version)}) if num_versions > 0: - section.append(lhbuilder.H2("Version %d" % version)) + addTxtEle(doc, "h2", "Version %d" % version, section) alg = mantid.FrameworkManager.createAlgorithm(name, version) - section.append(lhbuilder.H3("Summary")) - section.append(lhbuilder.P(alg.getWikiSummary())) - - section.append(lhbuilder.H3("Properties")) - table = le.SubElement(section, "table", - **{"border":"1", "cellpadding":"5", "cellspacing":"0"}) - header_row = le.SubElement(table, "tr") - header_row.append(lhbuilder.TH("Order")) - header_row.append(lhbuilder.TH("Name")) - header_row.append(lhbuilder.TH("Direction")) - header_row.append(lhbuilder.TH("Type")) - header_row.append(lhbuilder.TH("Default")) - header_row.append(lhbuilder.TH("Description")) + addTxtEle(doc, "h3", "Summary", section) + addTxtEle(doc, "p", alg.getWikiSummary(), section) + + addTxtEle(doc, "h3", "Properties", section) + table = addEle(doc, "table", section, {"border":"1", "cellpadding":"5", "cellspacing":"0"}) + header_row = addEle(doc, "tr", table) + addTxtEle(doc, "th", "Order", header_row) + addTxtEle(doc, "th", "Name", header_row) + addTxtEle(doc, "th", "Direction", header_row) + addTxtEle(doc, "th", "Type", header_row) + addTxtEle(doc, "th", "Default", header_row) + addTxtEle(doc, "th", "Description", header_row) properties = alg.getProperties() mandatory = alg.mandatoryProperties() for (i, property) in zip(range(len(properties)), properties): - propToHtml(table, property, i) + propToHtml(doc, table, property, i) - section.append(lhbuilder.H3("Description")) - section.append(lhbuilder.P(alg.getWikiDescription())) + addTxtEle(doc, "h3", "Description", section) + addTxtEle(doc, "p", alg.getWikiDescription(), section) """ algorithm methods ['__class__', '__contains__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'alias', 'categories', 'category', 'docString', 'execute', 'existsProperty', 'getOptionalMessage', 'getProperties', 'getProperty', 'getPropertyValue', 'getWikiDescription', 'getWikiSummary', 'initialize', 'isChild', 'isExecuted', 'isInitialized', 'mandatoryProperties', 'name', 'orderedProperties', 'outputProperties', 'propertyCount', 'setAlwaysStoreInADS', 'setChild', 'setLogging', 'setProperty', 'setPropertyValue', 'setRethrows', 'version'] """ if version > 1: - body.append(lhbuilder.HR()) + addEle(doc, "hr", body) - # write out the fiel + # write out the file outfile = "Algo_%s.html" % (name) - qhp.addFile(outfile, name) + qhp.addFile(os.path.join(HTML_DIR, outfile), name) outfile = os.path.join(outputdir, outfile) handle = open(outfile, 'w') - handle.write(le.tostring(root, pretty_print=True, - xml_declaration=False)) + handle.write(doc.toprettyxml(indent=" ", encoding="utf-8")) """ Do the wiki page diff --git a/Code/Mantid/docs/qtassistant/assistant_common.py b/Code/Mantid/docs/qtassistant/assistant_common.py new file mode 100644 index 0000000000000000000000000000000000000000..e24836fffd875d4629001456999fd6b8da865bd4 --- /dev/null +++ b/Code/Mantid/docs/qtassistant/assistant_common.py @@ -0,0 +1,49 @@ +HTML_DIR = "html" +QCH_DIR = "qch" +IMG_DIR = "src/images" +WEB_BASE = "http://www.mantidproject.org/" + +def getParser(description): + import optparse + parser = optparse.OptionParser(description=description) + defaultmantidpath = "" + parser.add_option('-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) + parser.add_option('-o', '--output', dest='helpoutdir', + help="Full path to where the output files should go.") + return parser + +def assertDirs(outputdir, verbose=False): + import os + + for direc in (HTML_DIR, QCH_DIR, IMG_DIR): + direc = os.path.join(outputdir, direc) + direc = os.path.abspath(direc) + if not os.path.exists(direc): + if verbose: + print "creating '%s'" % direc + try: + os.makedirs(direc) + except OSError, e: + # EEXIST says that the file already exists + if e.errno != os.errno.EEXIST: + raise e + +def addEle(doc, tag, parent=None, attrs={}): + """Assumes that the 'doc' that comes in is a xml.dom.minidom.Document + """ + ele = doc.createElement(tag) + for key in attrs.keys(): + ele.setAttribute(key, attrs[key]) + if parent is not None: + parent.appendChild(ele) + return ele + +def addTxtEle(doc, tag, text, parent=None, attrs={}): + """Assumes that the 'doc' that comes in is a xml.dom.minidom.Document + """ + ele = addEle(doc, tag, parent, attrs) + text = doc.createTextNode(text) + ele.appendChild(text) + return ele diff --git a/Code/Mantid/docs/qtassistant/fitfunctions_help.py b/Code/Mantid/docs/qtassistant/fitfunctions_help.py index b69d5b05541c2c8c7884b653f7f932468285c5c7..fffb7dbeff047953ea22c38d7bda36c622e48f4c 100644 --- a/Code/Mantid/docs/qtassistant/fitfunctions_help.py +++ b/Code/Mantid/docs/qtassistant/fitfunctions_help.py @@ -1,60 +1,58 @@ -from lxml import etree as le # python-lxml on rpm based systems -import lxml.html -from lxml.html import builder as lhbuilder import os - -WEB_BASE = "http://www.mantidproject.org/" +from xml.dom.minidom import Document +from assistant_common import WEB_BASE, HTML_DIR, addEle, addTxtEle def process_function(name, qhp, outputdir, **kwargs): # was (args, algo): import mantid.api func = mantid.api.FunctionFactory.createFunction(name) #print "***", func, dir(func) - root = le.Element("html") - head = le.SubElement(root, "head") - head.append(lhbuilder.META(lhbuilder.TITLE(name + " Fit Function"))) - body = le.SubElement(root, "body") - body.append(lhbuilder.CENTER(lhbuilder.H1(name + " Fit Function"))) - text = '<a href="%s">wiki help</a>' % (WEB_BASE+name) - body.append(lxml.html.fragment_fromstring(text)) - body.append(lhbuilder.HR()) - - body.append(lhbuilder.H3("Summary")) - + doc = Document() + root = addEle(doc, "html", doc) + head = addEle(doc, "head", root) + addTxtEle(doc, "title", name + " Fit Function", head) + body = addEle(doc, "body", root) + temp = addEle(doc, "center", body) + addTxtEle(doc, "h1", name + " Fit Function", temp) + addTxtEle(doc, "a", "wiki help", body, {"href":WEB_BASE+name}) + addEle(doc, "hr", body) + addTxtEle(doc, "h3", "Summary", body) if func.numParams() <= 0: - body.append(lhbuilder.H3("No Parameters")) + addTxtEle(doc, "h3", "No Parameters", body) else: - body.append(lhbuilder.H3("Parameters")) - table = le.SubElement(body, "table", - **{"border":"1", "cellpadding":"5", "cellspacing":"0"}) - header_row = le.SubElement(table, "tr") - header_row.append(lhbuilder.TH("Order")) - header_row.append(lhbuilder.TH("Name")) - header_row.append(lhbuilder.TH("Default")) - header_row.append(lhbuilder.TH("Explicit")) - header_row.append(lhbuilder.TH("Description")) + addTxtEle(doc, "h3", "Parameters", body) + table = addEle(doc, "table", body, {"border":"1", "cellpadding":"5", "cellspacing":"0"}) + header_row = addEle(doc, "tr", table) + addTxtEle(doc, "th", "Order", header_row) + addTxtEle(doc, "th", "Name", header_row) + addTxtEle(doc, "th", "Default", header_row) + addTxtEle(doc, "th", "Explicit", header_row) + addTxtEle(doc, "th", "Description", header_row) for number in range(func.numParams()): - row = le.SubElement(table, "tr") - row.append(lhbuilder.TD(str(number+1))) - row.append(lhbuilder.TD(func.getParamName(number))) - row.append(lhbuilder.TD(str(func.getParamValue(number)))) - row.append(lhbuilder.TD(str(func.getParamExplicit(number)))) + row = addEle(doc, "tr", table) + addTxtEle(doc, "td", str(number+1), row) + addTxtEle(doc, "td", func.getParamName(number), row) + addTxtEle(doc, "td", str(func.getParamValue(number)), row) + addTxtEle(doc, "td", str(func.getParamExplicit(number)), row) descr = func.getParamDescr(number) if len(descr) <= 0: - descr = u'\u00a0' # hack to create r' ' - row.append(lhbuilder.TD(descr)) + # u"\u00A0".encode('utf-16') # hack to create r' ' + descr = " " # should be   + addTxtEle(doc, "td", descr, row) cats = [] for category in func.categories(): - cats.append('<a href="fitfunctions_index.html#%s">%s</a>' % (category, category)) + ref = "fitfunctions_index.html#%s" % (category) + cats.append(addTxtEle(doc, "a", category, attrs={"href":ref})) if len(cats) > 0: - text = '<p><b>Categories:</b> ' + " ".join(cats) + '</p>' - body.append(lxml.html.fragment_fromstring(text)) + p = addEle(doc, "p", body) + addTxtEle(doc, "b", "Categories:", p) + for category in cats: + p.appendChild(category) # write out the file outfile = "FitFunc_%s.html" % name - qhp.addFile(outfile, name) + qhp.addFile(os.path.join(HTML_DIR, outfile), name) outfile = os.path.join(outputdir, outfile) handle = open(outfile, 'w') - handle.write(le.tostring(root, pretty_print=True, - xml_declaration=False)) + handle.write(doc.toprettyxml(indent=" ", encoding='utf-8')) diff --git a/Code/Mantid/docs/qtassistant/make_algorithms_help.py b/Code/Mantid/docs/qtassistant/make_algorithms_help.py index 14f56e16df44b58ba6d95c2097a4e1ea53f744aa..24cd9fdaa44134f2b0705936b0a8c00f54cd407c 100755 --- a/Code/Mantid/docs/qtassistant/make_algorithms_help.py +++ b/Code/Mantid/docs/qtassistant/make_algorithms_help.py @@ -1,15 +1,10 @@ #!/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 +from xml.dom.minidom import Document import os from qhpfile import QHPFile from string import split,join import sys - -OUTPUTDIR = "generated" -WEB_BASE = "http://www.mantidproject.org/" +from assistant_common import * def addWikiDir(helpsrcdir): """ @@ -19,25 +14,42 @@ def addWikiDir(helpsrcdir): wikitoolsloc = os.path.abspath(wikitoolsloc) sys.path.append(wikitoolsloc) -def genCatElement(category): +def addLetterIndex(doc, div, letters): + para = addEle(doc, "p", div) + for letter in map(chr, range(65, 91)): + if letter in letters: + addTxtEle(doc, "a", letter, para, {"href":'#algo%s' % letter}) + text = doc.createTextNode(" ") + para.appendChild(text) + else: + text = doc.createTextNode(letter+" ") + para.appendChild(text) + + +def appendCatElement(doc, ul, category): category = category.split('/') - text = "<li>" filename = 'AlgoCat_' + category[0] + '.html' url = filename + + li = addEle(doc, "li", ul) + if len(category) > 1: - text += '/'.join(category[:-1]) + '/' + text = '/'.join(category[:-1]) + '/' url += '#' + '_'.join(category[1:]) - text += '<a href="%s">%s</a></li>' % (url, category[-1]) - return lxml.html.fragment_fromstring(text) + text = doc.createTextNode(text) + li.appendChild(text) + addTxtEle(doc, "a", category[-1], li, {"href":url}) -def genAlgoElement(name, versions): - text = '<li><a href="Algo_%s.html">%s' % (name, name) - text += ' v%d</a>' % versions[-1] +def appendAlgoElement(doc, ul, name, versions): + li = addEle(doc, "li", ul) + text = "%s v%d" % (name, versions[-1]) + addTxtEle(doc, "a", text, li, {'href':'Algo_%s.html' % (name)}) if len(versions) > 1: + text = '' text += ', ' + ', '.join(['v'+str(version) for version in versions[:-1]]) - text += '</li>' - return lxml.html.fragment_fromstring(text) + text = doc.createTextNode(text) + li.appendChild(text) def processCategories(categories, qhp, outputdir): # determine the list of html pages @@ -51,31 +63,30 @@ def processCategories(categories, qhp, outputdir): 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))) + doc = Document() + root = addEle(doc, "html", doc) + head = addEle(doc, "head", root) + addTxtEle(doc, "title", page_name + " Algorithm Category", head) + body = addEle(doc, "body", root) + temp = addEle(doc, "center", body) + addTxtEle(doc, "h1", page_name, temp) 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") + addTxtEle(doc, "h2", subcategory, body) + addEle(doc, 'a', body, {"name":anchor}) + ul = addEle(doc, "ul", body) for (name, versions) in categories[subcategory]: - ul.append(genAlgoElement(name, versions)) + appendAlgoElement(doc, ul, name, versions) filename = "AlgoCat_%s.html" % page_name - qhp.addFile(filename, page_name+" Algorithm Category") + qhp.addFile(os.path.join(HTML_DIR, filename), page_name) filename = os.path.join(outputdir, filename) handle = open(filename, 'w') - handle.write(le.tostring(root, pretty_print=True, xml_declaration=False)) + handle.write(doc.toprettyxml(indent=" ", encoding="utf-8")) def process(algos, qhp, outputdir): import mantid @@ -86,7 +97,12 @@ def process(algos, qhp, outputdir): versions = algos[name] alg = mantid.FrameworkManager.createAlgorithm(name, versions[-1]) - for category in alg.categories().split(';'): + alg_categories = alg.categories() + try: + alg_categories = alg_categories.split(';') + except AttributeError, e: + pass # the categories are already a list + for category in alg_categories: category = category.replace('\\', '/') if not categories.has_key(category): categories[category] = [] @@ -104,56 +120,49 @@ def process(algos, qhp, outputdir): letter_groups[letter].append((str(name), versions)) ##### put together the top of the html document - root = le.Element("html") - head = le.SubElement(root, "head") - head.append(lh.META(lh.TITLE("Algorithms Index"))) - body = le.SubElement(root, "body") - body.append(lh.CENTER(lh.H1("Algorithms Index"))) + doc = Document() + root = addEle(doc, "html", doc) + head = addEle(doc, "head", root) + addTxtEle(doc, "title", "Algorithms Index", head) + body = addEle(doc, "body", root) + temp = addEle(doc, "center", body) + addTxtEle(doc, "h1", "Algorithms Index", temp) ##### section for categories - div_cat = le.SubElement(body, "div", **{"id":"alg_cats"}) - div_cat.append(lh.H2("Subcategories")) + div_cat = addEle(doc, "div", body, {"id":"alg_cats"}) + addTxtEle(doc, "h2", "Subcategories", div_cat) above = None - ul = le.SubElement(div_cat, "ul") + ul = addEle(doc, "ul", div_cat) for category in categories_list: - ul.append(genCatElement(category)) + appendCatElement(doc, ul, category) ##### section for alphabetical - div_alpha = le.SubElement(body, "div", **{"id":"alg_alpha"}) - div_alpha.append(lh.H2("Alphabetical")) + div_alpha = addEle(doc, "div", body, {"id":"alg_alpha"}) + addTxtEle(doc, "h2", "Alphabetical", div_alpha) letters = letter_groups.keys() letters.sort() # print an index within the page - para_text = "<p>" - for letter in map(chr, range(65, 91)): - if letter in letters: - para_text += "<a href='#algo%s'>%s</a> " % (letter, letter) - else: - para_text += letter + ' ' - para_text += "</p>" - div_alpha.append( lxml.html.fragment_fromstring(para_text)) + addLetterIndex(doc, div_alpha, letters) # print the list of algorithms by name for letter in letters: - temp = le.SubElement(div_alpha, 'h3') - le.SubElement(temp, 'a', **{"name":'algo'+letter}) - temp.text = letter - - ul = le.SubElement(div_alpha, "ul") + addTxtEle(doc, 'h3', letter, div_alpha) + addEle(doc, 'a', div_alpha, {"name":'algo'+letter}) + ul = addEle(doc, "ul", div_alpha) for (name, versions) in letter_groups[letter]: - ul.append(genAlgoElement(name, versions)) + appendAlgoElement(doc, ul, name, versions) # print an index within the page - div_alpha.append( lxml.html.fragment_fromstring(para_text)) + addLetterIndex(doc, div_alpha, letters) filename = os.path.join(outputdir, "algorithms_index.html") handle = open(filename, 'w') - handle.write(le.tostring(root, pretty_print=True, xml_declaration=False)) + handle.write(doc.toprettyxml(indent=" ", encoding="utf-8")) shortname = os.path.split(filename)[1] - qhp.addFile(shortname, "Algorithms Index") + qhp.addFile(os.path.join(HTML_DIR, shortname), "Algorithms Index") # create all of the category pages processCategories(categories, qhp, outputdir) @@ -162,40 +171,30 @@ def process(algos, qhp, outputdir): from algorithm_help import process_algorithm for name in algos.keys(): versions = algos[name] - process_algorithm(name, versions, qhp, helpoutdir) + process_algorithm(name, versions, qhp, outputdir) if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Generate qtassistant docs " \ - + "for the algorithms") - 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) - parser.add_argument('-o', '--output', dest='helpoutdir', - help="Full path to where the output files should go.") - - args = parser.parse_args() + parser = getParser("Generate qtassistant docs for the algorithms") + (options, args) = parser.parse_args() # where to put the generated files helpsrcdir = os.path.dirname(os.path.abspath(__file__)) - if args.helpoutdir is not None: - helpoutdir = os.path.abspath(args.helpoutdir) + if options.helpoutdir is not None: + helpoutdir = os.path.abspath(options.helpoutdir) else: - helpoutdir = os.path.join(helpsrcdir, OUTPUTDIR) + raise RuntimeError("need to specify output directory") print "Writing algorithm web pages to '%s'" % helpoutdir - if not os.path.exists(helpoutdir): - os.makedirs(helpoutdir) + assertDirs(helpoutdir) addWikiDir(helpsrcdir) # initialize mantid - if not args.mantidpath.endswith("bin"): - args.mantidpath = os.path.join(args.mantidpath, "bin") - sys.path.append(args.mantidpath) + sys.path.append(options.mantidpath) + os.environ['MANTIDPATH'] = options.mantidpath import mantid.api algos = mantid.api.AlgorithmFactory.getRegisteredAlgorithms(True) # setup the qhp file qhp = QHPFile("org.mantidproject.algorithms") - process(algos, qhp, helpoutdir) + process(algos, qhp, os.path.join(helpoutdir, HTML_DIR)) qhp.write(os.path.join(helpoutdir, "algorithms.qhp")) diff --git a/Code/Mantid/docs/qtassistant/make_fitfunctions_help.py b/Code/Mantid/docs/qtassistant/make_fitfunctions_help.py index 78d67ecc44006458036c5450e1715a10cab8c490..8f66386f5df30225069a64e01523846c50b905dd 100755 --- a/Code/Mantid/docs/qtassistant/make_fitfunctions_help.py +++ b/Code/Mantid/docs/qtassistant/make_fitfunctions_help.py @@ -1,15 +1,10 @@ #!/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 +from xml.dom.minidom import Document import os from qhpfile import QHPFile from string import split,join import sys - -OUTPUTDIR = "generated" -WEB_BASE = "http://www.mantidproject.org/" +from assistant_common import * def addWikiDir(helpsrcdir): """ @@ -19,48 +14,9 @@ def addWikiDir(helpsrcdir): wikitoolsloc = os.path.abspath(wikitoolsloc) sys.path.append(wikitoolsloc) -def genFuncElement(name): - text = '<a href="FitFunc_%s.html">%s</a>' % (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 appendFuncElement(doc, div, name): + li = addEle(doc, "li", div) + addTxtEle(doc, "a", name, li, {"href":"FitFunc_%s.html" % name}) def process(functions, qhp, outputdir): import mantid.api @@ -78,67 +34,58 @@ def process(functions, qhp, outputdir): 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"))) + doc = Document() + root = addEle(doc, "html", doc) + head = addEle(doc, "head", root) + addTxtEle(doc, "title", "Fit Functions Index", head) + body = addEle(doc, "body", root) + temp = addEle(doc, "center", body) + addTxtEle(doc, "h1", "Fit Functions Index", temp) ##### section for categories - div_cat = le.SubElement(body, "div", **{"id":"function_cats"}) + div_cat = addEle(doc, "div", body, {"id":"function_cats"}) for category in categories_list: - temp = le.SubElement(div_cat, "h2") - le.SubElement(temp, 'a', **{"name":category}) - temp.text = category + " Category" - ul = le.SubElement(div_cat, "ul") + addTxtEle(doc, "h2", category + " Category", div_cat) + addEle(doc, "a", div_cat, {"name":category}) + ul = addEle(doc, "ul", div_cat) funcs = categories[category] for func in funcs: - li = le.SubElement(ul, "li") - li.append(genFuncElement(func)) + appendFuncElement(doc, ul, func) filename = os.path.join(outputdir, "fitfunctions_index.html") handle = open(filename, 'w') - handle.write(le.tostring(root, pretty_print=True, xml_declaration=False)) + handle.write(doc.toprettyxml(indent=" ", encoding="utf-8")) shortname = os.path.split(filename)[1] - qhp.addFile(shortname, "Fit Functions Index") + qhp.addFile(os.path.join(HTML_DIR, shortname), "Fit Functions Index") # create individual html pages from fitfunctions_help import process_function for func in functions: - process_function(func, qhp, helpoutdir) + process_function(func, qhp, outputdir) 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) - parser.add_argument('-o', '--output', dest='helpoutdir', - help="Full path to where the output files should go.") - - args = parser.parse_args() + parser = getParser("Generate qtassistant docs for the fit functions") + (options, args) = parser.parse_args() # where to put the generated files helpsrcdir = os.path.dirname(os.path.abspath(__file__)) - if args.helpoutdir is not None: - helpoutdir = os.path.abspath(args.helpoutdir) + if options.helpoutdir is not None: + helpoutdir = os.path.abspath(options.helpoutdir) else: - helpoutdir = os.path.join(helpsrcdir, OUTPUTDIR) + raise RuntimeError("need to specify output directory") print "Writing fit function web pages to '%s'" % helpoutdir - if not os.path.exists(helpoutdir): - os.makedirs(helpoutdir) + assertDirs(helpoutdir) addWikiDir(helpsrcdir) # initialize mantid - import wiki_tools - wiki_tools.initialize_Mantid(args.mantidpath) + sys.path.append(options.mantidpath) + os.environ['MANTIDPATH'] = options.mantidpath import mantid.api functions = mantid.api.FunctionFactory.getFunctionNames() # setup the qhp file qhp = QHPFile("org.mantidproject.fitfunctions") - process(functions, qhp, helpoutdir) + process(functions, qhp, os.path.join(helpoutdir, HTML_DIR)) qhp.write(os.path.join(helpoutdir, "fitfunctions.qhp")) diff --git a/Code/Mantid/docs/qtassistant/mantid.qhcp b/Code/Mantid/docs/qtassistant/mantid.qhcp new file mode 100644 index 0000000000000000000000000000000000000000..2e8b3610205b25835029662ffeb6f2b9717a323f --- /dev/null +++ b/Code/Mantid/docs/qtassistant/mantid.qhcp @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8" ?> +<QHelpCollectionProject version="1.0"> + <assistant> + <title>Mantid Help</title> + <startPage>qthelp://org.mantidproject/doc/html/index.html</startPage> + <applicationIcon>src/images/MantidPlot_Icon_32offset.png</applicationIcon> + <enableFilterFunctionality>false</enableFilterFunctionality> + <enableDocumentationManager>true</enableDocumentationManager> + <enableAddressBar visible="false">true</enableAddressBar> + <cacheDirectory>mantidproject</cacheDirectory> + <aboutMenuText> + <text>About Mantid</text> + </aboutMenuText> + <aboutDialog> + <file>about.txt</file> + <icon>src/images/Mantid_Logo_Transparent.png</icon> + </aboutDialog> + </assistant> + <docFiles> + <generate> + <file> + <input>mantidgeneral.qhp</input> + <output>qch/mantidgeneral.qch</output> + </file> + <file> + <input>algorithms.qhp</input> + <output>qch/algorithms.qch</output> + </file> + <file> + <input>fitfunctions.qhp</input> + <output>qch/fitfunctions.qch</output> + </file> + </generate> + <register> + <file>qch/mantidgeneral.qch</file> + <file>qch/algorithms.qch</file> + <file>qch/fitfunctions.qch</file> + </register> + </docFiles> +</QHelpCollectionProject> diff --git a/Code/Mantid/docs/qtassistant/mantid.qhcp.template b/Code/Mantid/docs/qtassistant/mantid.qhcp.template deleted file mode 100644 index e326a2769ac0991b7f3d9b671c7c9ed4a5feddc9..0000000000000000000000000000000000000000 --- a/Code/Mantid/docs/qtassistant/mantid.qhcp.template +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<QHelpCollectionProject version="1.0"> - <assistant> - <title>Mantid Help</title> - <startPage>qthelp://org.mantidproject/doc/index.html</startPage> - <applicationIcon>@CMAKE_CURRENT_SOURCE_DIR@/img/MantidPlot_Icon_32offset.png</applicationIcon> - <enableFilterFunctionality>false</enableFilterFunctionality> - <enableDocumentationManager>true</enableDocumentationManager> - <enableAddressBar visible="true">false</enableAddressBar> - <cacheDirectory>mantidproject</cacheDirectory> - <aboutMenuText> - <text>About Mantid</text> - </aboutMenuText> - <aboutDialog> - <file>@CMAKE_CURRENT_SOURCE_DIR@/src/about.txt</file> - <icon>@CMAKE_CURRENT_SOURCE_DIR@/img/Mantid_Logo_Transparent.png</icon> - </aboutDialog> - </assistant> - <docFiles> - <generate> - <file> - <input>@CMAKE_CURRENT_SOURCE_DIR@/src/mantidgeneral.qhp</input> - <output>mantidgeneral.qch</output> - </file> - <file> - <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> diff --git a/Code/Mantid/docs/qtassistant/qhpfile.py b/Code/Mantid/docs/qtassistant/qhpfile.py index 3e81b06e9be98d6d2d63caa26ffe8488f94994c2..0202f25d40fdea885aac4fca0e668cc4af3a9beb 100755 --- a/Code/Mantid/docs/qtassistant/qhpfile.py +++ b/Code/Mantid/docs/qtassistant/qhpfile.py @@ -1,21 +1,19 @@ #!/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/" +from xml.dom.minidom import Document +from assistant_common import addEle, addTxtEle class QHPFile: - def __init__(self, namespace, folder="doc"): - self.__root = le.Element("QtHelpProject", - **{"version":"1.0"}) + def __init__(self, namespace, folder="doc", prettyxml=False): + self.__doc = Document() + self.__root = addEle(self.__doc,"QtHelpProject", self.__doc, + {"version":"1.0"}) + self.__prettyxml = prettyxml + + addTxtEle(self.__doc, "namespace", namespace, self.__root) + addTxtEle(self.__doc, "virtualFolder", folder, self.__root) - self.__addtxtele(self.__root, "namespace", namespace) - self.__addtxtele(self.__root, "virtualFolder", folder) - self.__filterSect = le.SubElement(self.__root, "filterSection") + self.__filterSect = addEle(self.__doc, "filterSection", self.__root) self.__keywordsEle = None # should have 'keywords' section self.__keywords = [] @@ -35,25 +33,23 @@ class QHPFile: def addFile(self, filename, keyword=None): if not keyword is None: if self.__keywordsEle is None: - self.__keywordsEle = le.SubElement(self.__filterSect, "keywords") + self.__keywordsEle = addEle(self.__doc, "keywords", + self.__filterSect) if not keyword in self.__keywords: - le.SubElement(self.__keywordsEle, "keyword", - **{"name":keyword, "ref":os.path.split(filename)[1]}) + addEle(self.__doc, "keyword", self.__keywordsEle, + {"name":keyword, "ref":filename}) self.__keywords.append(keyword) if self.__filesEle is None: - self.__filesEle = le.SubElement(self.__filterSect, "files") + self.__filesEle = addEle(self.__doc, "files", self.__filterSect) if not filename in self.__files: - self.__addtxtele(self.__filesEle, "file", filename) + addTxtEle(self.__doc, "file", filename, self.__filesEle) 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) + if self.__prettyxml: + return self.__doc.toprettyxml(indent=" ") + else: + return self.__doc.toxml() def write(self, filename): """ diff --git a/Code/Mantid/docs/qtassistant/src/mantidgeneral.qhp b/Code/Mantid/docs/qtassistant/src/mantidgeneral.qhp index 184f00d635ce446caccdd1d9d4d8bb6f472de500..1c78b31f51795468c0097f69f4c44407aa304b95 100644 --- a/Code/Mantid/docs/qtassistant/src/mantidgeneral.qhp +++ b/Code/Mantid/docs/qtassistant/src/mantidgeneral.qhp @@ -4,14 +4,14 @@ <virtualFolder>doc</virtualFolder> <filterSection> <toc> - <section title="Mantid overview" ref="index.html"/> - <section title="MantidPlot" ref="./mantidplot.html"> - <section title="User Interfaces" ref="./userui.html"/> - <section title="Algorithms" ref="algorithms_index.html"/> - <section title="Fitting Functions" ref="fitfunctions_index.html"/> + <section title="Mantid overview" ref="html/index.html"/> + <section title="MantidPlot" ref="html/mantidplot.html"> + <section title="User Interfaces" ref="html/userui.html"/> + <section title="Algorithms" ref="html/algorithms_index.html"/> + <section title="Fitting Functions" ref="html/fitfunctions_index.html"/> </section> - <section title="Mantid Python" ref="./mantidpython.html"/> - <section title="Developer information" ref="./developers.html"/> + <section title="Mantid Python" ref="html/mantidpython.html"/> + <section title="Developer information" ref="html/developers.html"/> </toc> <!-- <keywords>