diff libervia/server/tasks/manager.py @ 1509:106bae41f5c8

massive refactoring from camelCase -> snake_case. See backend commit log for more details
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:44:11 +0200
parents 822bd0139769
children
line wrap: on
line diff
--- a/libervia/server/tasks/manager.py	Fri Apr 07 15:20:40 2023 +0200
+++ b/libervia/server/tasks/manager.py	Sat Apr 08 13:44:11 2023 +0200
@@ -56,14 +56,14 @@
     def build_path(self):
         """path where generated files will be build for this site"""
         if self._build_path is None:
-            self._build_path = self.host.getBuildPath(self.site_name)
+            self._build_path = self.host.get_build_path(self.site_name)
         return self._build_path
 
     @property
     def site_name(self):
         return self.resource.site_name
 
-    def validateData(self, task):
+    def validate_data(self, task):
         """Check workflow attributes in task"""
 
         for var, allowed in (("ON_ERROR", ("continue", "stop")),
@@ -83,7 +83,7 @@
                     raise ValueError(_("Unexpected value for {var}: {value!r}").format(
                         var=var, value=value))
 
-    async def importTask(
+    async def import_task(
         self,
         task_name: str,
         task_path: Path,
@@ -108,7 +108,7 @@
                     raise ValueError(
                         f"task {task_name!r} must be run after {pre_task_name!r}, "
                         f"however there is no task with such name")
-                await self.importTask(pre_task_name, pre_task_path, to_import)
+                await self.import_task(pre_task_name, pre_task_path, to_import)
 
         # we launch prepare, which is a method used to prepare
         # data at runtime (e.g. set WATCH_DIRS using config)
@@ -120,21 +120,21 @@
             log.info(_('== preparing task "{task_name}" for {site_name} =='.format(
                 task_name=task_name, site_name=self.site_name or DEFAULT_SITE_LABEL)))
             try:
-                await utils.asDeferred(prepare)
+                await utils.as_deferred(prepare)
             except exceptions.CancelError as e:
                 log.debug(f"Skipping {task_name} which cancelled itself: {e}")
                 return
 
         self.tasks[task_name] = task
-        self.validateData(task)
+        self.validate_data(task)
         if self.host.options['dev-mode']:
             dirs = task.WATCH_DIRS or []
             for dir_ in dirs:
-                self.host.files_watcher.watchDir(
+                self.host.files_watcher.watch_dir(
                     dir_, auto_add=True, recursive=True,
-                    callback=self._autorunTask, task_name=task_name)
+                    callback=self._autorun_task, task_name=task_name)
 
-    async def parseTasksDir(self, dir_path: Path) -> None:
+    async def parse_tasks_dir(self, dir_path: Path) -> None:
         log.debug(f"parsing tasks in {dir_path}")
         tasks_paths = sorted(dir_path.glob('task_*.py'))
         to_import = {}
@@ -152,40 +152,40 @@
             to_import[task_name] = task_path
 
         for task_name, task_path in to_import.items():
-            await self.importTask(task_name, task_path, to_import)
+            await self.import_task(task_name, task_path, to_import)
 
-    async def parseTasks(self):
+    async def parse_tasks(self):
         # implicit tasks are always run
         implicit_path = Path(implicit.__file__).parent
-        await self.parseTasksDir(implicit_path)
+        await self.parse_tasks_dir(implicit_path)
         # now we check if there are tasks specific to this site
         if not self.tasks_dir.is_dir():
             log.debug(_("{name} has no task to launch.").format(
                 name = self.resource.site_name or DEFAULT_SITE_LABEL))
             return
         else:
-            await self.parseTasksDir(self.tasks_dir)
+            await self.parse_tasks_dir(self.tasks_dir)
 
-    def _autorunTask(self, host, filepath, flags, task_name):
+    def _autorun_task(self, host, filepath, flags, task_name):
         """Called when an event is received from a watched directory"""
         if flags == ['create']:
             return
         try:
             task = self.tasks[task_name]
-            on_dir_event_cb = task.onDirEvent
+            on_dir_event_cb = task.on_dir_event
         except AttributeError:
-            return defer.ensureDeferred(self.runTask(task_name))
+            return defer.ensureDeferred(self.run_task(task_name))
         else:
-            return utils.asDeferred(
+            return utils.as_deferred(
                 on_dir_event_cb, host, Path(filepath.path.decode()), flags)
 
-    async def runTaskInstance(self, task: Task) -> None:
+    async def run_task_instance(self, task: Task) -> None:
         self._current_task = task.name
         log.info(_('== running task "{task_name}" for {site_name} =='.format(
             task_name=task.name, site_name=self.site_name or DEFAULT_SITE_LABEL)))
         os.chdir(self.site_path)
         try:
-            await utils.asDeferred(task.start)
+            await utils.as_deferred(task.start)
         except Exception as e:
             on_error = task.ON_ERROR
             if on_error == 'stop':
@@ -197,17 +197,17 @@
                 raise exceptions.InternalError("we should never reach this point")
         self._current_task = None
 
-    async def runTask(self, task_name: str) -> None:
+    async def run_task(self, task_name: str) -> None:
         """Run a single task
 
         @param task_name(unicode): name of the task to run
         """
         task = self.tasks[task_name]
-        await self.runTaskInstance(task)
+        await self.run_task_instance(task)
 
-    async def runTasks(self):
+    async def run_tasks(self):
         """Run all the tasks found"""
         old_path = os.getcwd()
         for task_name, task_value in self.tasks.items():
-            await self.runTask(task_name)
+            await self.run_task(task_name)
         os.chdir(old_path)