added automatic parsing from file
This commit is contained in:
+10
-4
@@ -7,10 +7,16 @@ from pathlib import Path
|
|||||||
class RunnerScript(BaseModel):
|
class RunnerScript(BaseModel):
|
||||||
script: List[str]
|
script: List[str]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_file(path: Path):
|
||||||
|
assert path.exists()
|
||||||
|
with open(path, 'r') as fh:
|
||||||
|
content_dict = yaml.safe_load(fh)
|
||||||
|
script_list = content_dict['script'].split('\n')
|
||||||
|
return RunnerScript.model_validate({'script': script_list})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
path = Path(__file__).parent.parent / 'runner_script.yml'
|
path = Path(__file__).parent.parent / 'runner_script.yml'
|
||||||
with open(path, 'r') as fh:
|
rs = RunnerScript.from_file(path)
|
||||||
script = yaml.safe_load(fh)
|
print(rs)
|
||||||
runner_script = RunnerScript.parse_obj(script)
|
|
||||||
print(runner_script)
|
|
||||||
Reference in New Issue
Block a user