forked from M-Labs/artiq
file_db: support default data if file not present
This commit is contained in:
parent
9fb42e4952
commit
f983fdc985
|
@ -5,9 +5,16 @@ from artiq.protocols.sync_struct import Notifier
|
||||||
|
|
||||||
|
|
||||||
class FlatFileDB:
|
class FlatFileDB:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename, default_data=None):
|
||||||
self.filename = filename
|
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 = []
|
self.hooks = []
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
|
Loading…
Reference in New Issue