BaseType refactoring
This commit is contained in:
parent
df3753c36b
commit
e360a07a21
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"base 'interface' types for option types"
|
"base 'interface' types for option types"
|
||||||
# Copyright (C) 2012 Team tiramisu (see AUTHORS for all contributors)
|
# Copyright (C) 2012-2013 Team tiramisu (see AUTHORS for all contributors)
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
class BaseType(object):
|
class CommonType(object):
|
||||||
def has_properties(self):
|
def has_properties(self):
|
||||||
return bool(len(self.properties))
|
return bool(len(self.properties))
|
||||||
def has_property(self, propname):
|
def has_property(self, propname):
|
||||||
|
@ -34,21 +34,44 @@ class BaseType(object):
|
||||||
def del_property(self, propname):
|
def del_property(self, propname):
|
||||||
if self.has_property(propname):
|
if self.has_property(propname):
|
||||||
self.properties.remove(propname)
|
self.properties.remove(propname)
|
||||||
|
|
||||||
|
#class HiddenBaseType(BaseType):
|
||||||
|
# def hide(self):
|
||||||
|
# self.add_property('hidden')
|
||||||
|
# def show(self):
|
||||||
|
# self.del_property('hidden')
|
||||||
|
# def _is_hidden(self):
|
||||||
|
# # dangerous method: how an Option() can determine its status by itself ?
|
||||||
|
# return self.has_property('hidden')
|
||||||
|
|
||||||
|
#class DisabledBaseType(BaseType):
|
||||||
|
# def disable(self):
|
||||||
|
# self.add_property('disabled')
|
||||||
|
# def enable(self):
|
||||||
|
# self.del_property('disabled')
|
||||||
|
# def _is_disabled(self):
|
||||||
|
# return self.has_property('disabled')
|
||||||
|
|
||||||
|
# commonly used properties. Option and OptionDescription will have these methods
|
||||||
|
common_properties = {'hidden': ('hide', 'show', '_is_hidden'),
|
||||||
|
'disabled': ('disable', 'enable', '_is_disabled')
|
||||||
|
}
|
||||||
|
|
||||||
|
basetype_methods = dict()
|
||||||
|
|
||||||
class HiddenBaseType(BaseType):
|
def build_properties(prop, add_prop, del_prop, is_prop):
|
||||||
def hide(self):
|
def add_property(self):
|
||||||
self.add_property('hidden')
|
self.add_property(prop)
|
||||||
def show(self):
|
def del_property(self):
|
||||||
self.del_property('hidden')
|
self.del_property(prop)
|
||||||
def _is_hidden(self):
|
def is_property(self):
|
||||||
# dangerous method: how an Option() can determine its status by itself ?
|
return self.has_property(prop)
|
||||||
return self.has_property('hidden')
|
return {add_prop:add_property, del_prop:del_property,
|
||||||
|
is_prop:is_property}
|
||||||
|
|
||||||
class DisabledBaseType(BaseType):
|
for propname, meth_names in common_properties.items():
|
||||||
def disable(self):
|
basetype_methods.update(build_properties(propname, meth_names[0], meth_names[1],
|
||||||
self.add_property('disabled')
|
meth_names[2]))
|
||||||
def enable(self):
|
|
||||||
self.del_property('disabled')
|
BaseType = type('BaseType', (CommonType,), basetype_methods)
|
||||||
def _is_disabled(self):
|
|
||||||
return self.has_property('disabled')
|
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,15 @@
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
import re
|
import re
|
||||||
from types import FunctionType
|
from types import FunctionType
|
||||||
from tiramisu.basetype import HiddenBaseType, DisabledBaseType
|
from tiramisu.basetype import BaseType
|
||||||
from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
|
from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
|
||||||
RequiresError, RequirementRecursionError, MandatoryError,
|
RequiresError, RequirementRecursionError, MandatoryError,
|
||||||
PropertiesOptionError)
|
PropertiesOptionError)
|
||||||
from tiramisu.autolib import carry_out_calculation
|
from tiramisu.autolib import carry_out_calculation
|
||||||
from tiramisu.setting import groups, owners
|
from tiramisu.setting import groups, owners
|
||||||
|
|
||||||
requires_actions = [('hide', 'show'), ('enable', 'disable'), ('freeze', 'unfreeze')]
|
requires_actions = [('hide', 'show'), ('enable', 'disable'),
|
||||||
|
('freeze', 'unfreeze')]
|
||||||
|
|
||||||
available_actions = []
|
available_actions = []
|
||||||
reverse_actions = {}
|
reverse_actions = {}
|
||||||
|
@ -48,7 +49,7 @@ def valid_name(name):
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
#
|
#
|
||||||
|
|
||||||
class Option(HiddenBaseType, DisabledBaseType):
|
class Option(BaseType):
|
||||||
"""
|
"""
|
||||||
Abstract base class for configuration option's.
|
Abstract base class for configuration option's.
|
||||||
|
|
||||||
|
@ -373,7 +374,7 @@ class NetmaskOption(Option):
|
||||||
# by now the validation is nothing but a string, use IPy instead
|
# by now the validation is nothing but a string, use IPy instead
|
||||||
return isinstance(value, str)
|
return isinstance(value, str)
|
||||||
|
|
||||||
class OptionDescription(HiddenBaseType, DisabledBaseType):
|
class OptionDescription(BaseType):
|
||||||
"""Config's schema (organisation, group) and container of Options"""
|
"""Config's schema (organisation, group) and container of Options"""
|
||||||
# the group_type is useful for filtering OptionDescriptions in a config
|
# the group_type is useful for filtering OptionDescriptions in a config
|
||||||
group_type = groups.default
|
group_type = groups.default
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"sets the options of the configuration objects Config object itself"
|
"sets the options of the configuration objects Config object itself"
|
||||||
# Copyright (C) 2012 Team tiramisu (see AUTHORS for all contributors)
|
# Copyright (C) 2012-2013 Team tiramisu (see AUTHORS for all contributors)
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|
Loading…
Reference in New Issue