__pycache__/__init__.cpython-36.opt-1.pyc000064400000000437147205104220014101 0ustar003 s  __pycache__/__init__.cpython-36.pyc000064400000000437147205104220013142 0ustar003 s  __pycache__/factory.cpython-36.opt-1.pyc000064400000001423147205104220014005 0ustar003 s  __pycache__/factory.cpython-36.pyc000064400000001423147205104220013046 0ustar003 s  __pycache__/interfaces.cpython-36.opt-1.pyc000064400000002410147205104220014456 0ustar003 eZdZddZdddZddZdd Zd d Zd d ZdS)ProvidercCs tdS)N)r)rroptionvaluerrrsetsz Provider.setNcCs tdS)N)r)rrr defaultrrrget sz Provider.getcCs tdS)N)r)rrr rrrunset szProvider.unsetcCs tdS)N)r)rrrrclearszProvider.clearcCs tdS)N)r)rrrrloadsz Provider.loadcCs tdS)N)r)rrrrsavesz Provider.save)N) rr r rrrrrrrrrrr s  r N)objectrr rrrrs__pycache__/interfaces.cpython-36.pyc000064400000002410147205104220013517 0ustar003 eZdZddZdddZddZdd Zd d Zd d ZdS)ProvidercCs tdS)N)r)rroptionvaluerrrsetsz Provider.setNcCs tdS)N)r)rrr defaultrrrget sz Provider.getcCs tdS)N)r)rrr rrrunset szProvider.unsetcCs tdS)N)r)rrrrclearszProvider.clearcCs tdS)N)r)rrrrloadsz Provider.loadcCs tdS)N)r)rrrrsavesz Provider.save)N) rr r rrrrrrrrrrr s  r N)objectrr rrrrs__pycache__/pickle_provider.cpython-36.opt-1.pyc000064400000004305147205104220015521 0ustar003 tjdt|jt|jd}tj|j|WdQRXWn:tt fk rx}ztj d|j|fWYdd}~XnXdS)Nz Saving %swbz"Error saving storage file '%s': %s) logdebugstrropenrpickledumpOSErrorIOErrorerror)rfer r r saves zPickleProvider.savecCsy(t|jd}tj||_WdQRXWnXttfk rh}z tjd|j|fi|_WYdd}~Xnt k ri|_YnXdS)Nrbz#Error loading storage file '%s': %s) rrrloadrrrrrEOFError)rrr r r r r#'szPickleProvider.loadcCsZ|jjytj|jWn:ttfk rT}ztjd|j|fWYdd}~XnXdS)Nz$Error removing storage file '%s': %s) rclearosunlinkrrrrr)rr r r r r%1s  zPickleProvider.clear)N)N) __name__ __module__ __qualname__ __slots__r rrrr!r#r%r r r r r s   r) rZ tuned.logsZtunedrr&Z tuned.constsrZlogsrrZProviderrr r r r s   __pycache__/pickle_provider.cpython-36.pyc000064400000004305147205104220014562 0ustar003 tjdt|jt|jd}tj|j|WdQRXWn:tt fk rx}ztj d|j|fWYdd}~XnXdS)Nz Saving %swbz"Error saving storage file '%s': %s) logdebugstrropenrpickledumpOSErrorIOErrorerror)rfer r r saves zPickleProvider.savecCsy(t|jd}tj||_WdQRXWnXttfk rh}z tjd|j|fi|_WYdd}~Xnt k ri|_YnXdS)Nrbz#Error loading storage file '%s': %s) rrrloadrrrrrEOFError)rrr r r r r#'szPickleProvider.loadcCsZ|jjytj|jWn:ttfk rT}ztjd|j|fWYdd}~XnXdS)Nz$Error removing storage file '%s': %s) rclearosunlinkrrrrr)rr r r r r%1s  zPickleProvider.clear)N)N) __name__ __module__ __qualname__ __slots__r rrrr!r#r%r r r r r s   r) rZ tuned.logsZtunedrr&Z tuned.constsrZlogsrrZProviderrr r r r s   __pycache__/storage.cpython-36.opt-1.pyc000064400000001631147205104220014003 0ustar003 s__pycache__/storage.cpython-36.pyc000064400000001631147205104220013044 0ustar003 s__init__.py000064400000000215147205104220006650 0ustar00from tuned.storage.storage import Storage from tuned.storage.factory import Factory from tuned.storage.pickle_provider import PickleProvider factory.py000064400000000546147205104220006567 0ustar00from . import interfaces from . import storage class Factory(interfaces.Factory): __slots__ = ["_storage_provider"] def __init__(self, storage_provider): self._storage_provider = storage_provider @property def provider(self): return self._storage_provider def create(self, namespace): return storage.Storage(self._storage_provider, namespace) interfaces.py000064400000000731147205104220007237 0ustar00class Factory(object): def create(self, namespace): raise NotImplementedError() class Provider(object): def set(self, namespace, option, value): raise NotImplementedError() def get(self, namespace, option, default=None): raise NotImplementedError() def unset(self, namespace, option): raise NotImplementedError() def clear(self): raise NotImplementedError() def load(self): raise NotImplementedError() def save(self): raise NotImplementedError() pickle_provider.py000064400000002604147205104220010276 0ustar00from . import interfaces import tuned.logs import pickle import os import tuned.consts as consts log = tuned.logs.get() class PickleProvider(interfaces.Provider): __slots__ = ["_path", "_data"] def __init__(self, path=None): if path is None: path = consts.DEFAULT_STORAGE_FILE self._path = path self._data = {} def set(self, namespace, option, value): self._data.setdefault(namespace, {}) self._data[namespace][option] = value def get(self, namespace, option, default=None): self._data.setdefault(namespace, {}) return self._data[namespace].get(option, default) def unset(self, namespace, option): self._data.setdefault(namespace, {}) if option in self._data[namespace]: del self._data[namespace][option] def save(self): try: log.debug("Saving %s" % str(self._data)) with open(self._path, "wb") as f: pickle.dump(self._data, f) except (OSError, IOError) as e: log.error("Error saving storage file '%s': %s" % (self._path, e)) def load(self): try: with open(self._path, "rb") as f: self._data = pickle.load(f) except (OSError, IOError) as e: log.debug("Error loading storage file '%s': %s" % (self._path, e)) self._data = {} except EOFError: self._data = {} def clear(self): self._data.clear() try: os.unlink(self._path) except (OSError, IOError) as e: log.debug("Error removing storage file '%s': %s" % (self._path, e)) storage.py000064400000000742147205104220006562 0ustar00class Storage(object): __slots__ = ["_storage_provider", "_namespace"] def __init__(self, storage_provider, namespace): self._storage_provider = storage_provider self._namespace = namespace def set(self, option, value): self._storage_provider.set(self._namespace, option, value) def get(self, option, default=None): return self._storage_provider.get(self._namespace, option, default) def unset(self, option): self._storage_provider.unset(self._namespace, option)