changeset 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 dc880664a8ec
files tasks/task_generate_doc.py tasks/task_social_contract.py
diffstat 2 files changed, 57 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/tasks/task_generate_doc.py	Sat Oct 05 01:26:51 2019 +0200
+++ b/tasks/task_generate_doc.py	Tue May 26 12:38:56 2020 +0200
@@ -1,61 +1,57 @@
 #!/ur/bin/env python3
 
 import os.path
-from twisted.internet import defer
 from sat.core.i18n import _
 from sat.core.log import getLogger
 from sat.tools.common import regex
-log = getLogger(__name__)
-
-WATCH_DIRS = []
-DOC_DIRS_DEFAULT = ('doc', 'docs')
+from libervia.server.tasks import task
 
 
-def prepare(self):
-    to_watch = set()
-    doc_path = self.getConfig("doc_path")
-    if doc_path is not None:
-        to_watch.add(doc_path)
-    sub_docs = self.getConfig("sub_docs_dict", value_type="path")
-    if sub_docs is not None:
-        for d in list(sub_docs.values()):
-            to_watch.add(d)
-    global WATCH_DIRS
-    WATCH_DIRS = list(to_watch)
+log = getLogger(__name__)
 
 
-@defer.inlineCallbacks
-def start(self):
-    # root documentation
-    doc_path = self.getConfig("doc_path")
-    # sub docs will be generated before the root documentation
-    sub_docs = self.getConfig("sub_docs_dict", value_type="path")
+class Task(task.Task):
+    DOC_DIRS_DEFAULT = ('doc', 'docs')
 
-    if doc_path is None:
-        # we check if there is documentation inside the site
-        for dirname in DOC_DIRS_DEFAULT:
-            path = os.path.join(self.site_path, dirname)
-            conf_file = os.path.join(path, 'conf.py')
-            if os.path.isdir(path) and os.path.exists(conf_file):
-                doc_path = path
-                break
+    def prepare(self):
+        to_watch = set()
+        # root documentation
+        self.doc_path = self.getConfig("doc_path")
+        if self.doc_path is not None:
+            to_watch.add(self.doc_path)
+        # sub docs will be generated before the root documentation
+        self.sub_docs = self.getConfig("sub_docs_dict", value_type="path")
+        if self.sub_docs is not None:
+            for d in list(self.sub_docs.values()):
+                to_watch.add(d)
+        self.WATCH_DIRS = list(to_watch)
 
-    if doc_path is None and sub_docs is None:
-        log.info("No documentation found for {site_name}, skipping".format(
-            site_name = self.site_name))
-        return
+    async def start(self):
+        if self.doc_path is None:
+            # we check if there is documentation inside the site
+            for dirname in self.DOC_DIRS_DEFAULT:
+                path = os.path.join(self.site_path, dirname)
+                conf_file = os.path.join(path, 'conf.py')
+                if os.path.isdir(path) and os.path.exists(conf_file):
+                    self.doc_path = path
+                    break
 
-    sphinx = self.findCommand('sphinx-build')
+        if self.doc_path is None and self.sub_docs is None:
+            log.info("No documentation found for {site_name}, skipping".format(
+                site_name = self.site_name))
+            return
 
-    # we first generate the sub documentations
-    for name, sub_doc_path in list(sub_docs.items()):
-        sub_dir = regex.pathEscape(name or '')
-        build_path = os.path.join(self.build_path, 'doc', sub_dir)
-        yield self.runCommand(sphinx, sub_doc_path, build_path)
+        sphinx = self.findCommand('sphinx-build')
 
-    # then the root one
-    if doc_path is not None:
-        build_path = os.path.join(self.build_path, 'doc')
-        yield self.runCommand(sphinx, doc_path, build_path)
+        # we first generate the sub documentations
+        for name, sub_doc_path in list(self.sub_docs.items()):
+            sub_dir = regex.pathEscape(name or '')
+            build_path = os.path.join(self.build_path, 'doc', sub_dir)
+            await self.runCommand(sphinx, sub_doc_path, build_path)
 
-    log.info(_("documentation has been generated"))
+        # then the root one
+        if self.doc_path is not None:
+            build_path = os.path.join(self.build_path, 'doc')
+            await self.runCommand(sphinx, self.doc_path, build_path)
+
+        log.info(_("documentation has been generated"))
--- a/tasks/task_social_contract.py	Sat Oct 05 01:26:51 2019 +0200
+++ b/tasks/task_social_contract.py	Tue May 26 12:38:56 2020 +0200
@@ -1,21 +1,26 @@
 #!/ur/bin/env python2
 
 import glob
+import os.path
 import markdown
-import os.path
 from sat.core.i18n import _
 from sat.core.log import getLogger
+from libervia.server.tasks import task
+
+
 log = getLogger(__name__)
 
 
-def start(self):
-    sat_path = self.getConfig("sat_repos_path")
-    for filepath in glob.glob(os.path.join(sat_path, "CONTRAT_SOCIAL*")):
-        filename = os.path.basename(filepath)
-        with open(filepath) as f:
-            md = markdown.markdown(f.read())
-        build_path = os.path.join(self.build_path, filename + '.html')
-        with open(build_path, 'w') as f:
-            f.write(md)
+class Task(task.Task):
 
-    log.info(_("social contract has been converted to  HTML"))
+    def start(self):
+        sat_path = self.getConfig("sat_repos_path")
+        for filepath in glob.glob(os.path.join(sat_path, "CONTRAT_SOCIAL*")):
+            filename = os.path.basename(filepath)
+            with open(filepath) as f:
+                md = markdown.markdown(f.read())
+            build_path = os.path.join(self.build_path, filename + '.html')
+            with open(build_path, 'w') as f:
+                f.write(md)
+
+        log.info(_("social contract has been converted to  HTML"))