Skip to content

Commit

Permalink
v1.17.5
Browse files Browse the repository at this point in the history
version 1.17.5
  • Loading branch information
thusser authored Nov 5, 2024
2 parents 45b3bb5 + 6d764fb commit e77969d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
26 changes: 15 additions & 11 deletions pyobs/robotic/scripts/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,29 @@ def __init__(
self.expression = expression
self.cases = cases

async def can_run(self) -> bool:
return True

async def run(
self,
task_runner: TaskRunner,
task_schedule: Optional[TaskSchedule] = None,
task_archive: Optional[TaskArchive] = None,
) -> None:
def __get_script(self) -> Script:
# evaluate condition
value = eval(self.expression, {"now": datetime.now(timezone.utc), "config": self.configuration})

# check in cases
if value in self.cases:
script = self.get_object(self.cases[value], Script, configuration=self.configuration)
return self.get_object(self.cases[value], Script, configuration=self.configuration)
elif "else" in self.cases:
script = self.get_object(self.cases["else"], Script, configuration=self.configuration)
return self.get_object(self.cases["else"], Script, configuration=self.configuration)
else:
raise ValueError("Invalid choice")

async def can_run(self) -> bool:
script = self.__get_script()
return await script.can_run()

async def run(
self,
task_runner: TaskRunner,
task_schedule: Optional[TaskSchedule] = None,
task_archive: Optional[TaskArchive] = None,
) -> None:
script = self.__get_script()
await script.run(task_runner, task_schedule, task_archive)


Expand Down
25 changes: 15 additions & 10 deletions pyobs/robotic/scripts/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,29 @@ def __init__(
self.true = true
self.false = false

def __get_script(self) -> Script:
# evaluate condition
ret = eval(self.condition, {"now": datetime.now(timezone.utc)})

# run scripts
if ret:
return self.get_object(self.true, Script)
else:
if self.false is not None:
return self.get_object(self.false, Script)

async def can_run(self) -> bool:
return True
script = self.__get_script()
return await script.can_run()

async def run(
self,
task_runner: TaskRunner,
task_schedule: Optional[TaskSchedule] = None,
task_archive: Optional[TaskArchive] = None,
) -> None:
# evaluate condition
ret = eval(self.condition, {"now": datetime.now(timezone.utc)})

# run scripts
if ret:
await self.get_object(self.true, Script).run(task_runner, task_schedule, task_archive)
else:
if self.false is not None:
await self.get_object(self.false, Script).run(task_runner, task_schedule, task_archive)
script = self.__get_script()
await script.run(task_runner, task_schedule, task_archive)


__all__ = ["ConditionalRunner"]
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.17.3"
version = "1.17.5"
description = "robotic telescope software"
authors = ["Tim-Oliver Husser <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit e77969d

Please sign in to comment.