summaryrefslogtreecommitdiff
path: root/ebus/datastore.py
diff options
context:
space:
mode:
authorEbus-at-dockstar <ebus@dockstar>2013-03-07 14:20:42 +0100
committerEbus-at-dockstar <ebus@dockstar>2013-03-07 14:20:42 +0100
commit604e92559787ed7e7b590321f6a1ff8fc515e06d (patch)
tree40c28fc8c47d0e5d2006a8e0bb2f006cb8f46825 /ebus/datastore.py
parent7f149ab501ab6121bddb82788e4156d21a1828c9 (diff)
downloadebus-alt-604e92559787ed7e7b590321f6a1ff8fc515e06d.tar.gz
ebus-alt-604e92559787ed7e7b590321f6a1ff8fc515e06d.zip
python datastore + webhdf
Diffstat (limited to 'ebus/datastore.py')
-rw-r--r--ebus/datastore.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/ebus/datastore.py b/ebus/datastore.py
index 88dcdc9..930b4fb 100644
--- a/ebus/datastore.py
+++ b/ebus/datastore.py
@@ -40,8 +40,12 @@ class Datastore(object):
if not name in self.files:
path = os.path.join(self.basepath, name+".hdf")
print "open {0}".format(path)
- file = tables.openFile(path, "a", title = "eBus Datastore")
- self.files[name] = file
+ if os.path.exists(path):
+ self.files[name] = tables.openFile(path, "a", title = "eBus Datastore")
+ elif klass:
+ self.files[name] = tables.openFile(path, "w", title = "eBus Datastore")
+ else:
+ raise Exception("No such sensor {0}".format(name))
if not name in self.tables:
t = None
@@ -49,6 +53,7 @@ class Datastore(object):
t = self.files[name].getNode("/"+name)
except tables.NoSuchNodeError,e:
if not klass: raise e
+
t = self.files[name].createTable("/",
name,
klass,
@@ -56,17 +61,27 @@ class Datastore(object):
filters=tables.Filters(complevel=1),
createparents=True)
t.cols.timestamp.createCSIndex()
+ self.files[name].close()
+
+ self.files[name] = tables.openFile(path, "a", title = "eBus Datastore")
+ t = self.files[name].getNode("/"+name)
+
self.tables[name] = t
return self.tables[name]
def addValue(self, name, ts, value, klass,flush=False):
t = self.getTable(name, klass)
+ if klass != None:
+ assert klass.columns['value'].type == t.cols.value.type, "Type check failed"
+
with self.fileLock:
t.row['timestamp'] = ts
t.row['value'] = value
t.row.append()
- if flush: t.flush()
+ if flush:
+ t.flush()
+ t.flushRowsToIndex()
def addValueInt(self, name, ts, value): self.addValue(name, ts, value, ValueInt)
def addValueString(self, name, ts, value): self.addValue(name, ts, value, ValueString)