105 lines
3.6 KiB
Python
105 lines
3.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (C) 2017-2018 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 ..i18n import _
|
|
from ..setting import undefined
|
|
from .symlinkoption import DynSymLinkOption
|
|
|
|
|
|
class SynDynOptionDescription(object):
|
|
__slots__ = ('_opt',
|
|
'_subpath',
|
|
'_suffix')
|
|
|
|
def __init__(self,
|
|
opt,
|
|
subpath,
|
|
suffix):
|
|
|
|
self._opt = opt
|
|
self._subpath = subpath
|
|
self._suffix = suffix
|
|
|
|
def __getattr__(self, name):
|
|
return getattr(self._opt, name)
|
|
|
|
def impl_getopt(self):
|
|
return self._opt
|
|
|
|
def impl_getchild(self,
|
|
name,
|
|
config_bag,
|
|
subconfig):
|
|
try:
|
|
if name.endswith(self._suffix):
|
|
oname = name[:-len(self._suffix)]
|
|
child = self._children[1][self._children[0].index(oname)]
|
|
return self._impl_get_dynchild(child,
|
|
self._suffix,
|
|
subconfig.cfgimpl_get_path())
|
|
except ValueError:
|
|
# when oname not in self._children
|
|
pass
|
|
raise AttributeError(_('unknown Option {0} '
|
|
'in SynDynOptionDescription {1}'
|
|
'').format(name, self.impl_getname()))
|
|
|
|
def impl_getname(self):
|
|
return self._opt.impl_getname() + self._suffix
|
|
|
|
def impl_getchildren(self,
|
|
config_bag,
|
|
dyn=True):
|
|
children = []
|
|
for child in self._opt.impl_getchildren(config_bag):
|
|
yield(self._opt._impl_get_dynchild(child,
|
|
self._suffix,
|
|
self._subpath))
|
|
|
|
def impl_getpath(self):
|
|
subpath = self._subpath
|
|
if subpath != '':
|
|
subpath += '.'
|
|
return subpath + self.impl_getname()
|
|
|
|
def getmaster(self):
|
|
master = self._opt.getmaster()
|
|
return DynSymLinkOption(master,
|
|
self.impl_getpath(),
|
|
self._suffix)
|
|
|
|
def getslaves(self):
|
|
subpath = self.impl_getpath()
|
|
for slave in self._opt.getslaves():
|
|
yield DynSymLinkOption(slave,
|
|
subpath,
|
|
self._suffix)
|
|
|
|
def pop(self,
|
|
values,
|
|
index,
|
|
setting_properties,
|
|
force_permissive,
|
|
slaves=undefined):
|
|
self._opt.pop(values,
|
|
index,
|
|
setting_properties,
|
|
force_permissive,
|
|
slaves=self.getslaves())
|