From 67d6dca84988d5d4271835522f4697d9e0a2c6f2 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 20 Apr 2011 16:08:33 -0400 Subject: [PATCH] Split out h5_create_group so it can be used by other modules. --- pypiezo/config.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pypiezo/config.py b/pypiezo/config.py index 1d67a18..80e2b5a 100644 --- a/pypiezo/config.py +++ b/pypiezo/config.py @@ -461,6 +461,16 @@ def _pformat_hdf5(cwg, depth=0): lines.append(' '*depth + str(value)) return lines +def h5_create_group(cwg, path): + "Create the group where the settings are stored (if necessary)." + 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] class _HDF5Config (_BackedConfig): """Mixin to back a `_Config` class with an HDF5 file. @@ -519,16 +529,7 @@ class _HDF5Config (_BackedConfig): 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('/'): - 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): -- 2.26.2