1 # Copyright (C) 2011 W. Trevor King <wking@drexel.edu>
3 # This file is part of h5config.
5 # h5config is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation, either version 3 of the License, or (at your
8 # option) any later version.
10 # h5config is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with h5config. If not, see <http://www.gnu.org/licenses/>.
19 class Storage (object):
20 "A storage bakend for loading and saving `Config` instances"
21 def load(self, config, merge=False, **kwargs):
24 self._load(config=config, **kwargs)
25 config._storage = self
27 def _load(self, config, **kwargs):
28 raise NotImplementedError()
30 def save(self, config, merge=False, **kwargs):
33 self._save(config=config, **kwargs)
34 config._storage = self
36 def _save(self, config, **kwargs):
37 raise NotImplementedError()
40 class FileStorage (Storage):
41 "`Config` storage backend by a single file"
44 def __init__(self, filename=None):
45 self._filename = filename