From 7a4083dec4db4e37491e49e24a6cc5cc7dd75cbd Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 26 Dec 2023 16:49:58 +0100 Subject: [PATCH 1/7] added a "list" command for pyobsd --- pyobs/cli/pyobsd.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyobs/cli/pyobsd.py b/pyobs/cli/pyobsd.py index 70f708a4..277288df 100755 --- a/pyobs/cli/pyobsd.py +++ b/pyobs/cli/pyobsd.py @@ -135,6 +135,10 @@ def status(self, services: Optional[List[str]] = None) -> None: for p in services: print(("[X]" if p in configs else "[ ]") + " " + ("[X]" if p in running else "[ ]") + " " + p) + def list(self, **kwargs) -> None: + configs = [self._service(r) for r in self._configs] + print("\n".join(configs)) + def _start_service(self, service: str) -> None: # get PID file pid_file = self._pid_file(service) @@ -228,7 +232,7 @@ def main() -> None: parser.add_argument( "--start-stop-daemon", type=str, default=config.get("start-stop-daemon", "/sbin/start-stop-daemon") ) - parser.add_argument("command", type=str, choices=["start", "stop", "restart", "status"]) + parser.add_argument("command", type=str, choices=["start", "stop", "restart", "status", "list"]) parser.add_argument("services", type=str, nargs="*") args = parser.parse_args() From a1bdc74016304cbbd58d2b13028c47a6218e6b35 Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 26 Dec 2023 17:00:50 +0100 Subject: [PATCH 2/7] added autocompletion script for pyobsd --- autocompletion.bash | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 autocompletion.bash diff --git a/autocompletion.bash b/autocompletion.bash new file mode 100644 index 00000000..a436a571 --- /dev/null +++ b/autocompletion.bash @@ -0,0 +1,17 @@ +function _pyobsd() +{ + latest="${COMP_WORDS[$COMP_CWORD]}" + prev="${COMP_WORDS[$COMP_CWORD - 1]}" + words="" + case "${prev}" in + start|stop|restart) + words=`pyobsd list` + ;; + *) + words="start stop restart status";; + esac + COMPREPLY=($(compgen -W "$words" -- $latest)) + return 0 +} + +complete -F _pyobsd pyobsd From 7f3c2d929b6b9cf084ab10c0c7527da59df8dd43 Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 26 Dec 2023 18:52:33 +0100 Subject: [PATCH 3/7] timeout for run() method can be defined in config --- pyobs/modules/robotic/scriptrunner.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyobs/modules/robotic/scriptrunner.py b/pyobs/modules/robotic/scriptrunner.py index 82be26e4..c71b7325 100644 --- a/pyobs/modules/robotic/scriptrunner.py +++ b/pyobs/modules/robotic/scriptrunner.py @@ -1,13 +1,18 @@ import logging from typing import Any, Dict -from pyobs.modules import Module +from pyobs.modules import Module, timeout from pyobs.interfaces import IRunnable from pyobs.robotic.scripts import Script log = logging.getLogger(__name__) +async def calc_run_timeout(obj: "ScriptRunner", *args: Any, **kwargs: Any) -> float: + """Calculates timeout for run().""" + return obj.timeout + + class ScriptRunner(Module, IRunnable): """Module for running a script.""" @@ -17,6 +22,7 @@ def __init__( self, script: Dict[str, Any], run_once: bool = False, + timeout: int = 10, **kwargs: Any, ): """Initialize a new script runner. @@ -29,11 +35,13 @@ def __init__( # store self.script = script self._script = self.add_child_object(script, Script) + self.timeout = timeout # add thread func if run_once: self.add_background_task(self._run_thread, False) + @timeout(calc_run_timeout) async def run(self, **kwargs: Any) -> None: """Run script.""" script = self.get_object(self.script, Script) From dbaa9dced5f27e307bdb7935b878b151a7016769 Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 26 Dec 2023 18:55:33 +0100 Subject: [PATCH 4/7] changelog --- CHANGELOG.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8ee96899..80d32d64 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +v1.12.0 (2023-12-xx) +******************* +* Added `list` command for `pyobsd`, which outputs all configurations. +* Added bash auto-complete script `pyobsd`. +* Added timeouts (to be defined in the config) for `ScriptRunner` modules. + + v1.11.0 (2023-12-25) ******************* * Acquisition and AutoFocus both got a `broadcast` option to disable broadcast of images. From 74e49a0d3d4a446af2762854d9fd13c744aeb741 Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Thu, 28 Dec 2023 18:43:55 +0100 Subject: [PATCH 5/7] added awaits for can_run() --- pyobs/robotic/scripts/parallel.py | 4 +++- pyobs/robotic/scripts/sequential.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyobs/robotic/scripts/parallel.py b/pyobs/robotic/scripts/parallel.py index fe68b5c5..51f47af9 100644 --- a/pyobs/robotic/scripts/parallel.py +++ b/pyobs/robotic/scripts/parallel.py @@ -42,7 +42,9 @@ async def run( task_archive: Optional[TaskArchive] = None, ) -> None: scripts = [self.get_object(s, Script) for s in self.scripts] - tasks = [asyncio.create_task(s.run(task_runner, task_schedule, task_archive)) for s in scripts if s.can_run()] + tasks = [ + asyncio.create_task(s.run(task_runner, task_schedule, task_archive)) for s in scripts if await s.can_run() + ] await asyncio.gather(*tasks) diff --git a/pyobs/robotic/scripts/sequential.py b/pyobs/robotic/scripts/sequential.py index 36870f1d..dc1152c2 100644 --- a/pyobs/robotic/scripts/sequential.py +++ b/pyobs/robotic/scripts/sequential.py @@ -41,7 +41,7 @@ async def run( ) -> None: for s in self.scripts: script = self.get_object(s, Script) - if script.can_run(): + if await script.can_run(): await script.run(task_runner, task_schedule, task_archive) From e2c0d2b23c744c3869d6b13b0da7401f891b4f8c Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Thu, 28 Dec 2023 18:44:18 +0100 Subject: [PATCH 6/7] 1.12 --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 80d32d64..9f04b4a1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,4 +1,4 @@ -v1.12.0 (2023-12-xx) +v1.12.0 (2023-12-28) ******************* * Added `list` command for `pyobsd`, which outputs all configurations. * Added bash auto-complete script `pyobsd`. From 287b3a5ebd92c58c71ec73148368222ab1a2a4a3 Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Thu, 28 Dec 2023 18:44:29 +0100 Subject: [PATCH 7/7] v1.12.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8787e15f..b4c5199c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pyobs-core" packages = [{ include = "pyobs" }] -version = "1.11.3" +version = "1.12.0" description = "robotic telescope software" authors = ["Tim-Oliver Husser "] license = "MIT"