-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
import logging | ||
from typing import Any, Dict, Optional, List, TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from pyobs.robotic import TaskRunner, TaskSchedule, TaskArchive | ||
from pyobs.robotic.scripts import Script | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class CallModule(Script): | ||
"""Script for calling method on a module.""" | ||
|
||
__module__ = "pyobs.modules.robotic" | ||
|
||
def __init__( | ||
self, | ||
module: str, | ||
method: str, | ||
params: Optional[List[Any]], | ||
**kwargs: Any, | ||
): | ||
"""Initialize a new SequentialRunner. | ||
Args: | ||
script: list or dict of scripts to run in a sequence. | ||
""" | ||
Script.__init__(self, **kwargs) | ||
self.module = module | ||
self.method = method | ||
self.params = params or [] | ||
|
||
async def can_run(self) -> bool: | ||
try: | ||
self.comm.proxy(self.module) | ||
return True | ||
except ValueError: | ||
return False | ||
|
||
async def run( | ||
self, | ||
task_runner: TaskRunner, | ||
task_schedule: Optional[TaskSchedule] = None, | ||
task_archive: Optional[TaskArchive] = None, | ||
) -> None: | ||
proxy = self.comm.proxy(self.module) | ||
await proxy.execute(self.method, *self.params) | ||
|
||
|
||
__all__ = ["CallModule"] |