Debian Codegraph @

lib/ansible/module_utils/distro/__init__.py

raw
1 # (c) 2018 Toshio Kuratomi <[email protected]>
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17
18
19 """
20 Compat distro library.
21 """
22 from __future__ import annotations
23
24 # The following makes it easier for us to script updates of the bundled code
25 _BUNDLED_METADATA = {"pypi_name": "distro", "version": "1.9.0"}
26
27 # The following additional changes have been made:
28 # * Remove optparse since it is not needed for our use.
29 # * A format string including {} has been changed to {0} (py2.6 compat)
30 # * Port two calls from subprocess.check_output to subprocess.Popen().communicate() (py2.6 compat)
31
32
33 import sys
34 import types
35
36 try:
37 import distro as _system_distro
38 except ImportError:
39 _system_distro = None
40 else:
41 # There could be a 'distro' package/module that isn't what we expect, on the
42 # PYTHONPATH. Rather than erroring out in this case, just fall back to ours.
43 # We require more functions than distro.id(), but this is probably a decent
44 # test that we have something we can reasonably use.
45 if not hasattr(_system_distro, 'id') or \
46 not isinstance(_system_distro.id, types.FunctionType):
47 _system_distro = None
48
49 if _system_distro:
50 distro = _system_distro
51 else:
52 # Our bundled copy
53 from ansible.module_utils.distro import _distro as distro
54
55 sys.modules['ansible.module_utils.distro'] = distro