Mercurial > libervia-website
comparison tasks/task_generate_doc.py @ 7:b5fc67c97c50
tasks: updated tasks following changes in Libervia
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 26 May 2020 12:38:56 +0200 |
parents | 9ce41ef66dfa |
children | a24d362796be |
comparison
equal
deleted
inserted
replaced
6:9ce41ef66dfa | 7:b5fc67c97c50 |
---|---|
1 #!/ur/bin/env python3 | 1 #!/ur/bin/env python3 |
2 | 2 |
3 import os.path | 3 import os.path |
4 from twisted.internet import defer | |
5 from sat.core.i18n import _ | 4 from sat.core.i18n import _ |
6 from sat.core.log import getLogger | 5 from sat.core.log import getLogger |
7 from sat.tools.common import regex | 6 from sat.tools.common import regex |
7 from libervia.server.tasks import task | |
8 | |
9 | |
8 log = getLogger(__name__) | 10 log = getLogger(__name__) |
9 | 11 |
10 WATCH_DIRS = [] | |
11 DOC_DIRS_DEFAULT = ('doc', 'docs') | |
12 | 12 |
13 class Task(task.Task): | |
14 DOC_DIRS_DEFAULT = ('doc', 'docs') | |
13 | 15 |
14 def prepare(self): | 16 def prepare(self): |
15 to_watch = set() | 17 to_watch = set() |
16 doc_path = self.getConfig("doc_path") | 18 # root documentation |
17 if doc_path is not None: | 19 self.doc_path = self.getConfig("doc_path") |
18 to_watch.add(doc_path) | 20 if self.doc_path is not None: |
19 sub_docs = self.getConfig("sub_docs_dict", value_type="path") | 21 to_watch.add(self.doc_path) |
20 if sub_docs is not None: | 22 # sub docs will be generated before the root documentation |
21 for d in list(sub_docs.values()): | 23 self.sub_docs = self.getConfig("sub_docs_dict", value_type="path") |
22 to_watch.add(d) | 24 if self.sub_docs is not None: |
23 global WATCH_DIRS | 25 for d in list(self.sub_docs.values()): |
24 WATCH_DIRS = list(to_watch) | 26 to_watch.add(d) |
27 self.WATCH_DIRS = list(to_watch) | |
25 | 28 |
29 async def start(self): | |
30 if self.doc_path is None: | |
31 # we check if there is documentation inside the site | |
32 for dirname in self.DOC_DIRS_DEFAULT: | |
33 path = os.path.join(self.site_path, dirname) | |
34 conf_file = os.path.join(path, 'conf.py') | |
35 if os.path.isdir(path) and os.path.exists(conf_file): | |
36 self.doc_path = path | |
37 break | |
26 | 38 |
27 @defer.inlineCallbacks | 39 if self.doc_path is None and self.sub_docs is None: |
28 def start(self): | 40 log.info("No documentation found for {site_name}, skipping".format( |
29 # root documentation | 41 site_name = self.site_name)) |
30 doc_path = self.getConfig("doc_path") | 42 return |
31 # sub docs will be generated before the root documentation | |
32 sub_docs = self.getConfig("sub_docs_dict", value_type="path") | |
33 | 43 |
34 if doc_path is None: | 44 sphinx = self.findCommand('sphinx-build') |
35 # we check if there is documentation inside the site | |
36 for dirname in DOC_DIRS_DEFAULT: | |
37 path = os.path.join(self.site_path, dirname) | |
38 conf_file = os.path.join(path, 'conf.py') | |
39 if os.path.isdir(path) and os.path.exists(conf_file): | |
40 doc_path = path | |
41 break | |
42 | 45 |
43 if doc_path is None and sub_docs is None: | 46 # we first generate the sub documentations |
44 log.info("No documentation found for {site_name}, skipping".format( | 47 for name, sub_doc_path in list(self.sub_docs.items()): |
45 site_name = self.site_name)) | 48 sub_dir = regex.pathEscape(name or '') |
46 return | 49 build_path = os.path.join(self.build_path, 'doc', sub_dir) |
50 await self.runCommand(sphinx, sub_doc_path, build_path) | |
47 | 51 |
48 sphinx = self.findCommand('sphinx-build') | 52 # then the root one |
53 if self.doc_path is not None: | |
54 build_path = os.path.join(self.build_path, 'doc') | |
55 await self.runCommand(sphinx, self.doc_path, build_path) | |
49 | 56 |
50 # we first generate the sub documentations | 57 log.info(_("documentation has been generated")) |
51 for name, sub_doc_path in list(sub_docs.items()): | |
52 sub_dir = regex.pathEscape(name or '') | |
53 build_path = os.path.join(self.build_path, 'doc', sub_dir) | |
54 yield self.runCommand(sphinx, sub_doc_path, build_path) | |
55 | |
56 # then the root one | |
57 if doc_path is not None: | |
58 build_path = os.path.join(self.build_path, 'doc') | |
59 yield self.runCommand(sphinx, doc_path, build_path) | |
60 | |
61 log.info(_("documentation has been generated")) |