mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
install: make knob base declaration explicit
Declare knob bases explicitly using a keyword argument instead of guessing if the type argument is a base or a type of the knob. https://fedorahosted.org/freeipa/ticket/6392 Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
parent
043c262ce4
commit
269ca6c454
@ -149,11 +149,16 @@ class KnobBase(PropertyBase):
|
|||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
def knob(type_or_base, default=_missing, sensitive=_missing,
|
def knob(type_=_missing, default=_missing, bases=_missing, sensitive=_missing,
|
||||||
deprecated=_missing, description=_missing, cli_names=_missing,
|
deprecated=_missing, description=_missing, cli_names=_missing,
|
||||||
cli_deprecated_names=_missing, cli_metavar=_missing):
|
cli_deprecated_names=_missing, cli_metavar=_missing):
|
||||||
if type_or_base is None:
|
if type_ is None:
|
||||||
type_or_base = NoneType
|
type_ = NoneType
|
||||||
|
|
||||||
|
if bases is _missing:
|
||||||
|
bases = (KnobBase,)
|
||||||
|
elif isinstance(bases, type):
|
||||||
|
bases = (bases,)
|
||||||
|
|
||||||
if cli_names is None or isinstance(cli_names, str):
|
if cli_names is None or isinstance(cli_names, str):
|
||||||
cli_names = (cli_names,)
|
cli_names = (cli_names,)
|
||||||
@ -165,15 +170,10 @@ def knob(type_or_base, default=_missing, sensitive=_missing,
|
|||||||
elif cli_deprecated_names is not _missing:
|
elif cli_deprecated_names is not _missing:
|
||||||
cli_deprecated_names = tuple(cli_deprecated_names)
|
cli_deprecated_names = tuple(cli_deprecated_names)
|
||||||
|
|
||||||
assert isinstance(type_or_base, type)
|
|
||||||
|
|
||||||
class_dict = {}
|
class_dict = {}
|
||||||
class_dict['_order'] = next(_counter)
|
class_dict['_order'] = next(_counter)
|
||||||
|
if type_ is not _missing:
|
||||||
if not issubclass(type_or_base, KnobBase):
|
class_dict['type'] = type_
|
||||||
class_dict['type'] = type_or_base
|
|
||||||
type_or_base = KnobBase
|
|
||||||
|
|
||||||
if default is not _missing:
|
if default is not _missing:
|
||||||
class_dict['default'] = default
|
class_dict['default'] = default
|
||||||
if sensitive is not _missing:
|
if sensitive is not _missing:
|
||||||
@ -189,40 +189,45 @@ def knob(type_or_base, default=_missing, sensitive=_missing,
|
|||||||
if cli_metavar is not _missing:
|
if cli_metavar is not _missing:
|
||||||
class_dict['cli_metavar'] = cli_metavar
|
class_dict['cli_metavar'] = cli_metavar
|
||||||
|
|
||||||
return util.InnerClassMeta('Knob', (type_or_base,), class_dict)
|
return util.InnerClassMeta('Knob', bases, class_dict)
|
||||||
|
|
||||||
|
|
||||||
def Knob(type_or_base, default=_missing, sensitive=_missing,
|
def Knob(type_or_base, default=_missing, sensitive=_missing,
|
||||||
deprecated=_missing, description=_missing, cli_positional=False,
|
deprecated=_missing, description=_missing, cli_positional=False,
|
||||||
cli_name=_missing, cli_short_name=_missing, cli_aliases=_missing,
|
cli_name=_missing, cli_short_name=_missing, cli_aliases=_missing,
|
||||||
cli_metavar=_missing):
|
cli_metavar=_missing):
|
||||||
if isinstance(type_or_base, tuple):
|
if isinstance(type_or_base, type) and issubclass(type_or_base, KnobBase):
|
||||||
assert type_or_base[0] is list
|
type_ = _missing
|
||||||
scalar_type = type_or_base[1]
|
bases = (type_or_base,)
|
||||||
else:
|
else:
|
||||||
scalar_type = type_or_base
|
if isinstance(type_or_base, tuple):
|
||||||
|
assert type_or_base[0] is list
|
||||||
|
scalar_type = type_or_base[1]
|
||||||
|
else:
|
||||||
|
scalar_type = type_or_base
|
||||||
|
|
||||||
if scalar_type is bool:
|
if scalar_type is bool:
|
||||||
scalar_type = NoneType
|
scalar_type = NoneType
|
||||||
elif scalar_type == 'ip':
|
elif scalar_type == 'ip':
|
||||||
scalar_type = CheckedIPAddress
|
scalar_type = CheckedIPAddress
|
||||||
elif isinstance(scalar_type, set):
|
elif isinstance(scalar_type, set):
|
||||||
scalar_type = type(
|
scalar_type = type(
|
||||||
'Enum',
|
'Enum',
|
||||||
(enum.Enum,),
|
(enum.Enum,),
|
||||||
{re.sub(r'[^0-9A-Za-z_]', '', n): n for n in scalar_type})
|
{re.sub(r'[^0-9A-Za-z_]', '', n): n for n in scalar_type})
|
||||||
|
|
||||||
if isinstance(type_or_base, tuple):
|
if isinstance(type_or_base, tuple):
|
||||||
type_or_base = typing.List[scalar_type]
|
type_ = typing.List[scalar_type]
|
||||||
else:
|
else:
|
||||||
type_or_base = scalar_type
|
type_ = scalar_type
|
||||||
|
bases = _missing
|
||||||
|
|
||||||
if cli_name is not _missing or cli_short_name is not _missing:
|
if cli_name is not _missing or cli_short_name is not _missing:
|
||||||
if cli_positional and cli_name is not _missing:
|
if cli_positional and cli_name is not _missing:
|
||||||
cli_positional_name = [cli_name]
|
cli_positional_name = [cli_name]
|
||||||
elif issubclass(type_or_base, KnobBase):
|
elif bases is not _missing:
|
||||||
cli_positional_name = [
|
cli_positional_name = [
|
||||||
n for n in type_or_base.cli_names # pylint: disable=no-member
|
n for n in bases[0].cli_names # pylint: disable=no-member
|
||||||
if n is not None and n[:1] != '-'
|
if n is not None and n[:1] != '-'
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
@ -230,9 +235,9 @@ def Knob(type_or_base, default=_missing, sensitive=_missing,
|
|||||||
|
|
||||||
if cli_short_name is not _missing:
|
if cli_short_name is not _missing:
|
||||||
cli_short_name = ['-{}'.format(cli_short_name)]
|
cli_short_name = ['-{}'.format(cli_short_name)]
|
||||||
elif issubclass(type_or_base, KnobBase):
|
elif bases is not _missing:
|
||||||
cli_short_name = [
|
cli_short_name = [
|
||||||
n for n in type_or_base.cli_names # pylint: disable=no-member
|
n for n in bases[0].cli_names # pylint: disable=no-member
|
||||||
if n is not None and n[:1] == '-' and n[:2] != '--'
|
if n is not None and n[:1] == '-' and n[:2] != '--'
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
@ -243,9 +248,9 @@ def Knob(type_or_base, default=_missing, sensitive=_missing,
|
|||||||
cli_long_name = ['--{}'.format(cli_name)]
|
cli_long_name = ['--{}'.format(cli_name)]
|
||||||
else:
|
else:
|
||||||
cli_long_name = [None]
|
cli_long_name = [None]
|
||||||
elif issubclass(type_or_base, KnobBase):
|
elif bases is not _missing:
|
||||||
cli_long_name = [
|
cli_long_name = [
|
||||||
n for n in type_or_base.cli_names # pylint: disable=no-member
|
n for n in bases[0].cli_names # pylint: disable=no-member
|
||||||
if n is None or n[:2] == '--'
|
if n is None or n[:2] == '--'
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
@ -260,8 +265,9 @@ def Knob(type_or_base, default=_missing, sensitive=_missing,
|
|||||||
else:
|
else:
|
||||||
cli_deprecated_names = _missing
|
cli_deprecated_names = _missing
|
||||||
|
|
||||||
return knob(type_or_base,
|
return knob(type_,
|
||||||
default=default,
|
default=default,
|
||||||
|
bases=bases,
|
||||||
sensitive=sensitive,
|
sensitive=sensitive,
|
||||||
deprecated=deprecated,
|
deprecated=deprecated,
|
||||||
description=description,
|
description=description,
|
||||||
|
Loading…
Reference in New Issue
Block a user