2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

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

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):