Воркед
This commit is contained in:
1 parent
ac32c55ab9
commit
ee94d8e529
1138 files changed
+55771
-77901
No files matched your search
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright 2015,2016,2017 Nir Cohen
|
||||
# Copyright 2015-2021 Nir Cohen
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -55,7 +55,7 @@ except ImportError:
|
||||
# Python 3.7
|
||||
TypedDict = dict
|
||||
|
||||
__version__ = "1.7.0"
|
||||
__version__ = "1.9.0"
|
||||
|
||||
|
||||
class VersionDict(TypedDict):
|
||||
@@ -122,6 +122,27 @@ _DISTRO_RELEASE_CONTENT_REVERSED_PATTERN = re.compile(
|
||||
# Pattern for base file name of distro release file
|
||||
_DISTRO_RELEASE_BASENAME_PATTERN = re.compile(r"(\w+)[-_](release|version)$")
|
||||
|
||||
# Base file names to be looked up for if _UNIXCONFDIR is not readable.
|
||||
_DISTRO_RELEASE_BASENAMES = [
|
||||
"SuSE-release",
|
||||
"altlinux-release",
|
||||
"arch-release",
|
||||
"base-release",
|
||||
"centos-release",
|
||||
"fedora-release",
|
||||
"gentoo-release",
|
||||
"mageia-release",
|
||||
"mandrake-release",
|
||||
"mandriva-release",
|
||||
"mandrivalinux-release",
|
||||
"manjaro-release",
|
||||
"oracle-release",
|
||||
"redhat-release",
|
||||
"rocky-release",
|
||||
"sl-release",
|
||||
"slackware-version",
|
||||
]
|
||||
|
||||
# Base file names to be ignored when searching for distro release file
|
||||
_DISTRO_RELEASE_IGNORE_BASENAMES = (
|
||||
"debian_version",
|
||||
@@ -131,6 +152,8 @@ _DISTRO_RELEASE_IGNORE_BASENAMES = (
|
||||
"system-release",
|
||||
"plesk-release",
|
||||
"iredmail-release",
|
||||
"board-release",
|
||||
"ec2_version",
|
||||
)
|
||||
|
||||
|
||||
@@ -200,6 +223,7 @@ def id() -> str:
|
||||
"opensuse" openSUSE
|
||||
"amzn" Amazon Linux
|
||||
"arch" Arch Linux
|
||||
"buildroot" Buildroot
|
||||
"cloudlinux" CloudLinux OS
|
||||
"exherbo" Exherbo Linux
|
||||
"gentoo" GenToo Linux
|
||||
@@ -221,6 +245,8 @@ def id() -> str:
|
||||
"midnightbsd" MidnightBSD
|
||||
"rocky" Rocky Linux
|
||||
"aix" AIX
|
||||
"guix" Guix System
|
||||
"altlinux" ALT Linux
|
||||
============== =========================================
|
||||
|
||||
If you have a need to get distros for reliable IDs added into this set,
|
||||
@@ -876,6 +902,9 @@ class LinuxDistribution:
|
||||
if self.uname_attr("id").startswith("aix"):
|
||||
# On AIX platforms, prefer oslevel command output.
|
||||
versions.insert(0, self.oslevel_info())
|
||||
elif self.id() == "debian" or "debian" in self.like().split():
|
||||
# On Debian-like, add debian_version file content to candidates list.
|
||||
versions.append(self._debian_version)
|
||||
version = ""
|
||||
if best:
|
||||
# This algorithm uses the last version in priority order that has
|
||||
@@ -966,10 +995,10 @@ class LinuxDistribution:
|
||||
|
||||
For details, see :func:`distro.info`.
|
||||
"""
|
||||
return dict(
|
||||
return InfoDict(
|
||||
id=self.id(),
|
||||
version=self.version(pretty, best),
|
||||
version_parts=dict(
|
||||
version_parts=VersionDict(
|
||||
major=self.major_version(best),
|
||||
minor=self.minor_version(best),
|
||||
build_number=self.build_number(best),
|
||||
@@ -1186,6 +1215,16 @@ class LinuxDistribution:
|
||||
return ""
|
||||
return self._to_str(stdout).strip()
|
||||
|
||||
@cached_property
|
||||
def _debian_version(self) -> str:
|
||||
try:
|
||||
with open(
|
||||
os.path.join(self.etc_dir, "debian_version"), encoding="ascii"
|
||||
) as fp:
|
||||
return fp.readline().rstrip()
|
||||
except FileNotFoundError:
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def _parse_uname_content(lines: Sequence[str]) -> Dict[str, str]:
|
||||
if not lines:
|
||||
@@ -1228,14 +1267,14 @@ class LinuxDistribution:
|
||||
# file), because we want to use what was specified as best as
|
||||
# possible.
|
||||
match = _DISTRO_RELEASE_BASENAME_PATTERN.match(basename)
|
||||
if "name" in distro_info and "cloudlinux" in distro_info["name"].lower():
|
||||
distro_info["id"] = "cloudlinux"
|
||||
elif match:
|
||||
distro_info["id"] = match.group(1)
|
||||
return distro_info
|
||||
else:
|
||||
try:
|
||||
basenames = os.listdir(self.etc_dir)
|
||||
basenames = [
|
||||
basename
|
||||
for basename in os.listdir(self.etc_dir)
|
||||
if basename not in _DISTRO_RELEASE_IGNORE_BASENAMES
|
||||
and os.path.isfile(os.path.join(self.etc_dir, basename))
|
||||
]
|
||||
# We sort for repeatability in cases where there are multiple
|
||||
# distro specific files; e.g. CentOS, Oracle, Enterprise all
|
||||
# containing `redhat-release` on top of their own.
|
||||
@@ -1245,39 +1284,29 @@ class LinuxDistribution:
|
||||
# sure about the *-release files. Check common entries of
|
||||
# /etc for information. If they turn out to not be there the
|
||||
# error is handled in `_parse_distro_release_file()`.
|
||||
basenames = [
|
||||
"SuSE-release",
|
||||
"arch-release",
|
||||
"base-release",
|
||||
"centos-release",
|
||||
"fedora-release",
|
||||
"gentoo-release",
|
||||
"mageia-release",
|
||||
"mandrake-release",
|
||||
"mandriva-release",
|
||||
"mandrivalinux-release",
|
||||
"manjaro-release",
|
||||
"oracle-release",
|
||||
"redhat-release",
|
||||
"rocky-release",
|
||||
"sl-release",
|
||||
"slackware-version",
|
||||
]
|
||||
basenames = _DISTRO_RELEASE_BASENAMES
|
||||
for basename in basenames:
|
||||
if basename in _DISTRO_RELEASE_IGNORE_BASENAMES:
|
||||
continue
|
||||
match = _DISTRO_RELEASE_BASENAME_PATTERN.match(basename)
|
||||
if match:
|
||||
filepath = os.path.join(self.etc_dir, basename)
|
||||
distro_info = self._parse_distro_release_file(filepath)
|
||||
if "name" in distro_info:
|
||||
# The name is always present if the pattern matches
|
||||
self.distro_release_file = filepath
|
||||
distro_info["id"] = match.group(1)
|
||||
if "cloudlinux" in distro_info["name"].lower():
|
||||
distro_info["id"] = "cloudlinux"
|
||||
return distro_info
|
||||
return {}
|
||||
if match is None:
|
||||
continue
|
||||
filepath = os.path.join(self.etc_dir, basename)
|
||||
distro_info = self._parse_distro_release_file(filepath)
|
||||
# The name is always present if the pattern matches.
|
||||
if "name" not in distro_info:
|
||||
continue
|
||||
self.distro_release_file = filepath
|
||||
break
|
||||
else: # the loop didn't "break": no candidate.
|
||||
return {}
|
||||
|
||||
if match is not None:
|
||||
distro_info["id"] = match.group(1)
|
||||
|
||||
# CloudLinux < 7: manually enrich info with proper id.
|
||||
if "cloudlinux" in distro_info.get("name", "").lower():
|
||||
distro_info["id"] = "cloudlinux"
|
||||
|
||||
return distro_info
|
||||
|
||||
def _parse_distro_release_file(self, filepath: str) -> Dict[str, str]:
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user