change None to undefined when it's needed
This commit is contained in:
parent
3ab0688c46
commit
aa0734591d
|
@ -10,3 +10,4 @@ Sat Apr 12 11:37:27 CEST 2014 Emmanuel Garette <egarette@cadoles.com>
|
||||||
object MasterSlaves for all code related to master/slaves options
|
object MasterSlaves for all code related to master/slaves options
|
||||||
* tiramisu/option/masterslave.py: master and slaves values (length,
|
* tiramisu/option/masterslave.py: master and slaves values (length,
|
||||||
consistency, ...) are now check every time
|
consistency, ...) are now check every time
|
||||||
|
* change None to undefined when needed
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
import weakref
|
import weakref
|
||||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||||
from tiramisu.option import OptionDescription, Option, SymLinkOption
|
from tiramisu.option import OptionDescription, Option, SymLinkOption
|
||||||
from tiramisu.setting import groups, Settings, default_encoding
|
from tiramisu.setting import groups, Settings, default_encoding, undefined
|
||||||
from tiramisu.storage import get_storages, get_storage, set_storage, \
|
from tiramisu.storage import get_storages, get_storage, set_storage, \
|
||||||
_impl_getstate_setting
|
_impl_getstate_setting
|
||||||
from tiramisu.value import Values, Multi
|
from tiramisu.value import Values, Multi
|
||||||
|
@ -256,7 +256,7 @@ class SubConfig(object):
|
||||||
validate=validate,
|
validate=validate,
|
||||||
force_permissive=force_permissive)
|
force_permissive=force_permissive)
|
||||||
|
|
||||||
def find(self, bytype=None, byname=None, byvalue=None, type_='option',
|
def find(self, bytype=None, byname=None, byvalue=undefined, type_='option',
|
||||||
check_properties=True, force_permissive=False):
|
check_properties=True, force_permissive=False):
|
||||||
"""
|
"""
|
||||||
finds a list of options recursively in the config
|
finds a list of options recursively in the config
|
||||||
|
@ -273,7 +273,7 @@ class SubConfig(object):
|
||||||
check_properties=check_properties,
|
check_properties=check_properties,
|
||||||
force_permissive=force_permissive)
|
force_permissive=force_permissive)
|
||||||
|
|
||||||
def find_first(self, bytype=None, byname=None, byvalue=None,
|
def find_first(self, bytype=None, byname=None, byvalue=undefined,
|
||||||
type_='option', display_error=True, check_properties=True,
|
type_='option', display_error=True, check_properties=True,
|
||||||
force_permissive=False):
|
force_permissive=False):
|
||||||
"""
|
"""
|
||||||
|
@ -306,7 +306,7 @@ class SubConfig(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _filter_by_value():
|
def _filter_by_value():
|
||||||
if byvalue is None:
|
if byvalue is undefined:
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
value = self.getattr(path, force_permissive=force_permissive)
|
value = self.getattr(path, force_permissive=force_permissive)
|
||||||
|
@ -344,7 +344,7 @@ class SubConfig(object):
|
||||||
if not _filter_by_type():
|
if not _filter_by_type():
|
||||||
continue
|
continue
|
||||||
#remove option with propertyerror, ...
|
#remove option with propertyerror, ...
|
||||||
if byvalue is None and check_properties:
|
if byvalue is undefined and check_properties:
|
||||||
try:
|
try:
|
||||||
value = self.getattr(path,
|
value = self.getattr(path,
|
||||||
force_permissive=force_permissive)
|
force_permissive=force_permissive)
|
||||||
|
@ -375,7 +375,7 @@ class SubConfig(object):
|
||||||
return find_results
|
return find_results
|
||||||
|
|
||||||
def make_dict(self, flatten=False, _currpath=None, withoption=None,
|
def make_dict(self, flatten=False, _currpath=None, withoption=None,
|
||||||
withvalue=None, force_permissive=False):
|
withvalue=undefined, force_permissive=False):
|
||||||
"""exports the whole config into a `dict`, for example:
|
"""exports the whole config into a `dict`, for example:
|
||||||
|
|
||||||
>>> print cfg.make_dict()
|
>>> print cfg.make_dict()
|
||||||
|
@ -415,7 +415,7 @@ class SubConfig(object):
|
||||||
pathsvalues = []
|
pathsvalues = []
|
||||||
if _currpath is None:
|
if _currpath is None:
|
||||||
_currpath = []
|
_currpath = []
|
||||||
if withoption is None and withvalue is not None:
|
if withoption is None and withvalue is not undefined:
|
||||||
raise ValueError(_("make_dict can't filtering with value without "
|
raise ValueError(_("make_dict can't filtering with value without "
|
||||||
"option"))
|
"option"))
|
||||||
if withoption is not None:
|
if withoption is not None:
|
||||||
|
@ -433,7 +433,7 @@ class SubConfig(object):
|
||||||
if mypath is not None:
|
if mypath is not None:
|
||||||
if mypath == path:
|
if mypath == path:
|
||||||
withoption = None
|
withoption = None
|
||||||
withvalue = None
|
withvalue = undefined
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
tmypath = mypath + '.'
|
tmypath = mypath + '.'
|
||||||
|
@ -535,7 +535,7 @@ class _CommonConfig(SubConfig):
|
||||||
"""
|
"""
|
||||||
self._impl_values.set_information(key, value)
|
self._impl_values.set_information(key, value)
|
||||||
|
|
||||||
def impl_get_information(self, key, default=None):
|
def impl_get_information(self, key, default=undefined):
|
||||||
"""retrieves one information's item
|
"""retrieves one information's item
|
||||||
|
|
||||||
:param key: the item string (ex: "help")
|
:param key: the item string (ex: "help")
|
||||||
|
@ -661,7 +661,7 @@ class GroupConfig(_CommonConfig):
|
||||||
except PropertiesOptionError:
|
except PropertiesOptionError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def find_firsts(self, byname=None, bypath=None, byvalue=None,
|
def find_firsts(self, byname=None, bypath=None, byvalue=undefined,
|
||||||
type_='path', display_error=True):
|
type_='path', display_error=True):
|
||||||
"""Find first not in current GroupConfig, but in each children
|
"""Find first not in current GroupConfig, but in each children
|
||||||
"""
|
"""
|
||||||
|
@ -671,7 +671,7 @@ class GroupConfig(_CommonConfig):
|
||||||
try:
|
try:
|
||||||
if bypath is None and byname is not None and \
|
if bypath is None and byname is not None and \
|
||||||
isinstance(self, MetaConfig):
|
isinstance(self, MetaConfig):
|
||||||
bypath = self._find(bytype=None, byvalue=None, byname=byname,
|
bypath = self._find(bytype=None, byvalue=undefined, byname=byname,
|
||||||
first=True, type_='path',
|
first=True, type_='path',
|
||||||
check_properties=False,
|
check_properties=False,
|
||||||
display_error=display_error)
|
display_error=display_error)
|
||||||
|
@ -684,7 +684,7 @@ class GroupConfig(_CommonConfig):
|
||||||
if bypath is not None:
|
if bypath is not None:
|
||||||
#if byvalue is None, try if not raise
|
#if byvalue is None, try if not raise
|
||||||
value = getattr(child, bypath)
|
value = getattr(child, bypath)
|
||||||
if byvalue is not None:
|
if byvalue is not undefined:
|
||||||
if isinstance(value, Multi):
|
if isinstance(value, Multi):
|
||||||
if byvalue in value:
|
if byvalue in value:
|
||||||
ret.append(child)
|
ret.append(child)
|
||||||
|
|
|
@ -24,7 +24,7 @@ from types import FunctionType
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from tiramisu.i18n import _
|
from tiramisu.i18n import _
|
||||||
from tiramisu.setting import log
|
from tiramisu.setting import log, undefined
|
||||||
from tiramisu.autolib import carry_out_calculation
|
from tiramisu.autolib import carry_out_calculation
|
||||||
from tiramisu.error import ConfigError, ValueWarning
|
from tiramisu.error import ConfigError, ValueWarning
|
||||||
|
|
||||||
|
@ -164,14 +164,14 @@ class BaseOption(object):
|
||||||
"""
|
"""
|
||||||
self._impl_informations[key] = value
|
self._impl_informations[key] = value
|
||||||
|
|
||||||
def impl_get_information(self, key, default=None):
|
def impl_get_information(self, key, default=undefined):
|
||||||
"""retrieves one information's item
|
"""retrieves one information's item
|
||||||
|
|
||||||
:param key: the item string (ex: "help")
|
:param key: the item string (ex: "help")
|
||||||
"""
|
"""
|
||||||
if key in self._impl_informations:
|
if key in self._impl_informations:
|
||||||
return self._impl_informations[key]
|
return self._impl_informations[key]
|
||||||
elif default is not None:
|
elif default is not undefined:
|
||||||
return default
|
return default
|
||||||
else:
|
else:
|
||||||
raise ValueError(_("information's item not found: {0}").format(
|
raise ValueError(_("information's item not found: {0}").format(
|
||||||
|
|
|
@ -396,7 +396,7 @@ class Values(object):
|
||||||
"""
|
"""
|
||||||
self._p_.set_information(key, value)
|
self._p_.set_information(key, value)
|
||||||
|
|
||||||
def get_information(self, key, default=None):
|
def get_information(self, key, default=undefined):
|
||||||
"""retrieves one information's item
|
"""retrieves one information's item
|
||||||
|
|
||||||
:param key: the item string (ex: "help")
|
:param key: the item string (ex: "help")
|
||||||
|
@ -404,7 +404,7 @@ class Values(object):
|
||||||
try:
|
try:
|
||||||
return self._p_.get_information(key)
|
return self._p_.get_information(key)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if default is not None:
|
if default is not undefined:
|
||||||
return default
|
return default
|
||||||
else:
|
else:
|
||||||
raise ValueError(_("information's item"
|
raise ValueError(_("information's item"
|
||||||
|
|
Loading…
Reference in New Issue