|
56 | 56 | import json |
57 | 57 | import datetime |
58 | 58 | import xml.sax.saxutils |
59 | | -from distutils.version import LooseVersion |
| 59 | +try: |
| 60 | + from distutils.version import LooseVersion |
| 61 | +except ImportError: |
| 62 | + # distutils removed in Python 3.12; minimal shim for version comparisons |
| 63 | + import re as _re |
| 64 | + class LooseVersion(object): |
| 65 | + def __init__(self, vstring): |
| 66 | + self.vstring = str(vstring) |
| 67 | + self._cmp_key = self._parse(self.vstring) |
| 68 | + @staticmethod |
| 69 | + def _parse(s): |
| 70 | + parts = [] |
| 71 | + for tok in _re.split(r'(\d+)', s): |
| 72 | + if tok.isdigit(): |
| 73 | + parts.append(int(tok)) |
| 74 | + elif tok: |
| 75 | + parts.append(tok) |
| 76 | + return parts |
| 77 | + def __str__(self): |
| 78 | + return self.vstring |
| 79 | + def __repr__(self): |
| 80 | + return 'LooseVersion(%r)' % self.vstring |
| 81 | + def _cmp(self, other): |
| 82 | + if not isinstance(other, LooseVersion): |
| 83 | + other = LooseVersion(other) |
| 84 | + a, b = self._cmp_key, other._cmp_key |
| 85 | + for i in range(max(len(a), len(b))): |
| 86 | + ai = a[i] if i < len(a) else 0 |
| 87 | + bi = b[i] if i < len(b) else 0 |
| 88 | + if type(ai) != type(bi): |
| 89 | + ai, bi = str(ai), str(bi) |
| 90 | + if ai < bi: |
| 91 | + return -1 |
| 92 | + if ai > bi: |
| 93 | + return 1 |
| 94 | + return 0 |
| 95 | + def __lt__(self, other): return self._cmp(other) < 0 |
| 96 | + def __le__(self, other): return self._cmp(other) <= 0 |
| 97 | + def __eq__(self, other): return self._cmp(other) == 0 |
| 98 | + def __ge__(self, other): return self._cmp(other) >= 0 |
| 99 | + def __gt__(self, other): return self._cmp(other) > 0 |
| 100 | + def __ne__(self, other): return self._cmp(other) != 0 |
60 | 101 |
|
61 | 102 | if not hasattr(subprocess, 'check_output'): |
62 | 103 | def check_output(*popenargs, **kwargs): |
@@ -4514,6 +4555,8 @@ def GetMyDistro(dist_class_name=''): |
4514 | 4555 | Distro = 'oracle' |
4515 | 4556 | elif ('redhat'.lower() in Distro.lower()): |
4516 | 4557 | Distro = 'redhat' |
| 4558 | + elif ('azurelinux' in Distro.lower()): |
| 4559 | + Distro = 'fedora' |
4517 | 4560 | elif ('Kali'.lower() in Distro.lower()): |
4518 | 4561 | Distro = 'Kali' |
4519 | 4562 | elif ('FreeBSD'.lower() in Distro.lower() or 'gaia'.lower() in Distro.lower() or 'panos'.lower() in Distro.lower()): |
@@ -4555,6 +4598,21 @@ def DistInfo(fullname=0): |
4555 | 4598 | return distinfo |
4556 | 4599 | if 'Linux' in platform.system(): |
4557 | 4600 | distinfo = ["Default"] |
| 4601 | + # On Python 3.8+ linux_distribution is removed; detect via /etc/os-release |
| 4602 | + try: |
| 4603 | + with open("/etc/os-release", "r") as f: |
| 4604 | + os_id, os_version = "", "" |
| 4605 | + for line in f: |
| 4606 | + k, _, v = line.strip().partition("=") |
| 4607 | + v = v.strip('"') |
| 4608 | + if k == "ID": |
| 4609 | + os_id = v |
| 4610 | + elif k == "VERSION_ID": |
| 4611 | + os_version = v |
| 4612 | + if os_id == "azurelinux": |
| 4613 | + return ["azurelinux", os_version] |
| 4614 | + except Exception: |
| 4615 | + pass |
4558 | 4616 | if "ubuntu" in platform.version().lower(): |
4559 | 4617 | distinfo[0] = "Ubuntu" |
4560 | 4618 | elif 'suse' in platform.version().lower(): |
|
0 commit comments