diff --git a/entropy/backends/base.py b/entropy/backends/base.py new file mode 100644 index 0000000..6e6b22e --- /dev/null +++ b/entropy/backends/base.py @@ -0,0 +1,39 @@ +# Copyright (C) 2013 Yahoo! Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import abc + +import six + + +@six.add_metaclass(abc.ABCMeta) +class Backend(object): + """Base class for persistence backends.""" + + def __init__(self, conf): + if not conf: + conf = {} + if not isinstance(conf, dict): + raise TypeError("Configuration dictionary expected not: %s" + % type(conf)) + self._conf = conf + + @abc.abstractmethod + def open(self): + pass + + @abc.abstractmethod + def close(self): + """Closes any resources this backend has open.""" + pass diff --git a/entropy/backends/file_backend.py b/entropy/backends/file_backend.py index 5c13c13..af542da 100644 --- a/entropy/backends/file_backend.py +++ b/entropy/backends/file_backend.py @@ -11,3 +11,13 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import os + +from entropy.backends import base + + +class FileBackend(base.Backend): + """A directory based backend.""" + def __init__(self, conf): + super(FileBackend, self).__init(conf) + self.path = os.path.abspath(conf['path']) diff --git a/setup.cfg b/setup.cfg index 9577b79..3e8024c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ description-file = README.md author = Entropy devs author-email = praneshpg@gmail.com -home-page = http://entropy.readthedocs.org/ +home-page = https://wiki.openstack.org/wiki/Entropy classifier = Development Status :: 4 - Beta Environment :: Console @@ -26,6 +26,10 @@ classifier = console_scripts = entropy = entropy.__main__:main +entropy.backend = + file = entropy.backends.file_backend:FileBackend + db = entropy.backends.file_backend:DbBackend + [global] setup-hooks = pbr.hooks.setup_hook