BaseType refactoring
This commit is contained in:
parent
df3753c36b
commit
e360a07a21
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"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
|
||||
# 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
|
||||
# ____________________________________________________________
|
||||
|
||||
class BaseType(object):
|
||||
class CommonType(object):
|
||||
def has_properties(self):
|
||||
return bool(len(self.properties))
|
||||
def has_property(self, propname):
|
||||
|
@ -34,21 +34,44 @@ class BaseType(object):
|
|||
def del_property(self, propname):
|
||||
if self.has_property(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 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')
|
||||
def build_properties(prop, add_prop, del_prop, is_prop):
|
||||
def add_property(self):
|
||||
self.add_property(prop)
|
||||
def del_property(self):
|
||||
self.del_property(prop)
|
||||
def is_property(self):
|
||||
return self.has_property(prop)
|
||||
return {add_prop:add_property, del_prop:del_property,
|
||||
is_prop:is_property}
|
||||
|
||||
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')
|
||||
for propname, meth_names in common_properties.items():
|
||||
basetype_methods.update(build_properties(propname, meth_names[0], meth_names[1],
|
||||
meth_names[2]))
|
||||
|
||||
BaseType = type('BaseType', (CommonType,), basetype_methods)
|
||||
|
||||
|
|
|
@ -22,14 +22,15 @@
|
|||
# ____________________________________________________________
|
||||
import re
|
||||
from types import FunctionType
|
||||
from tiramisu.basetype import HiddenBaseType, DisabledBaseType
|
||||
from tiramisu.basetype import BaseType
|
||||
from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
|
||||
RequiresError, RequirementRecursionError, MandatoryError,
|
||||
PropertiesOptionError)
|
||||
from tiramisu.autolib import carry_out_calculation
|
||||
from tiramisu.setting import groups, owners
|
||||
|
||||
requires_actions = [('hide', 'show'), ('enable', 'disable'), ('freeze', 'unfreeze')]
|
||||
requires_actions = [('hide', 'show'), ('enable', 'disable'),
|
||||
('freeze', 'unfreeze')]
|
||||
|
||||
available_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.
|
||||
|
||||
|
@ -373,7 +374,7 @@ class NetmaskOption(Option):
|
|||
# by now the validation is nothing but a string, use IPy instead
|
||||
return isinstance(value, str)
|
||||
|
||||
class OptionDescription(HiddenBaseType, DisabledBaseType):
|
||||
class OptionDescription(BaseType):
|
||||
"""Config's schema (organisation, group) and container of Options"""
|
||||
# the group_type is useful for filtering OptionDescriptions in a config
|
||||
group_type = groups.default
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
Loading…
Reference in New Issue