Split out h5_create_group so it can be used by other modules.
authorW. Trevor King <wking@drexel.edu>
Wed, 20 Apr 2011 20:08:33 +0000 (16:08 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 20 Apr 2011 20:08:33 +0000 (16:08 -0400)
pypiezo/config.py

index 1d67a18f50f493a50f6916a2b3d4651581eb3fd9..80e2b5a821b6b612375e6bd6bc91433a149e8950 100644 (file)
@@ -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):