annotate tasks/task_generate_doc.py @ 17:6371bdc0e711

i18n: update French catalog
author Goffi <goffi@goffi.org>
date Wed, 16 Jun 2021 19:22:26 +0200
parents b5fc67c97c50
children a24d362796be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
9ce41ef66dfa python 3 port
Goffi <goffi@goffi.org>
parents: 0
diff changeset
1 #!/ur/bin/env python3
0
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 sat.core.i18n import _
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.log import getLogger
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.tools.common import regex
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
7 from libervia.server.tasks import task
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
10 log = getLogger(__name__)
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
13 class Task(task.Task):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
14 DOC_DIRS_DEFAULT = ('doc', 'docs')
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
16 def prepare(self):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
17 to_watch = set()
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
18 # root documentation
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
19 self.doc_path = self.getConfig("doc_path")
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
20 if self.doc_path is not None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
21 to_watch.add(self.doc_path)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
22 # sub docs will be generated before the root documentation
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
23 self.sub_docs = self.getConfig("sub_docs_dict", value_type="path")
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
24 if self.sub_docs is not None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
25 for d in list(self.sub_docs.values()):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
26 to_watch.add(d)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
27 self.WATCH_DIRS = list(to_watch)
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
29 async def start(self):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
30 if self.doc_path is None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
31 # we check if there is documentation inside the site
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
32 for dirname in self.DOC_DIRS_DEFAULT:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
33 path = os.path.join(self.site_path, dirname)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
34 conf_file = os.path.join(path, 'conf.py')
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
35 if os.path.isdir(path) and os.path.exists(conf_file):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
36 self.doc_path = path
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
37 break
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
39 if self.doc_path is None and self.sub_docs is None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
40 log.info("No documentation found for {site_name}, skipping".format(
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
41 site_name = self.site_name))
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
42 return
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
44 sphinx = self.findCommand('sphinx-build')
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
46 # we first generate the sub documentations
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
47 for name, sub_doc_path in list(self.sub_docs.items()):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
48 sub_dir = regex.pathEscape(name or '')
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
49 build_path = os.path.join(self.build_path, 'doc', sub_dir)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
50 await self.runCommand(sphinx, sub_doc_path, build_path)
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
52 # then the root one
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
53 if self.doc_path is not None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
54 build_path = os.path.join(self.build_path, 'doc')
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
55 await self.runCommand(sphinx, self.doc_path, build_path)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
56
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
57 log.info(_("documentation has been generated"))