tiramisu/tiramisu/option/symlinkoption.py

61 lines
2.3 KiB
Python
Raw Normal View History

2017-12-07 22:20:19 +01:00
# -*- coding: utf-8 -*-
2021-02-24 20:30:04 +01:00
# Copyright (C) 2017-2021 Team tiramisu (see AUTHORS for all contributors)
2017-12-07 22:20:19 +01:00
#
# 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 typing import Any
2019-02-11 20:28:03 +01:00
from .baseoption import BaseOption, valid_name
2017-12-07 22:20:19 +01:00
from ..i18n import _
class SymLinkOption(BaseOption):
2018-09-04 08:36:02 +02:00
__slots__ = ('_opt',)
2017-12-07 22:20:19 +01:00
def __init__(self,
name: str,
opt: BaseOption) -> None:
2019-02-11 20:28:03 +01:00
if not valid_name(name):
raise ValueError(_('"{0}" is an invalid name for an option').format(name))
if not isinstance(opt, BaseOption) or \
opt.impl_is_optiondescription() or \
2017-12-07 22:20:19 +01:00
opt.impl_is_symlinkoption():
raise ValueError(_('malformed symlinkoption must be an option for symlink {0}'
'').format(name))
2017-12-07 22:20:19 +01:00
_setattr = object.__setattr__
_setattr(self, '_name', name)
_setattr(self, '_opt', opt)
opt._add_dependency(self)
self._path = None
2017-12-07 22:20:19 +01:00
2017-12-13 22:15:34 +01:00
def __getattr__(self,
name: str) -> Any:
2017-12-13 22:15:34 +01:00
return getattr(self._opt, name)
2018-01-05 23:32:00 +01:00
def impl_has_dependency(self,
self_is_dep: bool=True) -> bool:
2017-12-07 22:20:19 +01:00
"""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
2017-12-07 22:20:19 +01:00
def impl_is_symlinkoption(self) -> bool:
2017-12-07 22:20:19 +01:00
return True
def impl_getopt(self) -> BaseOption:
2017-12-07 22:20:19 +01:00
return self._opt