view tasks/task_generate_doc.py @ 3:b7e8db97b3b0

presentation: added installation section, with links to Flatpak and Android packages
author Goffi <goffi@goffi.org>
date Fri, 28 Jun 2019 17:12:40 +0200
parents 09d66acc7c73
children 9ce41ef66dfa
line wrap: on
line source

#!/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"))