Browse Source

Use pytable's createparents flag to avoid having to create group

structure manually.
tags/before-insert-rework
Jim Paris 11 years ago
parent
commit
85bb46f45c
1 changed files with 2 additions and 11 deletions
  1. +2
    -11
      nilmdb/nilmdb.py

+ 2
- 11
nilmdb/nilmdb.py View File

@@ -291,16 +291,6 @@ class NilmDB(object):
if group == '': if group == '':
raise ValueError("invalid path") raise ValueError("invalid path")


# Make the group structure, one element at a time
group_path = group.lstrip('/').split("/")
for i in range(len(group_path)):
parent = "/" + "/".join(group_path[0:i])
child = group_path[i]
try:
self.h5file.createGroup(parent, child)
except tables.NodeError:
pass

# Get description # Get description
try: try:
desc = nilmdb.layout.get_named(layout_name).description() desc = nilmdb.layout.get_named(layout_name).description()
@@ -314,7 +304,8 @@ class NilmDB(object):
# Create the table # Create the table
table = self.h5file.createTable(group, node, table = self.h5file.createTable(group, node,
description = desc, description = desc,
expectedrows = exp_rows)
expectedrows = exp_rows,
createparents = True)


# Insert into SQL database once the PyTables is happy # Insert into SQL database once the PyTables is happy
with self.con as con: with self.con as con:


Loading…
Cancel
Save