print => log
This commit is contained in:
parent
af5da925e2
commit
375b3c91de
8 changed files with 66 additions and 101 deletions
23
tiramisu/log.py
Normal file
23
tiramisu/log.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"logger for tiramisu"
|
||||
# Copyright (C) 2019 Team tiramisu (see AUTHORS for all contributors)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published by the
|
||||
# Free Software Foundation, either version 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
# details.
|
||||
#
|
||||
# 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/>.
|
||||
# ____________________________________________________________
|
||||
from logging import getLogger
|
||||
|
||||
|
||||
log = getLogger('tiramisu')
|
||||
# import logging
|
||||
# logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
|
@ -25,7 +25,7 @@ from typing import Any, List, Callable, Optional, Dict, Union, Tuple
|
|||
|
||||
from .baseoption import BaseOption, submulti, STATIC_TUPLE
|
||||
from ..i18n import _
|
||||
from ..setting import log, undefined, OptionBag, Undefined
|
||||
from ..setting import undefined, OptionBag, Undefined
|
||||
from ..autolib import carry_out_calculation
|
||||
from ..error import (ConfigError, ValueWarning, ValueErrorWarning, PropertiesOptionError,
|
||||
ValueOptionError, display_list)
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
# 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/>.
|
||||
# ____________________________________________________________
|
||||
from copy import copy
|
||||
from logging import getLogger
|
||||
import weakref
|
||||
from .error import (RequirementError, PropertiesOptionError,
|
||||
ConstError, ConfigError, display_list)
|
||||
from .i18n import _
|
||||
|
@ -114,10 +111,6 @@ FORBIDDEN_SET_PERMISSIVES = frozenset(['force_default_on_freeze',
|
|||
'force_store_value'])
|
||||
|
||||
|
||||
log = getLogger('tiramisu')
|
||||
#FIXME
|
||||
#import logging
|
||||
#logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
||||
static_set = frozenset()
|
||||
|
||||
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
# ____________________________________________________________
|
||||
from copy import copy
|
||||
from ..util import Cache
|
||||
|
||||
DEBUG = False
|
||||
#DEBUG = True
|
||||
from ...log import log
|
||||
|
||||
|
||||
class Properties(Cache):
|
||||
|
@ -34,19 +32,16 @@ class Properties(Cache):
|
|||
|
||||
# properties
|
||||
def setproperties(self, path, properties):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setproperties', path, properties)
|
||||
log.debug('setproperties', path, properties)
|
||||
self._properties[path] = properties
|
||||
|
||||
def getproperties(self, path, default_properties):
|
||||
ret = self._properties.get(path, frozenset(default_properties))
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getproperties', path, ret)
|
||||
log.debug('getproperties', path, ret)
|
||||
return ret
|
||||
|
||||
def delproperties(self, path):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('delproperties', path)
|
||||
log.debug('delproperties', path)
|
||||
if path in self._properties:
|
||||
del(self._properties[path])
|
||||
|
||||
|
@ -69,8 +64,7 @@ class Permissives(Cache):
|
|||
super(Permissives, self).__init__(storage)
|
||||
|
||||
def setpermissives(self, path, permissives):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setpermissives', path, permissives)
|
||||
log.debug('setpermissives', path, permissives)
|
||||
if not permissives:
|
||||
if path in self._permissives:
|
||||
del self._permissives[path]
|
||||
|
@ -79,8 +73,7 @@ class Permissives(Cache):
|
|||
|
||||
def getpermissives(self, path=None):
|
||||
ret = self._permissives.get(path, frozenset())
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getpermissives', path, ret)
|
||||
log.debug('getpermissives', path, ret)
|
||||
return ret
|
||||
|
||||
def exportation(self):
|
||||
|
@ -93,7 +86,6 @@ class Permissives(Cache):
|
|||
self._permissives = permissives
|
||||
|
||||
def delpermissive(self, path):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('delpermissive', path)
|
||||
log.debug('delpermissive', path)
|
||||
if path in self._permissives:
|
||||
del(self._permissives[path])
|
||||
|
|
|
@ -15,13 +15,10 @@
|
|||
# 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/>.
|
||||
# ____________________________________________________________
|
||||
import os
|
||||
from ..util import Cache
|
||||
from ...setting import undefined
|
||||
from ...i18n import _
|
||||
|
||||
DEBUG = bool(os.environ.get('TIRAMISU_DEBUG', False))
|
||||
del os
|
||||
from ...log import log
|
||||
|
||||
|
||||
class Values(Cache):
|
||||
|
@ -79,8 +76,7 @@ class Values(Cache):
|
|||
"""set value for a path
|
||||
a specified value must be associated to an owner
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setvalue', path, value, owner, index, id(self))
|
||||
log.debug('setvalue', path, value, owner, index, id(self))
|
||||
values = []
|
||||
vidx = None
|
||||
|
||||
|
@ -101,8 +97,7 @@ class Values(Cache):
|
|||
return: boolean
|
||||
"""
|
||||
has_path = path in self._values[0]
|
||||
if DEBUG: # pragma: no cover
|
||||
print('hasvalue', path, index, has_path, id(self))
|
||||
log.debug('hasvalue', path, index, has_path, id(self))
|
||||
if index is None:
|
||||
return has_path
|
||||
elif has_path:
|
||||
|
@ -115,8 +110,7 @@ class Values(Cache):
|
|||
"""
|
||||
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('reduce_index', path, index, id(self))
|
||||
log.debug('reduce_index', path, index, id(self))
|
||||
path_idx = self._values[0].index(path)
|
||||
# get the "index" position
|
||||
subidx = self._values[1][path_idx].index(index)
|
||||
|
@ -135,8 +129,7 @@ class Values(Cache):
|
|||
path,
|
||||
index,
|
||||
commit):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('resetvalue_index', path, index, id(self))
|
||||
log.debug('resetvalue_index', path, index, id(self))
|
||||
def _resetvalue(nb):
|
||||
values_idx = list(values[nb])
|
||||
del(values_idx[path_idx])
|
||||
|
@ -170,8 +163,7 @@ class Values(Cache):
|
|||
commit):
|
||||
"""remove value means delete value in storage
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('resetvalue', path, id(self))
|
||||
log.debug('resetvalue', path, id(self))
|
||||
def _resetvalue(nb):
|
||||
lst = list(self._values[nb])
|
||||
lst.pop(idx)
|
||||
|
@ -224,8 +216,7 @@ class Values(Cache):
|
|||
with_value)
|
||||
if owner is undefined:
|
||||
owner = default
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getvalue', path, index, value, owner, id(self))
|
||||
log.debug('getvalue', path, index, value, owner, id(self))
|
||||
if with_value:
|
||||
return owner, value
|
||||
else:
|
||||
|
|
|
@ -16,10 +16,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from .sqlite3db import Sqlite3DB
|
||||
|
||||
|
||||
DEBUG=False
|
||||
#DEBUG=True
|
||||
from ...log import log
|
||||
|
||||
|
||||
class Properties(Sqlite3DB):
|
||||
|
@ -84,8 +81,7 @@ class Permissives(Sqlite3DB):
|
|||
# permissive
|
||||
def setpermissives(self, path, permissive):
|
||||
path = self._sqlite_encode_path(path)
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setpermissive', path, permissive, id(self))
|
||||
log.debug('setpermissive', path, permissive, id(self))
|
||||
self._storage.execute("DELETE FROM permissive WHERE path = ? AND session_id = ?",
|
||||
(path, self._session_id),
|
||||
False)
|
||||
|
@ -103,8 +99,7 @@ class Permissives(Sqlite3DB):
|
|||
ret = frozenset()
|
||||
else:
|
||||
ret = frozenset(self._sqlite_decode(permissives[0]))
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getpermissive', path, ret, id(self))
|
||||
log.debug('getpermissive', path, ret, id(self))
|
||||
return ret
|
||||
|
||||
def delpermissive(self, path):
|
||||
|
|
|
@ -16,15 +16,11 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
|
||||
import os
|
||||
from .sqlite3db import Sqlite3DB
|
||||
from .storage import delete_session
|
||||
from ...setting import undefined, owners
|
||||
from ...i18n import _
|
||||
|
||||
|
||||
DEBUG = bool(os.environ.get('TIRAMISU_DEBUG', False))
|
||||
del os
|
||||
from ...log import log
|
||||
|
||||
|
||||
class Values(Sqlite3DB):
|
||||
|
@ -58,8 +54,7 @@ class Values(Sqlite3DB):
|
|||
"""set value for an option
|
||||
a specified value must be associated to an owner
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setvalue', path, value, owner, index, commit)
|
||||
log.debug('setvalue', path, value, owner, index, commit)
|
||||
path = self._sqlite_encode_path(path)
|
||||
if index is not None:
|
||||
self.resetvalue_index(path,
|
||||
|
@ -86,8 +81,7 @@ class Values(Sqlite3DB):
|
|||
"""if opt has a value
|
||||
return: boolean
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('hasvalue', path, index)
|
||||
log.debug('hasvalue', path, index)
|
||||
path = self._sqlite_encode_path(path)
|
||||
return self._sqlite_select(path, index) is not None
|
||||
|
||||
|
@ -97,8 +91,7 @@ class Values(Sqlite3DB):
|
|||
_values == ((path1, path2), ((idx1_1, idx1_2), None),
|
||||
((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('reduce_index', path, index, id(self))
|
||||
log.debug('reduce_index', path, index, id(self))
|
||||
self._storage.execute("UPDATE value SET idx = ? WHERE path = ? and idx = ? "
|
||||
"AND session_id = ?",
|
||||
(index - 1, path, index, self._session_id))
|
||||
|
@ -109,8 +102,7 @@ class Values(Sqlite3DB):
|
|||
commit=True):
|
||||
"""remove value means delete value in storage
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('resetvalue_index', path, index, commit)
|
||||
log.debug('resetvalue_index', path, index, commit)
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ? AND idx = ?",
|
||||
(path, self._session_id, index),
|
||||
|
@ -121,8 +113,7 @@ class Values(Sqlite3DB):
|
|||
commit):
|
||||
"""remove value means delete value in storage
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('resetvalue', path, commit)
|
||||
log.debug('resetvalue', path, commit)
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ?",
|
||||
(path, self._session_id),
|
||||
|
@ -135,8 +126,7 @@ class Values(Sqlite3DB):
|
|||
index=None):
|
||||
"""change owner for an option
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setowner', path, owner, index)
|
||||
log.debug('setowner', path, owner, index)
|
||||
path = self._sqlite_encode_path(path)
|
||||
if index is None:
|
||||
self._storage.execute("UPDATE value SET owner = ? WHERE path = ? AND session_id = ?",
|
||||
|
@ -153,8 +143,7 @@ class Values(Sqlite3DB):
|
|||
"""get owner for an option
|
||||
return: owner object
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getowner', path, default, index, with_value)
|
||||
log.debug('getowner', path, default, index, with_value)
|
||||
path = self._sqlite_encode_path(path)
|
||||
request = "SELECT owner, value FROM value WHERE path = ? AND session_id = ?"
|
||||
if index is not None:
|
||||
|
@ -189,8 +178,7 @@ class Values(Sqlite3DB):
|
|||
:param key: information's key (ex: "help", "doc"
|
||||
:param value: information's value (ex: "the help string")
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('set_information', key, value)
|
||||
log.debug('set_information', key, value)
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM information WHERE key = ? AND session_id = ? AND path = ?",
|
||||
(key, self._session_id, path),
|
||||
|
@ -203,8 +191,7 @@ class Values(Sqlite3DB):
|
|||
|
||||
:param key: the item string (ex: "help")
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('get_information', key, default)
|
||||
log.debug('get_information', key, default)
|
||||
path = self._sqlite_encode_path(path)
|
||||
value = self._storage.select("SELECT value FROM information WHERE key = ? AND "
|
||||
"session_id = ? AND path = ?",
|
||||
|
@ -218,8 +205,7 @@ class Values(Sqlite3DB):
|
|||
return self._sqlite_decode(value[0])
|
||||
|
||||
def del_information(self, path, key, raises):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('del_information', key, raises)
|
||||
log.debug('del_information', key, raises)
|
||||
path = self._sqlite_encode_path(path)
|
||||
if raises and self._storage.select("SELECT value FROM information WHERE key = ? "
|
||||
"AND session_id = ? AND path = ?",
|
||||
|
@ -241,8 +227,7 @@ class Values(Sqlite3DB):
|
|||
(self._session_id,))
|
||||
|
||||
def exportation(self):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('exportation')
|
||||
log.debug('exportation')
|
||||
rows = self._storage.select("SELECT path, value, owner, idx FROM value WHERE "
|
||||
"session_id = ?;", (self._session_id,), only_one=False)
|
||||
ret = [[], [], [], []]
|
||||
|
@ -271,8 +256,7 @@ class Values(Sqlite3DB):
|
|||
return ret
|
||||
|
||||
def importation(self, export):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('importation')
|
||||
log.debug('importation')
|
||||
request = "DELETE FROM value WHERE session_id = ?"
|
||||
self._storage.execute(request, (self._session_id,),
|
||||
commit=False)
|
||||
|
@ -298,8 +282,7 @@ class Values(Sqlite3DB):
|
|||
|
||||
def get_max_length(self,
|
||||
path):
|
||||
if DEBUG: # pragma: no cover
|
||||
print('get_max_length', path)
|
||||
log.debug('get_max_length', path)
|
||||
val_max = self._storage.select("SELECT max(idx) FROM value WHERE path = ? AND session_id = ?",
|
||||
(path, self._session_id), False)
|
||||
if val_max[0][0] is None:
|
||||
|
|
|
@ -15,17 +15,14 @@
|
|||
# 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/>.
|
||||
# ____________________________________________________________
|
||||
import os
|
||||
from time import time
|
||||
from .cache.dictionary import Cache as DictCache
|
||||
from ..log import log
|
||||
|
||||
|
||||
def _display_classname(obj): # pragma: no cover
|
||||
return(obj.__class__.__name__.lower())
|
||||
|
||||
DEBUG = bool(os.environ.get('TIRAMISU_DEBUG', False))
|
||||
del os
|
||||
|
||||
|
||||
class Cache(DictCache):
|
||||
__slots__ = ('_storage',)
|
||||
|
@ -39,13 +36,11 @@ class Cache(DictCache):
|
|||
if follower, add index
|
||||
"""
|
||||
if 'cache' in props or 'cache' in self_props:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setcache {} with index {} and value {} in {} ({})'.format(path, index, val,
|
||||
log.debug('setcache {} with index {} and value {} in {} ({})'.format(path, index, val,
|
||||
_display_classname(self),
|
||||
id(self)))
|
||||
self._setcache(path, index, val, time())
|
||||
elif DEBUG: # pragma: no cover
|
||||
print('not setcache {} with index {} and value {} and props {} and {} in {} ({})'.format(path,
|
||||
log.debug('not setcache {} with index {} and value {} and props {} and {} in {} ({})'.format(path,
|
||||
index,
|
||||
val,
|
||||
props,
|
||||
|
@ -80,38 +75,32 @@ class Cache(DictCache):
|
|||
'expire' in self_props):
|
||||
ntime = int(time())
|
||||
if timestamp + expiration_time >= ntime:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache in cache (1)', path, value, _display_classname(self),
|
||||
log.debug('getcache in cache (1)', path, value, _display_classname(self),
|
||||
id(self), index)
|
||||
return True, value
|
||||
else:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache expired value for path {} < {}'.format(
|
||||
timestamp + expiration_time, ntime))
|
||||
log.debug('getcache expired value for path {} < {}'.format(
|
||||
timestamp + expiration_time, ntime))
|
||||
# if expired, remove from cache
|
||||
#self.delcache(path)
|
||||
else:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache in cache (2)', path, value, _display_classname(self),
|
||||
log.debug('getcache in cache (2)', path, value, _display_classname(self),
|
||||
id(self), index)
|
||||
return True, value
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache {} with index {} not in {} cache'.format(path, index,
|
||||
log.debug('getcache {} with index {} not in {} cache'.format(path, index,
|
||||
_display_classname(self)))
|
||||
return no_cache
|
||||
|
||||
def delcache(self, path):
|
||||
"""remove cache for a specified path
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('delcache', path, _display_classname(self), id(self))
|
||||
log.debug('delcache', path, _display_classname(self), id(self))
|
||||
if path in self._cache:
|
||||
self._delcache(path)
|
||||
|
||||
def reset_all_cache(self):
|
||||
"empty the cache"
|
||||
if DEBUG: # pragma: no cover
|
||||
print('reset_all_cache', _display_classname(self), id(self))
|
||||
log.debug('reset_all_cache', _display_classname(self), id(self))
|
||||
self._reset_all_cache()
|
||||
|
||||
def get_cached(self):
|
||||
|
@ -119,6 +108,5 @@ class Cache(DictCache):
|
|||
please only use it in test purpose
|
||||
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
|
||||
"""
|
||||
if DEBUG: # pragma: no cover
|
||||
print('get_chached {} for {} ({})'.format(self._cache, _display_classname(self), id(self)))
|
||||
log.debug('get_chached {} for {} ({})'.format(self._cache, _display_classname(self), id(self)))
|
||||
return self._get_cached()
|
||||
|
|
Loading…
Reference in a new issue