diff tasks/task_generate_doc.py @ 0:09d66acc7c73

initial commit, website first draft: - presentation page - documentation (generated from backend and Libervia) - social contract (HTML generated from sat repository) - press/conferences (adapted from former website) - association page (adpated from former website) - news (a selected blog is displayed) - fr i18n
author Goffi <goffi@goffi.org>
date Sun, 26 May 2019 22:26:30 +0200
parents
children 9ce41ef66dfa
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tasks/task_generate_doc.py	Sun May 26 22:26:30 2019 +0200
@@ -0,0 +1,61 @@
+#!/ur/bin/env python2
+
+import os.path
+from twisted.internet import defer
+from sat.core.i18n import _
+from sat.core.log import getLogger
+from sat.tools.common import regex
+log = getLogger(__name__)
+
+WATCH_DIRS = []
+DOC_DIRS_DEFAULT = (u'doc', u'docs')
+
+
+def prepare(self):
+    to_watch = set()
+    doc_path = self.getConfig("doc_path")
+    if doc_path is not None:
+        to_watch.add(doc_path)
+    sub_docs = self.getConfig("sub_docs_dict", value_type=u"path")
+    if sub_docs is not None:
+        for d in sub_docs.values():
+            to_watch.add(d)
+    global WATCH_DIRS
+    WATCH_DIRS = list(to_watch)
+
+
+@defer.inlineCallbacks
+def start(self):
+    # root documentation
+    doc_path = self.getConfig("doc_path")
+    # sub docs will be generated before the root documentation
+    sub_docs = self.getConfig("sub_docs_dict", value_type=u"path")
+
+    if doc_path is None:
+        # we check if there is documentation inside the site
+        for dirname in DOC_DIRS_DEFAULT:
+            path = os.path.join(self.site_path, dirname)
+            conf_file = os.path.join(path, 'conf.py')
+            if os.path.isdir(path) and os.path.exists(conf_file):
+                doc_path = path
+                break
+
+    if doc_path is None and sub_docs is None:
+        log.info(u"No documentation found for {site_name}, skipping".format(
+            site_name = self.site_name))
+        return
+
+    sphinx = self.findCommand('sphinx-build2', 'sphinx-build')
+
+    # we first generate the sub documentations
+    for name, sub_doc_path in sub_docs.iteritems():
+        sub_dir = regex.pathEscape(name or u'')
+        build_path = os.path.join(self.build_path, u'doc', sub_dir)
+        yield self.runCommand(sphinx, sub_doc_path, build_path)
+
+    # then the root one
+    if doc_path is not None:
+        build_path = os.path.join(self.build_path, u'doc')
+        yield self.runCommand(sphinx, doc_path, build_path)
+
+    log.info(_(u"documentation has been generated"))