Mercurial > libervia-website
annotate tasks/task_generate_doc.py @ 10:0e9e97777fe0
doc: `-` in doc name is replace by `/`:
this is needed for Cagou which is deskop/mobile frontend.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 23 Apr 2021 11:04:23 +0200 |
parents | b5fc67c97c50 |
children | a24d362796be |
rev | line source |
---|---|
6 | 1 #!/ur/bin/env python3 |
0 | 2 |
3 import os.path | |
4 from sat.core.i18n import _ | |
5 from sat.core.log import getLogger | |
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 | 8 |
9 | |
7
b5fc67c97c50
tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
10 log = getLogger(__name__) |
0 | 11 |
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 | 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 | 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 | 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 | 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 | 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 | 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")) |