diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8ee96899..9f04b4a1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +v1.12.0 (2023-12-28) +******************* +* 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. 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 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() 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) 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) 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"