def _pformat_hdf5(cwg, depth=0):
lines = []
lines.append(' '*depth + cwg.name)
- depth += 1
+ depth += 1
for key,value in cwg.iteritems():
if isinstance(value, _h5py.Group):
lines.extend(_pformat_hdf5(value, depth))
else:
lines.append(' '*depth + str(value))
return lines
-
+
+def h5_create_group(cwg, path):
+ "Create the group where the settings are stored (if necessary)."
+ if path == '/':
+ return cwg
+ gpath = ['']
+ for group in path.strip('/').split('/'):
+ gpath.append(group)
+ if group not in cwg.keys():
+ _LOG.debug('creating group %s in %s'
+ % ('/'.join(gpath), cwg.file))
+ cwg.create_group(group)
+ cwg = cwg[group]
+ return cwg
+
class _HDF5Config (_config.BackedConfig):
"""Mixin to back a `_Config` class with an HDF5 file.
def _setup_file(self):
f = _h5py.File(self.filename, 'a')
cwg = f # current working group
-
- # Create the group where the settings are stored (if necessary)
- gpath = ['']
- for group in self.group.strip('/').split('/'):
- if not group:
- break
- gpath.append(group)
- if group not in cwg.keys():
- _LOG.debug('creating group %s in %s'
- % ('/'.join(gpath), self.filename))
- cwg.create_group(group)
- cwg = cwg[group]
+ h5_create_group(cwg, self.group)
f.close()
def dump(self, help=False, from_file=False):