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