__tablename__ = 'baseoption'
id = Column(Integer, primary_key=True)
_name = Column(String)
- _type = Column(PickleType)
_informations = relationship('_Information')
_default = Column(PickleType)
_default_multi = Column(PickleType)
backref=backref('options', enable_typechecks=False))
_choice_values = Column(PickleType)
_choice_open_values = Column(Boolean)
+ _type = Column(String(50))
+ __mapper_args__ = {
+ 'polymorphic_identity': 'person',
+ 'polymorphic_on': _type
+ }
#FIXME devrait etre une table
_optiondescription_group_type = Column(String)
#__slots__ = ('_name', '_requires', '_properties', '_readonly',
if not valid_name(name):
raise ValueError(_("invalid name: {0} for option").format(name))
self._name = name
- self._type = self.__class__
self.impl_set_information('doc', doc)
requires = validate_requires_arg(requires, self._name)
if requires is not None:
"""
#__slots__ = ('_values', '_open_values')
- _opt_type = 'string'
+ __mapper_args__ = {
+ 'polymorphic_identity': 'choice',
+ }
def __init__(self, name, doc, values, default=None, default_multi=None,
requires=None, multi=False, callback=None,
class BoolOption(Option):
"represents a choice between ``True`` and ``False``"
- __slots__ = tuple()
- _opt_type = 'bool'
+# __slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'bool',
+ }
def _validate(self, value):
if not isinstance(value, bool):
class IntOption(Option):
"represents a choice of an integer"
- __slots__ = tuple()
- _opt_type = 'int'
+# __slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'int',
+ }
def _validate(self, value):
if not isinstance(value, int):
class FloatOption(Option):
"represents a choice of a floating point number"
- __slots__ = tuple()
- _opt_type = 'float'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'float',
+ }
def _validate(self, value):
if not isinstance(value, float):
class StrOption(Option):
"represents the choice of a string"
- __slots__ = tuple()
- _opt_type = 'string'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'string',
+ }
def _validate(self, value):
if not isinstance(value, str):
if sys.version_info[0] >= 3:
#UnicodeOption is same as StrOption in python 3+
class UnicodeOption(StrOption):
- __slots__ = tuple()
+ #__slots__ = tuple()
pass
else:
class UnicodeOption(Option):
"represents the choice of a unicode string"
- __slots__ = tuple()
- _opt_type = 'unicode'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'unicode',
+ }
_empty = u''
def _validate(self, value):
class SymLinkOption(BaseOption):
#__slots__ = ('_name', '_opt', '_state_opt', '_readonly', '_parent')
- _opt_type = 'symlink'
+ __mapper_args__ = {
+ 'polymorphic_identity': 'symlink',
+ }
#not return _opt consistencies
#_consistencies = None
self._opt = opt
self._readonly = True
self._parent = None
- self._type = self.__class__
session.add(self)
session.commit()
del(self._state_opt)
super(SymLinkOption, self)._impl_setstate(descr)
- def impl_getname(self):
- return self._name
-
def impl_get_information(self, key, default=None):
#FIXME ne devrait pas etre util si ?
return self._opt.impl_get_information(key, default)
class IPOption(Option):
"represents the choice of an ip"
- __slots__ = ('_private_only', '_allow_reserved')
- _opt_type = 'ip'
+ #__slots__ = ('_private_only', '_allow_reserved')
+ __mapper_args__ = {
+ 'polymorphic_identity': 'ip',
+ }
def __init__(self, name, doc, default=None, default_multi=None,
requires=None, multi=False, callback=None,
Port number 0 is reserved and can't be used.
see: http://en.wikipedia.org/wiki/Port_numbers
"""
- __slots__ = ('_allow_range', '_allow_zero', '_min_value', '_max_value')
- _opt_type = 'port'
+ #__slots__ = ('_allow_range', '_allow_zero', '_min_value', '_max_value')
+ __mapper_args__ = {
+ 'polymorphic_identity': 'port',
+ }
def __init__(self, name, doc, default=None, default_multi=None,
requires=None, multi=False, callback=None,
class NetworkOption(Option):
"represents the choice of a network"
- __slots__ = tuple()
- _opt_type = 'network'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'network',
+ }
def _validate(self, value):
try:
class NetmaskOption(Option):
"represents the choice of a netmask"
- __slots__ = tuple()
- _opt_type = 'netmask'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'netmask',
+ }
def _validate(self, value):
try:
class BroadcastOption(Option):
- __slots__ = tuple()
- _opt_type = 'broadcast'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'broadcast',
+ }
def _validate(self, value):
try:
domainname:
fqdn: with tld, not supported yet
"""
- __slots__ = ('_dom_type', '_allow_ip', '_allow_without_dot', '_domain_re')
- _opt_type = 'domainname'
+ #__slots__ = ('_dom_type', '_allow_ip', '_allow_without_dot', '_domain_re')
+ __mapper_args__ = {
+ 'polymorphic_identity': 'domainname',
+ }
def __init__(self, name, doc, default=None, default_multi=None,
requires=None, multi=False, callback=None,
class EmailOption(DomainnameOption):
- __slots__ = tuple()
- _opt_type = 'email'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'email',
+ }
username_re = re.compile(r"^[\w!#$%&'*+\-/=?^`{|}~.]+$")
def _validate(self, value):
class URLOption(DomainnameOption):
- __slots__ = tuple()
- _opt_type = 'url'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'url',
+ }
proto_re = re.compile(r'(http|https)://')
path_re = re.compile(r"^[a-z0-9\-\._~:/\?#\[\]@!%\$&\'\(\)\*\+,;=]+$")
class FilenameOption(Option):
- __slots__ = tuple()
- _opt_type = 'file'
+ #__slots__ = tuple()
+ __mapper_args__ = {
+ 'polymorphic_identity': 'file',
+ }
path_re = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
def _validate(self, value):
# '_cache_consistencies', '_calc_properties', '__weakref__',
# '_readonly', '_impl_informations', '_state_requires',
# '_stated', '_state_readonly')
- _opt_type = 'optiondescription'
+ __mapper_args__ = {
+ 'polymorphic_identity': 'optiondescription',
+ }
def __init__(self, name, doc, children, requires=None, properties=None):
"""
if name.startswith('_') or name.startswith('impl_'):
return object.__getattribute__(self, name)
else:
- #FIXME regression ...
+ #FIXME regression ... devrait etre un query !
for child in self._children:
if child.impl_getname() == name:
+ return child
#convert to object
- return session.query(child._type).filter_by(id=child.id).first()
+ #return session.query(child._type).filter_by(id=child.id).first()
#return pouet#self._children[1][self._children[0].index(name)]
except ValueError:
pass
return paths
def impl_getchildren(self):
- for child in self._children:
- yield(session.query(child._type).filter_by(id=child.id).first())
+ #FIXME dans la base ??
+ return self._children
+ #for child in self._children:
+ # yield(session.query(child._type).filter_by(id=child.id).first())
def impl_build_cache(self,
cache_path=None,
- cache_type=None,
cache_option=None,
_currpath=None,
_consistencies=None,
save = False
if cache_path is None:
cache_path = []
- cache_type = []
cache_option = []
for option in self.impl_getchildren():
attr = option.impl_getname()
if not force_no_consistencies:
option._readonly = True
cache_path.append(str('.'.join(_currpath + [attr])))
- cache_type.append(option._type)
if not isinstance(option, OptionDescription):
if not force_no_consistencies and \
option._consistencies is not []:
all_cons_opts))
else:
_currpath.append(attr)
- option.impl_build_cache(cache_path, cache_type,
+ option.impl_build_cache(cache_path,
cache_option,
_currpath,
_consistencies,
force_no_consistencies)
_currpath.pop()
if save:
- self._cache_paths = (tuple(cache_option), tuple(cache_path), tuple(cache_type))
+ self._cache_paths = (tuple(cache_option), tuple(cache_path))
if not force_no_consistencies:
if _consistencies != {}:
self._cache_consistencies = {}
def impl_get_opt_by_path(self, path):
try:
+ #FIXME
idx = self._cache_paths[1].index(path)
opt_id = self._cache_paths[0][idx]
- opt_type = self._cache_paths[2][idx]
- return session.query(opt_type).filter_by(id=opt_id).first()
+ return session.query(BaseOption).filter_by(id=opt_id).first()
except ValueError:
raise AttributeError(_('no option for path {0}').format(path))
def impl_get_opt_by_id(self, opt_id):
try:
+ #FIXME
idx = self._cache_paths[0].index(opt_id)
- opt_type = self._cache_paths[2][idx]
- return session.query(opt_type).filter_by(id=opt_id).first()
+ return session.query(BaseOption).filter_by(id=opt_id).first()
except ValueError:
raise AttributeError(_('no id {0} found').format(opt_id))
raise ValueError(_('master group with wrong'
' master name for {0}'
).format(self.impl_getname()))
- if master._callback is not None and master._callback[1] is not None:
- for key, callbacks in master._callback[1].items():
- for callbk in callbacks:
- if isinstance(callbk, tuple):
- if callbk[0] in slaves:
- raise ValueError(_("callback of master's option shall "
- "not refered a slave's ones"))
+ #FIXME debut reecriture
+ ##master_callback, master_callback_params = master.impl_get_callback()
+ #if master._callback is not None and master._callback[1] is not None:
+ # for key, callbacks in master._callback[1].items():
+ # for callbk in callbacks:
+ # if isinstance(callbk, tuple):
+ # if callbk[0] in slaves:
+ # raise ValueError(_("callback of master's option shall "
+ # "not refered a slave's ones"))
master._master_slaves = tuple(slaves)
for child in self.impl_getchildren():
if child != master: