From: W. Trevor King Date: Fri, 16 Mar 2012 04:06:12 +0000 (-0400) Subject: Create missing ~/.config directory (and other) if necessary. X-Git-Tag: v0.2~12 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=717450e82cbdd3a4a73ba3a98c56a8c333e549c9;p=h5config.git Create missing ~/.config directory (and other) if necessary. --- diff --git a/h5config/storage/__init__.py b/h5config/storage/__init__.py index a62c473..a9dc2d4 100644 --- a/h5config/storage/__init__.py +++ b/h5config/storage/__init__.py @@ -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) diff --git a/h5config/storage/hdf5.py b/h5config/storage/hdf5.py index b8384bc..65b2ba7 100644 --- a/h5config/storage/hdf5.py +++ b/h5config/storage/hdf5.py @@ -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) diff --git a/h5config/storage/yaml.py b/h5config/storage/yaml.py index 61200d4..7999d20 100644 --- a/h5config/storage/yaml.py +++ b/h5config/storage/yaml.py @@ -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,