forked from M-Labs/artiq
1
0
Fork 0

file_db: support default data if file not present

This commit is contained in:
Sebastien Bourdeauducq 2015-01-23 18:59:56 +08:00
parent 9fb42e4952
commit f983fdc985
1 changed files with 9 additions and 2 deletions

View File

@ -5,9 +5,16 @@ from artiq.protocols.sync_struct import Notifier
class FlatFileDB:
def __init__(self, filename):
def __init__(self, filename, default_data=None):
self.filename = filename
self.data = Notifier(pyon.load_file(self.filename))
try:
data = pyon.load_file(self.filename)
except FileNotFoundError:
if default_data is None:
raise
else:
data = default_data
self.data = Notifier(data)
self.hooks = []
def save(self):