python 3 compatibility
remove __eq__ and __ne__ in Option
This commit is contained in:
parent
fc9aa7fad5
commit
fbf05ba5e4
|
@ -9,6 +9,7 @@ from py.test import raises
|
||||||
from tiramisu.config import Config
|
from tiramisu.config import Config
|
||||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||||
BoolOption, UnicodeOption, OptionDescription
|
BoolOption, UnicodeOption, OptionDescription
|
||||||
|
from tiramisu.error import ConflictError
|
||||||
|
|
||||||
|
|
||||||
def make_description():
|
def make_description():
|
||||||
|
@ -199,3 +200,14 @@ def test_values_not_setitem():
|
||||||
root = OptionDescription('root', '', [d1])
|
root = OptionDescription('root', '', [d1])
|
||||||
config = Config(root)
|
config = Config(root)
|
||||||
raises(ValueError, "config.cfgimpl_get_values()[g1] = 2")
|
raises(ValueError, "config.cfgimpl_get_values()[g1] = 2")
|
||||||
|
|
||||||
|
|
||||||
|
def test_duplicated_option():
|
||||||
|
g1 = IntOption('g1', '', 1)
|
||||||
|
#in same OptionDescription
|
||||||
|
raises(ConflictError, "d1 = OptionDescription('od', '', [g1, g1])")
|
||||||
|
d1 = OptionDescription('od1', '', [g1])
|
||||||
|
d2 = OptionDescription('od2', '', [g1])
|
||||||
|
root = OptionDescription('root', '', [d1, d2])
|
||||||
|
#in different OptionDescription
|
||||||
|
raises(ConflictError, "config = Config(root)")
|
||||||
|
|
|
@ -44,7 +44,7 @@ def test_freeze_whole_config():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
conf.gc.dummy = True
|
conf.gc.dummy = True
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'frozen' in prop
|
assert 'frozen' in prop
|
||||||
setting.remove('everything_frozen')
|
setting.remove('everything_frozen')
|
||||||
|
@ -65,7 +65,7 @@ def test_freeze_one_option():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
conf.gc.dummy = True
|
conf.gc.dummy = True
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'frozen' in prop
|
assert 'frozen' in prop
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ def test_frozen_value():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.string = "egg"
|
config.string = "egg"
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'frozen' in prop
|
assert 'frozen' in prop
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ def test_freeze():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
conf.gc.name = 'framework'
|
conf.gc.name = 'framework'
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'frozen' in prop
|
assert 'frozen' in prop
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ def test_freeze_multi():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
conf.boolop = [True]
|
conf.boolop = [True]
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'frozen' in prop
|
assert 'frozen' in prop
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ def test_freeze_get_multi():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
valmulti.append(False)
|
valmulti.append(False)
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'frozen' in prop
|
assert 'frozen' in prop
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import autopath
|
||||||
|
|
||||||
#from py.test import raises
|
#from py.test import raises
|
||||||
from tiramisu.config import Config, mandatory_warnings
|
from tiramisu.config import Config, mandatory_warnings
|
||||||
from tiramisu.option import StrOption, OptionDescription, UnicodeOption
|
from tiramisu.option import StrOption, UnicodeOption, OptionDescription
|
||||||
from tiramisu.error import PropertiesOptionError
|
from tiramisu.error import PropertiesOptionError
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ def test_mandatory_ro():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str1
|
config.str1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
config.read_write()
|
config.read_write()
|
||||||
|
@ -61,7 +61,7 @@ def test_mandatory_default():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str
|
config.str
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ def test_mandatory_none():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str1
|
config.str1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ def test_mandatory_empty():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str1
|
config.str1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ def test_mandatory_multi_none():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str3
|
config.str3
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
config.read_write()
|
config.read_write()
|
||||||
|
@ -114,7 +114,7 @@ def test_mandatory_multi_none():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str3
|
config.str3
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ def test_mandatory_multi_empty():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str3
|
config.str3
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
config.read_write()
|
config.read_write()
|
||||||
|
@ -138,7 +138,7 @@ def test_mandatory_multi_empty():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str3
|
config.str3
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'mandatory' in prop
|
assert 'mandatory' in prop
|
||||||
|
|
||||||
|
@ -160,16 +160,16 @@ def test_mandatory_disabled():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str1
|
config.str1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert prop == ['mandatory']
|
assert prop == ['mandatory']
|
||||||
setting[descr.str1].append('disabled')
|
setting[descr.str1].append('disabled')
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.str1
|
config.str1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert prop == ['disabled', 'mandatory']
|
assert set(prop) == set(['disabled', 'mandatory'])
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory_unicode():
|
def test_mandatory_unicode():
|
||||||
|
@ -180,7 +180,7 @@ def test_mandatory_unicode():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.unicode2
|
config.unicode2
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert prop == ['mandatory']
|
assert prop == ['mandatory']
|
||||||
config.read_write()
|
config.read_write()
|
||||||
|
@ -189,7 +189,7 @@ def test_mandatory_unicode():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.unicode2
|
config.unicode2
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert prop == ['mandatory']
|
assert prop == ['mandatory']
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ def test_mandatory_warnings_ro():
|
||||||
proc = []
|
proc = []
|
||||||
try:
|
try:
|
||||||
config.str
|
config.str
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
proc = err.proptype
|
proc = err.proptype
|
||||||
assert proc == ['mandatory']
|
assert proc == ['mandatory']
|
||||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
||||||
|
|
|
@ -6,33 +6,33 @@ import autopath
|
||||||
from tiramisu.option import BoolOption, IntOption
|
from tiramisu.option import BoolOption, IntOption
|
||||||
|
|
||||||
|
|
||||||
def test_option_comparison():
|
#def test_option_comparison():
|
||||||
"compare :class:`tiramisu.option.BoolOption`"
|
# "compare :class:`tiramisu.option.BoolOption`"
|
||||||
dummy1 = BoolOption('dummy1', 'doc dummy')
|
# dummy1 = BoolOption('dummy1', 'doc dummy')
|
||||||
dummy2 = BoolOption('dummy2', 'doc dummy')
|
# dummy2 = BoolOption('dummy2', 'doc dummy')
|
||||||
dummy3 = BoolOption('dummy1', 'doc dummy')
|
# dummy3 = BoolOption('dummy1', 'doc dummy')
|
||||||
assert dummy1 != dummy2
|
# assert dummy1 != dummy2
|
||||||
assert dummy1 == dummy3
|
# assert dummy1 == dummy3
|
||||||
|
|
||||||
|
|
||||||
def test_option_comparison_obj():
|
#def test_option_comparison_obj():
|
||||||
"compare :class:`tiramisu.option.IntOption`"
|
# "compare :class:`tiramisu.option.IntOption`"
|
||||||
dummy1 = BoolOption('dummy1', 'doc dummy')
|
# dummy1 = BoolOption('dummy1', 'doc dummy')
|
||||||
dummy2 = IntOption('dummy1', 'doc dummy')
|
# dummy2 = IntOption('dummy1', 'doc dummy')
|
||||||
assert dummy1 != dummy2
|
# assert dummy1 != dummy2
|
||||||
|
|
||||||
|
|
||||||
def test_option_comparison_advanced():
|
#def test_option_comparison_advanced():
|
||||||
dummy1 = BoolOption('dummy1', 'doc dummy')
|
# dummy1 = BoolOption('dummy1', 'doc dummy')
|
||||||
dummy2 = BoolOption('dummy1', 'doc dummy')
|
# dummy2 = BoolOption('dummy1', 'doc dummy')
|
||||||
dummy3 = BoolOption('dummy1', 'doc dummy', None)
|
# dummy3 = BoolOption('dummy1', 'doc dummy', None)
|
||||||
dummy4 = BoolOption('dummy1', 'doc dummy', True)
|
# dummy4 = BoolOption('dummy1', 'doc dummy', True)
|
||||||
dummy5 = BoolOption('dummy1', 'doc dummy', multi=True)
|
# dummy5 = BoolOption('dummy1', 'doc dummy', multi=True)
|
||||||
dummy6 = BoolOption('dummy1', 'doc dummy', properties=tuple())
|
# dummy6 = BoolOption('dummy1', 'doc dummy', properties=tuple())
|
||||||
dummy7 = BoolOption('dummy1', 'doc dummy', properties=tuple('new',))
|
# dummy7 = BoolOption('dummy1', 'doc dummy', properties=tuple('new',))
|
||||||
assert dummy1 == dummy2
|
# assert dummy1 == dummy2
|
||||||
assert dummy1 == dummy3
|
# assert dummy1 == dummy3
|
||||||
assert dummy1 != dummy4
|
# assert dummy1 != dummy4
|
||||||
assert dummy1 != dummy5
|
# assert dummy1 != dummy5
|
||||||
assert dummy1 == dummy6
|
# assert dummy1 == dummy6
|
||||||
assert dummy1 != dummy7
|
# assert dummy1 != dummy7
|
||||||
|
|
|
@ -71,7 +71,7 @@ def test_group_is_hidden():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
config.gc.dummy = False
|
config.gc.dummy = False
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'hidden' in prop
|
assert 'hidden' in prop
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ def test_group_is_hidden_multi():
|
||||||
prop = []
|
prop = []
|
||||||
try:
|
try:
|
||||||
objspace.append('std')
|
objspace.append('std')
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
prop = err.proptype
|
prop = err.proptype
|
||||||
assert 'hidden' in prop
|
assert 'hidden' in prop
|
||||||
setting[obj].remove('hidden')
|
setting[obj].remove('hidden')
|
||||||
|
|
|
@ -20,14 +20,14 @@ def test_permissive():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
config.u1
|
config.u1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
setting.setpermissive(('disabled',))
|
setting.setpermissive(('disabled',))
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
config.u1
|
config.u1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
setting.append('permissive')
|
setting.append('permissive')
|
||||||
|
@ -36,7 +36,7 @@ def test_permissive():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
config.u1
|
config.u1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -49,18 +49,18 @@ def test_permissive_mandatory():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
config.u1
|
config.u1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled', 'mandatory']
|
assert set(props) == set(['disabled', 'mandatory'])
|
||||||
setting.setpermissive(('mandatory', 'disabled',))
|
setting.setpermissive(('mandatory', 'disabled',))
|
||||||
setting.append('permissive')
|
setting.append('permissive')
|
||||||
config.u1
|
config.u1
|
||||||
setting.remove('permissive')
|
setting.remove('permissive')
|
||||||
try:
|
try:
|
||||||
config.u1
|
config.u1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled', 'mandatory']
|
assert set(props) == set(['disabled', 'mandatory'])
|
||||||
|
|
||||||
|
|
||||||
def test_permissive_frozen():
|
def test_permissive_frozen():
|
||||||
|
@ -71,7 +71,7 @@ def test_permissive_frozen():
|
||||||
setting.setpermissive(('frozen', 'disabled',))
|
setting.setpermissive(('frozen', 'disabled',))
|
||||||
try:
|
try:
|
||||||
config.u1 = 1
|
config.u1 = 1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['frozen', 'disabled']
|
assert props == ['frozen', 'disabled']
|
||||||
setting.append('permissive')
|
setting.append('permissive')
|
||||||
|
@ -80,7 +80,7 @@ def test_permissive_frozen():
|
||||||
setting.remove('permissive')
|
setting.remove('permissive')
|
||||||
try:
|
try:
|
||||||
config.u1 = 1
|
config.u1 = 1
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['frozen', 'disabled']
|
assert props == ['frozen', 'disabled']
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ def test_requires():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -47,14 +47,14 @@ def test_requires_same_action():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.activate_service_web
|
c.activate_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['new']
|
assert props == ['new']
|
||||||
#
|
#
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service_web
|
c.ip_address_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ def test_multiple_requires():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ def test_multiple_requires():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ def test_multiple_requires_inverse():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ def test_multiple_requires_inverse():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -136,14 +136,14 @@ def test_requires_transitive():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.activate_service_web
|
c.activate_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
#
|
#
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service_web
|
c.ip_address_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -167,14 +167,14 @@ def test_requires_transitive_bis():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.activate_service_web
|
c.activate_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
#
|
#
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service_web
|
c.ip_address_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ def test_requires_transitive_hidden_disabled():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.activate_service_web
|
c.activate_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['hidden']
|
assert props == ['hidden']
|
||||||
raises(RequirementError, 'c.ip_address_service_web')
|
raises(RequirementError, 'c.ip_address_service_web')
|
||||||
|
@ -220,7 +220,7 @@ def test_requires_not_transitive():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.activate_service_web
|
c.activate_service_web
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
#
|
#
|
||||||
|
@ -237,7 +237,7 @@ def test_requires_None():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
c.activate_service = False
|
c.activate_service = False
|
||||||
|
@ -260,7 +260,7 @@ def test_requires_multi_disabled():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ def test_requires_multi_disabled():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ def test_requires_multi_disabled():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ def test_requires_multi_disabled_inverse():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ def test_requires_multi_disabled_inverse():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ def test_requires_multi_disabled_inverse():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ def test_requires_multi_disabled_inverse():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
c.ip_address_service
|
c.ip_address_service
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ def test_requires_multi_disabled_2():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
cfg.z
|
cfg.z
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
for boo in list_bools:
|
for boo in list_bools:
|
||||||
|
@ -373,7 +373,7 @@ def test_requires_multi_disabled_2():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
cfg.z
|
cfg.z
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ def test_requires_multi_disabled_inverse_2():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
cfg.z
|
cfg.z
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
for boo in list_bools:
|
for boo in list_bools:
|
||||||
|
@ -418,7 +418,7 @@ def test_requires_multi_disabled_inverse_2():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
cfg.z
|
cfg.z
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
for boo in list_bools:
|
for boo in list_bools:
|
||||||
|
@ -426,7 +426,7 @@ def test_requires_multi_disabled_inverse_2():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
cfg.z
|
cfg.z
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,14 @@ def test_symlink_requires():
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
config.s
|
config.s
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
#
|
#
|
||||||
props = []
|
props = []
|
||||||
try:
|
try:
|
||||||
config.c
|
config.c
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
props = err.proptype
|
props = err.proptype
|
||||||
assert props == ['disabled']
|
assert props == ['disabled']
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ def test_symlink_master():
|
||||||
|
|
||||||
def test_symlink_slaves():
|
def test_symlink_slaves():
|
||||||
a = StrOption('a', "", multi=True)
|
a = StrOption('a', "", multi=True)
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', u"ip réseau autorisé", multi=True)
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||||
netmask_admin_eth0 = SymLinkOption('netmask_admin_eth0', a)
|
netmask_admin_eth0 = SymLinkOption('netmask_admin_eth0', a)
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
raises(ValueError, 'interface1.impl_set_group_type(groups.master)')
|
raises(ValueError, 'interface1.impl_set_group_type(groups.master)')
|
||||||
|
|
|
@ -59,7 +59,7 @@ def carry_out_calculation(name,
|
||||||
try:
|
try:
|
||||||
opt_value = config._getattr(path, force_permissive=True)
|
opt_value = config._getattr(path, force_permissive=True)
|
||||||
opt = config.unwrap_from_path(path, force_permissive=True)
|
opt = config.unwrap_from_path(path, force_permissive=True)
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
if check_disabled:
|
if check_disabled:
|
||||||
continue
|
continue
|
||||||
raise ConfigError(_('unable to carry out a calculation, '
|
raise ConfigError(_('unable to carry out a calculation, '
|
||||||
|
|
|
@ -646,7 +646,7 @@ def mandatory_warnings(config):
|
||||||
include_groups=True):
|
include_groups=True):
|
||||||
try:
|
try:
|
||||||
config._getattr(path, force_properties=frozenset(('mandatory',)))
|
config._getattr(path, force_properties=frozenset(('mandatory',)))
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
if err.proptype == ['mandatory']:
|
if err.proptype == ['mandatory']:
|
||||||
yield path
|
yield path
|
||||||
config.cfgimpl_reset_cache(only=('values',))
|
config.cfgimpl_reset_cache(only=('values',))
|
||||||
|
|
|
@ -32,28 +32,28 @@ class PropertiesOptionError(AttributeError):
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
# Exceptions for a Config
|
# Exceptions for a Config
|
||||||
class ConfigError(StandardError):
|
class ConfigError(Exception):
|
||||||
"""attempt to change an option's owner without a value
|
"""attempt to change an option's owner without a value
|
||||||
or in case of `_cfgimpl_descr` is None
|
or in case of `_cfgimpl_descr` is None
|
||||||
or if a calculation cannot be carried out"""
|
or if a calculation cannot be carried out"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConflictError(StandardError):
|
class ConflictError(Exception):
|
||||||
"duplicate options are present in a single config"
|
"duplicate options are present in a single config"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
# miscellaneous exceptions
|
# miscellaneous exceptions
|
||||||
class RequirementError(StandardError):
|
class RequirementError(Exception):
|
||||||
"""a recursive loop occurs in the requirements tree
|
"""a recursive loop occurs in the requirements tree
|
||||||
requires
|
requires
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SlaveError(StandardError):
|
class SlaveError(Exception):
|
||||||
"problem with a slave's value length"
|
"problem with a slave's value length"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,11 @@ if lc:
|
||||||
languages += DEFAULT_LANG
|
languages += DEFAULT_LANG
|
||||||
mo_location = LOCALE_DIR
|
mo_location = LOCALE_DIR
|
||||||
|
|
||||||
gettext.install(True, localedir=None, unicode=1)
|
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
gettext.install(True, localedir=None)
|
||||||
|
else:
|
||||||
|
gettext.install(True, localedir=None, unicode=1)
|
||||||
gettext.find(APP_NAME, mo_location)
|
gettext.find(APP_NAME, mo_location)
|
||||||
gettext.textdomain(APP_NAME)
|
gettext.textdomain(APP_NAME)
|
||||||
gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")
|
gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
from types import FunctionType
|
from types import FunctionType
|
||||||
from IPy import IP
|
from IPy import IP
|
||||||
|
@ -98,7 +99,7 @@ class Option(BaseInformation):
|
||||||
"""
|
"""
|
||||||
__slots__ = ('_name', '_requires', '_multi', '_validator',
|
__slots__ = ('_name', '_requires', '_multi', '_validator',
|
||||||
'_default_multi', '_default', '_properties', '_callback',
|
'_default_multi', '_default', '_properties', '_callback',
|
||||||
'_multitype', '_master_slaves', '_consistencies', '_empty',
|
'_multitype', '_master_slaves', '_consistencies',
|
||||||
'_calc_properties', '__weakref__')
|
'_calc_properties', '__weakref__')
|
||||||
_empty = ''
|
_empty = ''
|
||||||
|
|
||||||
|
@ -147,7 +148,7 @@ class Option(BaseInformation):
|
||||||
if default_multi is not None:
|
if default_multi is not None:
|
||||||
try:
|
try:
|
||||||
self._validate(default_multi)
|
self._validate(default_multi)
|
||||||
except ValueError, err:
|
except ValueError as err:
|
||||||
raise ValueError(_("invalid default_multi value {0} "
|
raise ValueError(_("invalid default_multi value {0} "
|
||||||
"for option {1}: {2}").format(
|
"for option {1}: {2}").format(
|
||||||
str(default_multi), name, err))
|
str(default_multi), name, err))
|
||||||
|
@ -184,36 +185,6 @@ class Option(BaseInformation):
|
||||||
self._name))
|
self._name))
|
||||||
self._properties = properties # 'hidden', 'disabled'...
|
self._properties = properties # 'hidden', 'disabled'...
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
"Option comparison"
|
|
||||||
if not isinstance(other, Option):
|
|
||||||
return False
|
|
||||||
slots = list(self.__slots__ +
|
|
||||||
Option.__slots__ +
|
|
||||||
BaseInformation.__slots__)
|
|
||||||
for var in slots:
|
|
||||||
try:
|
|
||||||
val1 = getattr(self, var)
|
|
||||||
not_in1 = False
|
|
||||||
except:
|
|
||||||
not_in1 = True
|
|
||||||
try:
|
|
||||||
val2 = getattr(other, var)
|
|
||||||
not_in2 = False
|
|
||||||
except:
|
|
||||||
not_in2 = True
|
|
||||||
if True in (not_in1, not_in2):
|
|
||||||
if not_in1 != not_in2:
|
|
||||||
return False
|
|
||||||
elif val1 != val2:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
if not isinstance(other, Option):
|
|
||||||
return False
|
|
||||||
return not self == other
|
|
||||||
|
|
||||||
def _launch_consistency(self, func, opt, vals, context, index, opt_):
|
def _launch_consistency(self, func, opt, vals, context, index, opt_):
|
||||||
if context is not None:
|
if context is not None:
|
||||||
descr = context.cfgimpl_get_description()
|
descr = context.cfgimpl_get_description()
|
||||||
|
@ -288,7 +259,7 @@ class Option(BaseInformation):
|
||||||
self.__class__.__name__))
|
self.__class__.__name__))
|
||||||
try:
|
try:
|
||||||
self._validate(_value)
|
self._validate(_value)
|
||||||
except ValueError, err:
|
except ValueError as err:
|
||||||
raise ValueError(_("invalid value {0} for option {1}: {2}"
|
raise ValueError(_("invalid value {0} for option {1}: {2}"
|
||||||
"").format(_value, self._name, err))
|
"").format(_value, self._name, err))
|
||||||
if context is not None:
|
if context is not None:
|
||||||
|
@ -381,7 +352,7 @@ class ChoiceOption(Option):
|
||||||
The option can also have the value ``None``
|
The option can also have the value ``None``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ('_values', '_open_values', '_opt_type')
|
__slots__ = ('_values', '_open_values')
|
||||||
_opt_type = 'string'
|
_opt_type = 'string'
|
||||||
|
|
||||||
def __init__(self, name, doc, values, default=None, default_multi=None,
|
def __init__(self, name, doc, values, default=None, default_multi=None,
|
||||||
|
@ -423,7 +394,7 @@ class ChoiceOption(Option):
|
||||||
|
|
||||||
class BoolOption(Option):
|
class BoolOption(Option):
|
||||||
"represents a choice between ``True`` and ``False``"
|
"represents a choice between ``True`` and ``False``"
|
||||||
__slots__ = ('_opt_type',)
|
__slots__ = tuple()
|
||||||
_opt_type = 'bool'
|
_opt_type = 'bool'
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
|
@ -433,7 +404,7 @@ class BoolOption(Option):
|
||||||
|
|
||||||
class IntOption(Option):
|
class IntOption(Option):
|
||||||
"represents a choice of an integer"
|
"represents a choice of an integer"
|
||||||
__slots__ = ('_opt_type',)
|
__slots__ = tuple()
|
||||||
_opt_type = 'int'
|
_opt_type = 'int'
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
|
@ -443,7 +414,7 @@ class IntOption(Option):
|
||||||
|
|
||||||
class FloatOption(Option):
|
class FloatOption(Option):
|
||||||
"represents a choice of a floating point number"
|
"represents a choice of a floating point number"
|
||||||
__slots__ = ('_opt_type',)
|
__slots__ = tuple()
|
||||||
_opt_type = 'float'
|
_opt_type = 'float'
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
|
@ -453,7 +424,7 @@ class FloatOption(Option):
|
||||||
|
|
||||||
class StrOption(Option):
|
class StrOption(Option):
|
||||||
"represents the choice of a string"
|
"represents the choice of a string"
|
||||||
__slots__ = ('_opt_type',)
|
__slots__ = tuple()
|
||||||
_opt_type = 'string'
|
_opt_type = 'string'
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
|
@ -462,19 +433,25 @@ class StrOption(Option):
|
||||||
'{0}').format(type(value)))
|
'{0}').format(type(value)))
|
||||||
|
|
||||||
|
|
||||||
class UnicodeOption(Option):
|
if sys.version_info[0] >= 3:
|
||||||
"represents the choice of a unicode string"
|
#UnicodeOption is same has StrOption in python 3+
|
||||||
__slots__ = ('_opt_type',)
|
class UnicodeOption(StrOption):
|
||||||
_opt_type = 'unicode'
|
__slots__ = tuple()
|
||||||
_empty = u''
|
pass
|
||||||
|
else:
|
||||||
|
class UnicodeOption(Option):
|
||||||
|
"represents the choice of a unicode string"
|
||||||
|
__slots__ = tuple()
|
||||||
|
_opt_type = 'unicode'
|
||||||
|
_empty = u''
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
if not isinstance(value, unicode):
|
if not isinstance(value, unicode):
|
||||||
raise ValueError(_('value must be an unicode'))
|
raise ValueError(_('value must be an unicode'))
|
||||||
|
|
||||||
|
|
||||||
class SymLinkOption(object):
|
class SymLinkOption(object):
|
||||||
__slots__ = ('_name', '_opt', '_consistencies')
|
__slots__ = ('_name', '_opt')
|
||||||
_opt_type = 'symlink'
|
_opt_type = 'symlink'
|
||||||
_consistencies = None
|
_consistencies = None
|
||||||
|
|
||||||
|
@ -495,7 +472,7 @@ class SymLinkOption(object):
|
||||||
|
|
||||||
class IPOption(Option):
|
class IPOption(Option):
|
||||||
"represents the choice of an ip"
|
"represents the choice of an ip"
|
||||||
__slots__ = ('_opt_type', '_only_private')
|
__slots__ = ('_only_private',)
|
||||||
_opt_type = 'ip'
|
_opt_type = 'ip'
|
||||||
|
|
||||||
def __init__(self, name, doc, default=None, default_multi=None,
|
def __init__(self, name, doc, default=None, default_multi=None,
|
||||||
|
@ -531,8 +508,7 @@ class PortOption(Option):
|
||||||
Port number 0 is reserved and can't be used.
|
Port number 0 is reserved and can't be used.
|
||||||
see: http://en.wikipedia.org/wiki/Port_numbers
|
see: http://en.wikipedia.org/wiki/Port_numbers
|
||||||
"""
|
"""
|
||||||
__slots__ = ('_opt_type', '_allow_range', '_allow_zero', '_min_value',
|
__slots__ = ('_allow_range', '_allow_zero', '_min_value', '_max_value')
|
||||||
'_max_value')
|
|
||||||
_opt_type = 'port'
|
_opt_type = 'port'
|
||||||
|
|
||||||
def __init__(self, name, doc, default=None, default_multi=None,
|
def __init__(self, name, doc, default=None, default_multi=None,
|
||||||
|
@ -593,7 +569,7 @@ class PortOption(Option):
|
||||||
|
|
||||||
class NetworkOption(Option):
|
class NetworkOption(Option):
|
||||||
"represents the choice of a network"
|
"represents the choice of a network"
|
||||||
__slots__ = ('_opt_type',)
|
__slots__ = tuple()
|
||||||
_opt_type = 'network'
|
_opt_type = 'network'
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
|
@ -604,7 +580,7 @@ class NetworkOption(Option):
|
||||||
|
|
||||||
class NetmaskOption(Option):
|
class NetmaskOption(Option):
|
||||||
"represents the choice of a netmask"
|
"represents the choice of a netmask"
|
||||||
__slots__ = ('_opt_type',)
|
__slots__ = tuple()
|
||||||
_opt_type = 'netmask'
|
_opt_type = 'netmask'
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
|
@ -651,7 +627,7 @@ class NetmaskOption(Option):
|
||||||
|
|
||||||
class DomainnameOption(Option):
|
class DomainnameOption(Option):
|
||||||
"represents the choice of a domain name"
|
"represents the choice of a domain name"
|
||||||
__slots__ = ('_opt_type', '_type', '_allow_ip')
|
__slots__ = ('_type', '_allow_ip')
|
||||||
_opt_type = 'domainname'
|
_opt_type = 'domainname'
|
||||||
|
|
||||||
def __init__(self, name, doc, default=None, default_multi=None,
|
def __init__(self, name, doc, default=None, default_multi=None,
|
||||||
|
@ -733,7 +709,7 @@ class OptionDescription(BaseInformation):
|
||||||
valid_child.sort()
|
valid_child.sort()
|
||||||
old = None
|
old = None
|
||||||
for child in valid_child:
|
for child in valid_child:
|
||||||
if id(child) == id(old):
|
if child == old:
|
||||||
raise ConflictError(_('duplicate option name: '
|
raise ConflictError(_('duplicate option name: '
|
||||||
'{0}').format(child))
|
'{0}').format(child))
|
||||||
old = child
|
old = child
|
||||||
|
@ -807,6 +783,9 @@ class OptionDescription(BaseInformation):
|
||||||
attr = option._name
|
attr = option._name
|
||||||
if attr.startswith('_cfgimpl'):
|
if attr.startswith('_cfgimpl'):
|
||||||
continue
|
continue
|
||||||
|
if option in cache_option:
|
||||||
|
raise ConflictError(_('duplicate option: {0}').format(option))
|
||||||
|
|
||||||
cache_option.append(option)
|
cache_option.append(option)
|
||||||
cache_path.append(str('.'.join(_currpath + [attr])))
|
cache_path.append(str('.'.join(_currpath + [attr])))
|
||||||
if not isinstance(option, OptionDescription):
|
if not isinstance(option, OptionDescription):
|
||||||
|
@ -826,15 +805,6 @@ class OptionDescription(BaseInformation):
|
||||||
_consistencies)
|
_consistencies)
|
||||||
_currpath.pop()
|
_currpath.pop()
|
||||||
if save:
|
if save:
|
||||||
#valid no duplicated option
|
|
||||||
valid_child = copy(cache_option)
|
|
||||||
valid_child.sort()
|
|
||||||
old = None
|
|
||||||
for child in valid_child:
|
|
||||||
if id(child) == id(old):
|
|
||||||
raise ConflictError(_('duplicate option: '
|
|
||||||
'{0}').format(child))
|
|
||||||
old = child
|
|
||||||
self._cache_paths = (tuple(cache_option), tuple(cache_path))
|
self._cache_paths = (tuple(cache_option), tuple(cache_path))
|
||||||
self._consistencies = _consistencies
|
self._consistencies = _consistencies
|
||||||
|
|
||||||
|
@ -971,7 +941,6 @@ def validate_requires_arg(requires, name):
|
||||||
' same_action must be boolean'))
|
' same_action must be boolean'))
|
||||||
|
|
||||||
if not isinstance(option, Option):
|
if not isinstance(option, Option):
|
||||||
print option, type(option)
|
|
||||||
raise ValueError(_('malformed requirements '
|
raise ValueError(_('malformed requirements '
|
||||||
'must be an option in option {0}').format(name))
|
'must be an option in option {0}').format(name))
|
||||||
if option.impl_is_multi():
|
if option.impl_is_multi():
|
||||||
|
@ -980,7 +949,7 @@ def validate_requires_arg(requires, name):
|
||||||
if expected is not None:
|
if expected is not None:
|
||||||
try:
|
try:
|
||||||
option._validate(expected)
|
option._validate(expected)
|
||||||
except ValueError, err:
|
except ValueError as err:
|
||||||
raise ValueError(_('malformed requirements second argument '
|
raise ValueError(_('malformed requirements second argument '
|
||||||
'must be valid for option {0}'
|
'must be valid for option {0}'
|
||||||
': {1}').format(name, err))
|
': {1}').format(name, err))
|
||||||
|
|
|
@ -206,7 +206,7 @@ class Property(object):
|
||||||
def set_storage(name, **args):
|
def set_storage(name, **args):
|
||||||
storage_type.set_storage(name)
|
storage_type.set_storage(name)
|
||||||
settings = __import__(storage_type.get_storage(), globals(), locals(),
|
settings = __import__(storage_type.get_storage(), globals(), locals(),
|
||||||
['Setting'], -1).Setting()
|
['Setting']).Setting()
|
||||||
for option, value in args.items():
|
for option, value in args.items():
|
||||||
try:
|
try:
|
||||||
getattr(settings, option)
|
getattr(settings, option)
|
||||||
|
@ -223,17 +223,17 @@ def get_storage(context, session_id, persistent):
|
||||||
if session_id is None:
|
if session_id is None:
|
||||||
session_id = gen_id(context)
|
session_id = gen_id(context)
|
||||||
return __import__(storage_type.get_storage(), globals(), locals(),
|
return __import__(storage_type.get_storage(), globals(), locals(),
|
||||||
['Storage'], -1).Storage(session_id, persistent)
|
['Storage']).Storage(session_id, persistent)
|
||||||
|
|
||||||
|
|
||||||
def list_sessions():
|
def list_sessions():
|
||||||
return __import__(storage_type.get_storage(), globals(), locals(),
|
return __import__(storage_type.get_storage(), globals(), locals(),
|
||||||
['list_sessions'], -1).list_sessions()
|
['list_sessions']).list_sessions()
|
||||||
|
|
||||||
|
|
||||||
def delete_session(session_id):
|
def delete_session(session_id):
|
||||||
return __import__(storage_type.get_storage(), globals(), locals(),
|
return __import__(storage_type.get_storage(), globals(), locals(),
|
||||||
['delete_session'], -1).delete_session(session_id)
|
['delete_session']).delete_session(session_id)
|
||||||
|
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
|
@ -255,8 +255,8 @@ class Settings(object):
|
||||||
self._owner = owners.user
|
self._owner = owners.user
|
||||||
self.context = weakref.ref(context)
|
self.context = weakref.ref(context)
|
||||||
import_lib = 'tiramisu.storage.{0}.setting'.format(storage.storage)
|
import_lib = 'tiramisu.storage.{0}.setting'.format(storage.storage)
|
||||||
self._p_ = __import__(import_lib, globals(), locals(), ['Settings'],
|
self._p_ = __import__(import_lib, globals(), locals(), ['Settings']
|
||||||
-1).Settings(storage)
|
).Settings(storage)
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
# properties methods
|
# properties methods
|
||||||
|
@ -496,7 +496,7 @@ class Settings(object):
|
||||||
try:
|
try:
|
||||||
value = self.context()._getattr(reqpath,
|
value = self.context()._getattr(reqpath,
|
||||||
force_permissive=True)
|
force_permissive=True)
|
||||||
except PropertiesOptionError, err:
|
except PropertiesOptionError as err:
|
||||||
if not transitive:
|
if not transitive:
|
||||||
continue
|
continue
|
||||||
properties = err.proptype
|
properties = err.proptype
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#
|
#
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
from tiramisu.i18n import _
|
from tiramisu.i18n import _
|
||||||
from tiramisu.error import ConfigError
|
from tiramisu.error import ConfigError
|
||||||
|
|
||||||
|
@ -84,8 +82,7 @@ class Cache(object):
|
||||||
return path in self._cache
|
return path in self._cache
|
||||||
|
|
||||||
def reset_expired_cache(self, cache_type, exp):
|
def reset_expired_cache(self, cache_type, exp):
|
||||||
keys = self._cache.keys()
|
for key in tuple(self._cache.keys()):
|
||||||
for key in keys:
|
|
||||||
val, created = self._cache[key]
|
val, created = self._cache[key]
|
||||||
if exp > created:
|
if exp > created:
|
||||||
del(self._cache[key])
|
del(self._cache[key])
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
from time import time
|
from time import time
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
import sys
|
||||||
import weakref
|
import weakref
|
||||||
from tiramisu.error import ConfigError, SlaveError
|
from tiramisu.error import ConfigError, SlaveError
|
||||||
from tiramisu.setting import owners, multitypes, expires_time
|
from tiramisu.setting import owners, multitypes, expires_time
|
||||||
|
@ -45,7 +46,7 @@ class Values(object):
|
||||||
# the storage type is dictionary or sqlite3
|
# the storage type is dictionary or sqlite3
|
||||||
import_lib = 'tiramisu.storage.{0}.value'.format(storage.storage)
|
import_lib = 'tiramisu.storage.{0}.value'.format(storage.storage)
|
||||||
self._p_ = __import__(import_lib, globals(), locals(), ['Values'],
|
self._p_ = __import__(import_lib, globals(), locals(), ['Values'],
|
||||||
-1).Values(storage)
|
).Values(storage)
|
||||||
|
|
||||||
def _getdefault(self, opt):
|
def _getdefault(self, opt):
|
||||||
"""
|
"""
|
||||||
|
@ -427,7 +428,12 @@ class Multi(list):
|
||||||
multitypes.master]:
|
multitypes.master]:
|
||||||
raise SlaveError(_("cannot sort multi option {0} if master or slave"
|
raise SlaveError(_("cannot sort multi option {0} if master or slave"
|
||||||
"").format(self.opt._name))
|
"").format(self.opt._name))
|
||||||
super(Multi, self).sort(cmp=cmp, key=key, reverse=reverse)
|
if sys.version_info[0] >= 3:
|
||||||
|
if cmp is not None:
|
||||||
|
raise ValueError(_('cmp is not permitted in python v3 or greater'))
|
||||||
|
super(Multi, self).sort(key=key, reverse=reverse)
|
||||||
|
else:
|
||||||
|
super(Multi, self).sort(cmp=cmp, key=key, reverse=reverse)
|
||||||
self.context().cfgimpl_get_values()._setvalue(self.opt, self.path, self)
|
self.context().cfgimpl_get_values()._setvalue(self.opt, self.path, self)
|
||||||
|
|
||||||
def reverse(self):
|
def reverse(self):
|
||||||
|
@ -458,7 +464,7 @@ class Multi(list):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
try:
|
try:
|
||||||
self.opt._validate(value)
|
self.opt._validate(value)
|
||||||
except ValueError, err:
|
except ValueError as err:
|
||||||
raise ValueError(_("invalid value {0} "
|
raise ValueError(_("invalid value {0} "
|
||||||
"for option {1}: {2}"
|
"for option {1}: {2}"
|
||||||
"").format(str(value),
|
"").format(str(value),
|
||||||
|
|
Loading…
Reference in New Issue