Split out h5_create_group so it can be used by other modules. v0.1
authorW. Trevor King <wking@drexel.edu>
Thu, 28 Jul 2011 17:35:12 +0000 (13:35 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 28 Jul 2011 17:35:12 +0000 (13:35 -0400)
My initial break from pypiezo was not from the pypiezo tip.  This
commit pulls in following pypiezo changes:

  commit 67d6dca84988d5d4271835522f4697d9e0a2c6f2
    Split out h5_create_group so it can be used by other modules.
  commit 9afcf604e967123b3cdf2665827afe24a74225f2
    Return the group created in h5_create_group().
  commit 5d84f6b5392236e8d2b1513178063bfc2a5f5893
    Special case for '/' group in h5_create_group.

It also strips trailing whitespace from h5config/hdf5.py.

h5config/hdf5.py

index 4e06567ff8896322b7e6ec717185f70a90e16199..996fadfab06411fb8de8463e72c6cc70652ea6c8 100644 (file)
@@ -35,7 +35,7 @@ def pformat_HDF5(filename, group='/'):
 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))
@@ -45,7 +45,21 @@ def _pformat_hdf5(cwg, depth=0):
         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.
@@ -109,18 +123,7 @@ class _HDF5Config (_config.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('/'):
-            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):