Create missing ~/.config directory (and other) if necessary.
authorW. Trevor King <wking@drexel.edu>
Fri, 16 Mar 2012 04:06:12 +0000 (00:06 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 16 Mar 2012 04:06:12 +0000 (00:06 -0400)
h5config/storage/__init__.py
h5config/storage/hdf5.py
h5config/storage/yaml.py

index a62c4734ea46ff53415e381fc34b60f635c43f34..a9dc2d4259658bd9c0e383011e3af8acd6864aa6 100644 (file)
@@ -46,3 +46,8 @@ class FileStorage (Storage):
 
     def __init__(self, filename=None):
         self._filename = filename
+
+    def _create_basedir(self, filename):
+        dirname = _os_path.dirname(filename)
+        if not _os_path.isdir(dirname):
+            _os.makedirs(dirname)
index b8384bcbd2d9f533f66eb3cd279f9c67f30e2900..65b2ba7996b83fe8a70811d5a2b521ea8f45f71c 100644 (file)
@@ -146,6 +146,7 @@ class HDF5_Storage (_FileStorage):
         self._file_checked = True
 
     def _setup_file(self):
+        self._create_basedir(filename=self._filename)
         with _h5py.File(self._filename, 'a') as f:
             cwg = f  # current working group
             h5_create_group(cwg, self.group)
index 61200d418d8925d59aeae8664e90f2711b9c951c..7999d20d03791627de7fa1e55d327676597f1f6a 100644 (file)
@@ -134,6 +134,7 @@ class YAML_Storage (_FileStorage):
         return config
 
     def _save(self, config):
+        self._create_basedir(filename=self._filename)
         data = self._to_dict(config)
         with open(self._filename, 'w') as f:
             _yaml.dump(data, stream=f, Dumper=self.dumper,