added automatic parsing from file
This commit is contained in:
+10
-4
@@ -7,10 +7,16 @@ from pathlib import Path
|
||||
class RunnerScript(BaseModel):
|
||||
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__':
|
||||
path = Path(__file__).parent.parent / 'runner_script.yml'
|
||||
with open(path, 'r') as fh:
|
||||
script = yaml.safe_load(fh)
|
||||
runner_script = RunnerScript.parse_obj(script)
|
||||
print(runner_script)
|
||||
rs = RunnerScript.from_file(path)
|
||||
print(rs)
|
||||
Reference in New Issue
Block a user