Starta på yaml io for separate mtr og config filer
This commit is contained in:
parent
3f4051426e
commit
e5a672ac70
29
otime/yaml_io.py
Normal file
29
otime/yaml_io.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user