coverages
This commit is contained in:
parent
6e30f59803
commit
b494c70d9a
3 changed files with 38 additions and 36 deletions
|
@ -15,13 +15,13 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
import os
|
||||||
from ..util import Cache
|
from ..util import Cache
|
||||||
from ...setting import undefined
|
from ...setting import undefined
|
||||||
from ...i18n import _
|
from ...i18n import _
|
||||||
|
|
||||||
|
DEBUG = bool(os.environ.get('DEBUG', False))
|
||||||
DEBUG = False
|
del os
|
||||||
#DEBUG = True
|
|
||||||
|
|
||||||
|
|
||||||
class Values(Cache):
|
class Values(Cache):
|
||||||
|
@ -79,7 +79,7 @@ class Values(Cache):
|
||||||
"""set value for a path
|
"""set value for a path
|
||||||
a specified value must be associated to an owner
|
a specified value must be associated to an owner
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('setvalue', path, value, owner, index, id(self))
|
print('setvalue', path, value, owner, index, id(self))
|
||||||
values = []
|
values = []
|
||||||
vidx = None
|
vidx = None
|
||||||
|
@ -101,7 +101,7 @@ class Values(Cache):
|
||||||
return: boolean
|
return: boolean
|
||||||
"""
|
"""
|
||||||
has_path = path in self._values[0]
|
has_path = path in self._values[0]
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('hasvalue', path, index, has_path, id(self))
|
print('hasvalue', path, index, has_path, id(self))
|
||||||
if index is None:
|
if index is None:
|
||||||
return has_path
|
return has_path
|
||||||
|
@ -115,7 +115,7 @@ class Values(Cache):
|
||||||
"""
|
"""
|
||||||
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('reduce_index', path, index, id(self))
|
print('reduce_index', path, index, id(self))
|
||||||
path_idx = self._values[0].index(path)
|
path_idx = self._values[0].index(path)
|
||||||
# get the "index" position
|
# get the "index" position
|
||||||
|
@ -132,7 +132,7 @@ class Values(Cache):
|
||||||
self._values = tuple(values)
|
self._values = tuple(values)
|
||||||
|
|
||||||
def resetvalue_index(self, path, index):
|
def resetvalue_index(self, path, index):
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('resetvalue_index', path, index, id(self))
|
print('resetvalue_index', path, index, id(self))
|
||||||
def _resetvalue(nb):
|
def _resetvalue(nb):
|
||||||
values_idx = list(values[nb])
|
values_idx = list(values[nb])
|
||||||
|
@ -167,7 +167,7 @@ class Values(Cache):
|
||||||
commit):
|
commit):
|
||||||
"""remove value means delete value in storage
|
"""remove value means delete value in storage
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('resetvalue', path, id(self))
|
print('resetvalue', path, id(self))
|
||||||
def _resetvalue(nb):
|
def _resetvalue(nb):
|
||||||
lst = list(self._values[nb])
|
lst = list(self._values[nb])
|
||||||
|
@ -221,7 +221,7 @@ class Values(Cache):
|
||||||
with_value)
|
with_value)
|
||||||
if owner is undefined:
|
if owner is undefined:
|
||||||
owner = default
|
owner = default
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('getvalue', path, index, value, owner, id(self))
|
print('getvalue', path, index, value, owner, id(self))
|
||||||
if with_value:
|
if with_value:
|
||||||
return owner, value
|
return owner, value
|
||||||
|
|
|
@ -16,14 +16,15 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
|
import os
|
||||||
from .sqlite3db import Sqlite3DB
|
from .sqlite3db import Sqlite3DB
|
||||||
from .storage import delete_session
|
from .storage import delete_session
|
||||||
from ...setting import undefined, owners
|
from ...setting import undefined, owners
|
||||||
from ...i18n import _
|
from ...i18n import _
|
||||||
|
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = bool(os.environ.get('DEBUG', False))
|
||||||
#DEBUG = True
|
del os
|
||||||
|
|
||||||
|
|
||||||
class Values(Sqlite3DB):
|
class Values(Sqlite3DB):
|
||||||
|
@ -57,7 +58,7 @@ class Values(Sqlite3DB):
|
||||||
"""set value for an option
|
"""set value for an option
|
||||||
a specified value must be associated to an owner
|
a specified value must be associated to an owner
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('setvalue', path, value, owner, index, commit)
|
print('setvalue', path, value, owner, index, commit)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
if index is not None:
|
if index is not None:
|
||||||
|
@ -85,7 +86,7 @@ class Values(Sqlite3DB):
|
||||||
"""if opt has a value
|
"""if opt has a value
|
||||||
return: boolean
|
return: boolean
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('hasvalue', path, index)
|
print('hasvalue', path, index)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
return self._sqlite_select(path, index) is not None
|
return self._sqlite_select(path, index) is not None
|
||||||
|
@ -96,7 +97,7 @@ class Values(Sqlite3DB):
|
||||||
_values == ((path1, path2), ((idx1_1, idx1_2), None),
|
_values == ((path1, path2), ((idx1_1, idx1_2), None),
|
||||||
((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('reduce_index', path, index, id(self))
|
print('reduce_index', path, index, id(self))
|
||||||
self._storage.execute("UPDATE value SET idx = ? WHERE path = ? and idx = ? "
|
self._storage.execute("UPDATE value SET idx = ? WHERE path = ? and idx = ? "
|
||||||
"AND session_id = ?",
|
"AND session_id = ?",
|
||||||
|
@ -108,7 +109,7 @@ class Values(Sqlite3DB):
|
||||||
commit=True):
|
commit=True):
|
||||||
"""remove value means delete value in storage
|
"""remove value means delete value in storage
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('resetvalue_index', path, index, commit)
|
print('resetvalue_index', path, index, commit)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ? AND idx = ?",
|
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ? AND idx = ?",
|
||||||
|
@ -120,7 +121,7 @@ class Values(Sqlite3DB):
|
||||||
commit):
|
commit):
|
||||||
"""remove value means delete value in storage
|
"""remove value means delete value in storage
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('resetvalue', path, commit)
|
print('resetvalue', path, commit)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ?",
|
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ?",
|
||||||
|
@ -134,7 +135,7 @@ class Values(Sqlite3DB):
|
||||||
index=None):
|
index=None):
|
||||||
"""change owner for an option
|
"""change owner for an option
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('setowner', path, owner, index)
|
print('setowner', path, owner, index)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
if index is None:
|
if index is None:
|
||||||
|
@ -152,7 +153,7 @@ class Values(Sqlite3DB):
|
||||||
"""get owner for an option
|
"""get owner for an option
|
||||||
return: owner object
|
return: owner object
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('getowner', path, default, index, with_value)
|
print('getowner', path, default, index, with_value)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
request = "SELECT owner, value FROM value WHERE path = ? AND session_id = ?"
|
request = "SELECT owner, value FROM value WHERE path = ? AND session_id = ?"
|
||||||
|
@ -188,7 +189,7 @@ class Values(Sqlite3DB):
|
||||||
:param key: information's key (ex: "help", "doc"
|
:param key: information's key (ex: "help", "doc"
|
||||||
:param value: information's value (ex: "the help string")
|
:param value: information's value (ex: "the help string")
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('set_information', key, value)
|
print('set_information', key, value)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
self._storage.execute("DELETE FROM information WHERE key = ? AND session_id = ? AND path = ?",
|
self._storage.execute("DELETE FROM information WHERE key = ? AND session_id = ? AND path = ?",
|
||||||
|
@ -202,7 +203,7 @@ class Values(Sqlite3DB):
|
||||||
|
|
||||||
:param key: the item string (ex: "help")
|
:param key: the item string (ex: "help")
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('get_information', key, default)
|
print('get_information', key, default)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
value = self._storage.select("SELECT value FROM information WHERE key = ? AND "
|
value = self._storage.select("SELECT value FROM information WHERE key = ? AND "
|
||||||
|
@ -217,7 +218,7 @@ class Values(Sqlite3DB):
|
||||||
return self._sqlite_decode(value[0])
|
return self._sqlite_decode(value[0])
|
||||||
|
|
||||||
def del_information(self, path, key, raises):
|
def del_information(self, path, key, raises):
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('del_information', key, raises)
|
print('del_information', key, raises)
|
||||||
path = self._sqlite_encode_path(path)
|
path = self._sqlite_encode_path(path)
|
||||||
if raises and self._storage.select("SELECT value FROM information WHERE key = ? "
|
if raises and self._storage.select("SELECT value FROM information WHERE key = ? "
|
||||||
|
@ -232,7 +233,7 @@ class Values(Sqlite3DB):
|
||||||
(self._session_id,))
|
(self._session_id,))
|
||||||
|
|
||||||
def exportation(self):
|
def exportation(self):
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('exportation')
|
print('exportation')
|
||||||
rows = self._storage.select("SELECT path, value, owner, idx FROM value WHERE "
|
rows = self._storage.select("SELECT path, value, owner, idx FROM value WHERE "
|
||||||
"session_id = ?;", (self._session_id,), only_one=False)
|
"session_id = ?;", (self._session_id,), only_one=False)
|
||||||
|
@ -262,7 +263,7 @@ class Values(Sqlite3DB):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def importation(self, export):
|
def importation(self, export):
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('importation')
|
print('importation')
|
||||||
request = "DELETE FROM value WHERE session_id = ?"
|
request = "DELETE FROM value WHERE session_id = ?"
|
||||||
self._storage.execute(request, (self._session_id,),
|
self._storage.execute(request, (self._session_id,),
|
||||||
|
@ -289,7 +290,7 @@ class Values(Sqlite3DB):
|
||||||
|
|
||||||
def get_max_length(self,
|
def get_max_length(self,
|
||||||
path):
|
path):
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('get_max_length', path)
|
print('get_max_length', path)
|
||||||
val_max = self._storage.select("SELECT max(idx) FROM value WHERE path = ? AND session_id = ?",
|
val_max = self._storage.select("SELECT max(idx) FROM value WHERE path = ? AND session_id = ?",
|
||||||
(path, self._session_id), False)
|
(path, self._session_id), False)
|
||||||
|
|
|
@ -15,15 +15,16 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
import os
|
||||||
from time import time
|
from time import time
|
||||||
from .cache.dictionary import Cache as DictCache
|
from .cache.dictionary import Cache as DictCache
|
||||||
|
|
||||||
|
|
||||||
def _display_classname(obj): # pragma: no cover
|
def _display_classname(obj):
|
||||||
return(obj.__class__.__name__.lower())
|
return(obj.__class__.__name__.lower())
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = bool(os.environ.get('DEBUG', False))
|
||||||
#DEBUG = True
|
del os
|
||||||
|
|
||||||
|
|
||||||
class Cache(DictCache):
|
class Cache(DictCache):
|
||||||
|
@ -38,12 +39,12 @@ class Cache(DictCache):
|
||||||
if slave, add index
|
if slave, add index
|
||||||
"""
|
"""
|
||||||
if 'cache' in props or 'cache' in self_props:
|
if 'cache' in props or 'cache' in self_props:
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('setcache {} with index {} and value {} in {} ({})'.format(path, index, val,
|
print('setcache {} with index {} and value {} in {} ({})'.format(path, index, val,
|
||||||
_display_classname(self),
|
_display_classname(self),
|
||||||
id(self)))
|
id(self)))
|
||||||
self._setcache(path, index, val, time())
|
self._setcache(path, index, val, time())
|
||||||
elif DEBUG: # pragma: no cover
|
elif DEBUG:
|
||||||
print('not setcache {} with index {} and value {} and props {} and {} in {} ({})'.format(path,
|
print('not setcache {} with index {} and value {} and props {} and {} in {} ({})'.format(path,
|
||||||
index,
|
index,
|
||||||
val,
|
val,
|
||||||
|
@ -79,22 +80,22 @@ class Cache(DictCache):
|
||||||
'expire' in self_props):
|
'expire' in self_props):
|
||||||
ntime = int(time())
|
ntime = int(time())
|
||||||
if timestamp + expires_time >= ntime:
|
if timestamp + expires_time >= ntime:
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('getcache in cache (1)', path, value, _display_classname(self),
|
print('getcache in cache (1)', path, value, _display_classname(self),
|
||||||
id(self), index)
|
id(self), index)
|
||||||
return True, value
|
return True, value
|
||||||
else:
|
else:
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('getcache expired value for path {} < {}'.format(
|
print('getcache expired value for path {} < {}'.format(
|
||||||
timestamp + expires_time, ntime))
|
timestamp + expires_time, ntime))
|
||||||
# if expired, remove from cache
|
# if expired, remove from cache
|
||||||
#self.delcache(path)
|
#self.delcache(path)
|
||||||
else:
|
else:
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('getcache in cache (2)', path, value, _display_classname(self),
|
print('getcache in cache (2)', path, value, _display_classname(self),
|
||||||
id(self), index)
|
id(self), index)
|
||||||
return True, value
|
return True, value
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('getcache {} with index {} not in {} cache'.format(path, index,
|
print('getcache {} with index {} not in {} cache'.format(path, index,
|
||||||
_display_classname(self)))
|
_display_classname(self)))
|
||||||
return no_cache
|
return no_cache
|
||||||
|
@ -102,14 +103,14 @@ class Cache(DictCache):
|
||||||
def delcache(self, path):
|
def delcache(self, path):
|
||||||
"""remove cache for a specified path
|
"""remove cache for a specified path
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('delcache', path, _display_classname(self), id(self))
|
print('delcache', path, _display_classname(self), id(self))
|
||||||
if path in self._cache:
|
if path in self._cache:
|
||||||
self._delcache(path)
|
self._delcache(path)
|
||||||
|
|
||||||
def reset_all_cache(self):
|
def reset_all_cache(self):
|
||||||
"empty the cache"
|
"empty the cache"
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('reset_all_cache', _display_classname(self), id(self))
|
print('reset_all_cache', _display_classname(self), id(self))
|
||||||
self._reset_all_cache()
|
self._reset_all_cache()
|
||||||
|
|
||||||
|
@ -118,6 +119,6 @@ class Cache(DictCache):
|
||||||
please only use it in test purpose
|
please only use it in test purpose
|
||||||
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
|
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
|
||||||
"""
|
"""
|
||||||
if DEBUG: # pragma: no cover
|
if DEBUG:
|
||||||
print('get_chached {} for {} ({})'.format(self._cache, _display_classname(self), id(self)))
|
print('get_chached {} for {} ({})'.format(self._cache, _display_classname(self), id(self)))
|
||||||
return self._get_cached()
|
return self._get_cached()
|
||||||
|
|
Loading…
Reference in a new issue