From f983fdc9853b6b238f637c06f3e7f7d979d642a5 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 23 Jan 2015 18:59:56 +0800 Subject: [PATCH] file_db: support default data if file not present --- artiq/protocols/file_db.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/artiq/protocols/file_db.py b/artiq/protocols/file_db.py index edf6e7a33..71228985c 100644 --- a/artiq/protocols/file_db.py +++ b/artiq/protocols/file_db.py @@ -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):