From e5a672ac70dd925ee6e0591d69ec8a87fa7b27fb Mon Sep 17 00:00:00 2001 From: Trygve Date: Fri, 17 Nov 2023 13:55:21 +0100 Subject: [PATCH] =?UTF-8?q?Starta=20p=C3=A5=20yaml=20io=20for=20separate?= =?UTF-8?q?=20mtr=20og=20config=20filer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime/yaml_io.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 otime/yaml_io.py diff --git a/otime/yaml_io.py b/otime/yaml_io.py new file mode 100644 index 0000000..8b8714b --- /dev/null +++ b/otime/yaml_io.py @@ -0,0 +1,29 @@ +from yaml import load, dump +try: + from yaml import CLoader as Loader, CDumper as Dumper +except ImportError: + from yaml import Loader, Dumper + +from copy import deepcopy +import otime + +# Disse funksjonene er for å kunne lese og skrive seperate config, mtr og databasefiler. +def write_config(event, file_path): + output_event = deepcopy(event) + output_event.runners = [] + output_event.card_dumps = [] + with open(file_path, 'w') as f: + dump(output_event, f) + +def write_card_dumps(event, file_path): + card_dumps = deepcopy(event.card_dumps) + with open(file_path, 'w') as f: + dump(card_dumps, f) + +def event_from_config_and_card_dumps(config_path, mtr_path): + with open(mtr_path, 'r') as f: + card_dumps = load(f, Loader=Loader) + with open(config_path, 'r') as f: + event = load(f, Loader=Loader) + event.card_dumps = card_dumps + return event \ No newline at end of file