Skip to content

Commit

Permalink
v1.12.0
Browse files Browse the repository at this point in the history
version 1.12.0
  • Loading branch information
thusser authored Dec 28, 2023
2 parents 4478c32 + 287b3a5 commit aab8a51
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
17 changes: 17 additions & 0 deletions autocompletion.bash
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion pyobs/cli/pyobsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
10 changes: 9 additions & 1 deletion pyobs/modules/robotic/scriptrunner.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand All @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion pyobs/robotic/scripts/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion pyobs/robotic/scripts/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit aab8a51

Please sign in to comment.