154 lines
4.8 KiB
Python
154 lines
4.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (C) 2017 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 Lesser General Public License as published by the
|
|
# Free Software Foundation, either version 3 of the License, or (at your
|
|
# option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
# The original `Config` design model is unproudly borrowed from
|
|
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
|
|
# the whole pypy projet is under MIT licence
|
|
# ____________________________________________________________
|
|
from .baseoption import OnlyOption
|
|
from ..i18n import _
|
|
from ..setting import undefined
|
|
|
|
|
|
class SymLinkOption(OnlyOption):
|
|
|
|
def __init__(self,
|
|
name,
|
|
opt):
|
|
if not isinstance(opt, OnlyOption) or \
|
|
opt.impl_is_symlinkoption():
|
|
raise ValueError(_('malformed symlinkoption '
|
|
'must be an option '
|
|
'for symlink {0}').format(name))
|
|
_setattr = object.__setattr__
|
|
_setattr(self, '_name', name)
|
|
_setattr(self, '_opt', opt)
|
|
opt._add_dependency(self)
|
|
|
|
def __getattr__(self,
|
|
name):
|
|
return getattr(self._opt, name)
|
|
|
|
def impl_has_dependency(self,
|
|
self_is_dep=True):
|
|
"""If self_is_dep is True, it has dependency (self._opt), so return True
|
|
if self_is_dep is False, cannot has validation or callback, so return False
|
|
"""
|
|
return self_is_dep is True
|
|
|
|
def impl_is_symlinkoption(self):
|
|
return True
|
|
|
|
def impl_getopt(self):
|
|
return self._opt
|
|
|
|
#def impl_get_information(self,
|
|
# key,
|
|
# default=undefined):
|
|
# return self._opt.impl_get_information(key, default)
|
|
|
|
def impl_is_readonly(self):
|
|
return True
|
|
|
|
#def impl_getproperties(self):
|
|
# return self._opt.impl_getproperties()
|
|
|
|
#def impl_get_callback(self):
|
|
# return self._opt.impl_get_callback()
|
|
|
|
#def impl_has_callback(self):
|
|
# "to know if a callback has been defined or not"
|
|
# return self._opt.impl_has_callback()
|
|
|
|
#def impl_is_multi(self):
|
|
# return self._opt.impl_is_multi()
|
|
|
|
#def _is_subdyn(self):
|
|
# return getattr(self._opt, '_subdyn', None) is not None
|
|
|
|
def get_consistencies(self):
|
|
return ()
|
|
|
|
def _has_consistencies(self,
|
|
context):
|
|
return option._opt._has_consistencies(context)
|
|
|
|
|
|
class DynSymLinkOption(object):
|
|
__slots__ = ('_rootpath',
|
|
'_opt',
|
|
'_suffix')
|
|
|
|
def __init__(self,
|
|
opt,
|
|
rootpath,
|
|
suffix):
|
|
self._opt = opt
|
|
self._rootpath = rootpath
|
|
self._suffix = suffix
|
|
|
|
def __getattr__(self,
|
|
name):
|
|
return getattr(self._opt, name)
|
|
|
|
def __eq__(self, left):
|
|
if not isinstance(left, DynSymLinkOption):
|
|
return False
|
|
return self._opt == left._opt and \
|
|
self._rootpath == left._rootpath and \
|
|
self._suffix == left._suffix
|
|
return True
|
|
|
|
def impl_getname(self):
|
|
return self._opt.impl_getname() + self._suffix
|
|
|
|
def impl_get_display_name(self):
|
|
return self._opt.impl_get_display_name(dyn_name=self.impl_getname())
|
|
|
|
def impl_getopt(self):
|
|
return self._opt
|
|
|
|
def impl_getsuffix(self):
|
|
return self._suffix
|
|
|
|
def impl_getpath(self,
|
|
context):
|
|
if self._rootpath == '':
|
|
return self.impl_getname()
|
|
return self._rootpath + '.' + self.impl_getname()
|
|
|
|
def impl_validate(self,
|
|
value,
|
|
config_bag,
|
|
context=undefined,
|
|
force_index=None,
|
|
current_opt=undefined,
|
|
is_multi=None,
|
|
check_error=True,
|
|
multi=None):
|
|
# add current_opt !
|
|
self._opt.impl_validate(value,
|
|
config_bag,
|
|
context,
|
|
force_index,
|
|
current_opt=self,
|
|
is_multi=is_multi,
|
|
check_error=check_error,
|
|
multi=multi)
|
|
|
|
def impl_is_dynsymlinkoption(self):
|
|
return True
|