annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/ur/bin/env python2
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 import os.path
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from twisted.internet import defer
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import _
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.tools.common import regex
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 log = getLogger(__name__)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 WATCH_DIRS = []
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 DOC_DIRS_DEFAULT = (u'doc', u'docs')
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 def prepare(self):
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 to_watch = set()
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 doc_path = self.getConfig("doc_path")
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 if doc_path is not None:
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 to_watch.add(doc_path)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 sub_docs = self.getConfig("sub_docs_dict", value_type=u"path")
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 if sub_docs is not None:
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 for d in sub_docs.values():
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 to_watch.add(d)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 global WATCH_DIRS
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 WATCH_DIRS = list(to_watch)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 @defer.inlineCallbacks
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 def start(self):
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 # root documentation
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 doc_path = self.getConfig("doc_path")
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 # sub docs will be generated before the root documentation
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 sub_docs = self.getConfig("sub_docs_dict", value_type=u"path")
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 if doc_path is None:
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 # we check if there is documentation inside the site
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 for dirname in DOC_DIRS_DEFAULT:
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 path = os.path.join(self.site_path, dirname)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 conf_file = os.path.join(path, 'conf.py')
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 if os.path.isdir(path) and os.path.exists(conf_file):
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 doc_path = path
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 break
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 if doc_path is None and sub_docs is None:
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 log.info(u"No documentation found for {site_name}, skipping".format(
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 site_name = self.site_name))
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 return
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 sphinx = self.findCommand('sphinx-build2', 'sphinx-build')
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 # we first generate the sub documentations
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 for name, sub_doc_path in sub_docs.iteritems():
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 sub_dir = regex.pathEscape(name or u'')
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 build_path = os.path.join(self.build_path, u'doc', sub_dir)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 yield self.runCommand(sphinx, sub_doc_path, build_path)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 # then the root one
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 if doc_path is not None:
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 build_path = os.path.join(self.build_path, u'doc')
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 yield self.runCommand(sphinx, doc_path, build_path)
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 log.info(_(u"documentation has been generated"))