mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
Cleanups to the common.sys_info API
* Move get_all_subclasses out of sys_info as it is unrelated to system information. * get_all_subclasses now returns a set() instead of a list. * Don't port get_platform to sys_info as it is deprecated. Code using the common API should just use platform.system() directly. * Rename load_platform_subclass() to get_platform_subclass and do not instantiate the rturned class. * Test the compat shims in module_utils/basic.py separately from the new API in module_utils/common/sys_info.py and module_utils/common/_utils.py
This commit is contained in:
parent
79dc9a75c3
commit
5844c8c7f0
7 changed files with 284 additions and 47 deletions
|
@ -165,11 +165,9 @@ from ansible.module_utils.common.file import (
|
|||
get_flags_from_attributes,
|
||||
)
|
||||
from ansible.module_utils.common.sys_info import (
|
||||
get_platform,
|
||||
get_distribution,
|
||||
get_distribution_version,
|
||||
load_platform_subclass,
|
||||
get_all_subclasses,
|
||||
get_platform_subclass,
|
||||
)
|
||||
from ansible.module_utils.pycompat24 import get_exception, literal_eval
|
||||
from ansible.module_utils.six import (
|
||||
|
@ -184,6 +182,7 @@ from ansible.module_utils.six import (
|
|||
)
|
||||
from ansible.module_utils.six.moves import map, reduce, shlex_quote
|
||||
from ansible.module_utils._text import to_native, to_bytes, to_text
|
||||
from ansible.module_utils.common._utils import get_all_subclasses as _get_all_subclasses
|
||||
from ansible.module_utils.parsing.convert_bool import BOOLEANS, BOOLEANS_FALSE, BOOLEANS_TRUE, boolean
|
||||
|
||||
|
||||
|
@ -276,6 +275,42 @@ if not _PY_MIN:
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
#
|
||||
# Deprecated functions
|
||||
#
|
||||
|
||||
def get_platform():
|
||||
'''
|
||||
**Deprecated** Use :py:func:`platform.system` directly.
|
||||
|
||||
:returns: Name of the platform the module is running on in a native string
|
||||
|
||||
Returns a native string that labels the platform ("Linux", "Solaris", etc). Currently, this is
|
||||
the result of calling :py:func:`platform.system`.
|
||||
'''
|
||||
return platform.system()
|
||||
|
||||
# End deprecated functions
|
||||
|
||||
|
||||
#
|
||||
# Compat shims
|
||||
#
|
||||
|
||||
def load_platform_subclass(cls, *args, **kwargs):
|
||||
"""**Deprecated**: Use ansible.module_utils.common.sys_info.get_platform_subclass instead"""
|
||||
platform_cls = get_platform_subclass(cls)
|
||||
return super(cls, platform_cls).__new__(platform_cls)
|
||||
|
||||
|
||||
def get_all_subclasses(cls):
|
||||
"""**Deprecated**: Use ansible.module_utils.common._utils.get_all_subclasses instead"""
|
||||
return list(_get_all_subclasses(cls))
|
||||
|
||||
|
||||
# End compat shims
|
||||
|
||||
|
||||
def json_dict_unicode_to_bytes(d, encoding='utf-8', errors='surrogate_or_strict'):
|
||||
''' Recursively convert dict keys and values to byte str
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue