27 lines
596 B
Python
27 lines
596 B
Python
import subprocess
|
|
from typing import Text
|
|
|
|
import pydantic
|
|
|
|
from jeeves.core.objects import Result
|
|
from .base import Task
|
|
|
|
|
|
class ShellTask(Task):
|
|
id = "library/shell"
|
|
verbose_name = "Execute Shell script"
|
|
|
|
class Parameters(pydantic.BaseModel):
|
|
script: Text
|
|
|
|
def execute(self):
|
|
process = subprocess.run(
|
|
self.parameters.script,
|
|
shell=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
)
|
|
return Result(
|
|
success=process.returncode == 0, output=process.stdout.decode("utf-8")
|
|
)
|