protocols: move FlatFileDB into pyon

This commit is contained in:
Sebastien Bourdeauducq 2015-10-12 18:19:28 +08:00
parent 22bffa98b5
commit a83ffb3dce
4 changed files with 22 additions and 24 deletions

View File

@ -3,7 +3,7 @@
import logging
import argparse
from artiq.protocols.file_db import FlatFileDB
from artiq.protocols.pyon import FlatFileDB
from artiq.master.worker_db import DeviceManager
from artiq.tools import *

View File

@ -1,22 +0,0 @@
from artiq.protocols import pyon
from artiq.protocols.sync_struct import Notifier
class FlatFileDB:
def __init__(self, filename):
self.filename = filename
self.data = Notifier(pyon.load_file(self.filename))
def save(self):
pyon.store_file(self.filename, self.data.read)
def get(self, key):
return self.data.read[key]
def set(self, key, value):
self.data[key] = value
self.save()
def delete(self, key):
del self.data[key]
self.save()

View File

@ -187,3 +187,23 @@ def load_file(filename):
"""Parses the specified file and returns the decoded Python object."""
with open(filename, "r") as f:
return decode(f.read())
class FlatFileDB:
def __init__(self, filename):
self.filename = filename
self.data = pyon.load_file(self.filename)
def save(self):
pyon.store_file(self.filename, self.data)
def get(self, key):
return self.data[key]
def set(self, key, value):
self.data[key] = value
self.save()
def delete(self, key):
del self.data[key]
self.save()

View File

@ -6,7 +6,7 @@ import unittest
import logging
from artiq.language import *
from artiq.protocols.file_db import FlatFileDB
from artiq.protocols.pyon import FlatFileDB
from artiq.master.worker_db import DeviceManager, ResultDB
from artiq.frontend.artiq_run import DummyScheduler