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