Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertEqual(distro.linux_distribution(),
MODULE_DISTROI.linux_distribution(full_distribution_name=True))
self.assertEqual(distro.linux_distribution(full_distribution_name=True),
MODULE_DISTROI.linux_distribution())
self.assertEqual(distro.linux_distribution(full_distribution_name=False),
MODULE_DISTROI.linux_distribution(full_distribution_name=False))
self.assertEqual(distro.id(),
MODULE_DISTROI.id())
self.assertEqual(distro.name(),
MODULE_DISTROI.name(pretty=False))
self.assertEqual(distro.name(pretty=False),
MODULE_DISTROI.name())
self.assertEqual(distro.name(pretty=True),
MODULE_DISTROI.name(pretty=True))
self.assertEqual(distro.version(),
MODULE_DISTROI.version(pretty=False))
self.assertEqual(distro.version(pretty=False),
MODULE_DISTROI.version())
self.assertEqual(distro.version(pretty=True),
MODULE_DISTROI.version(pretty=True))
self.assertEqual(distro.version(),
MODULE_DISTROI.version(best=False))
self.assertEqual(distro.version(best=False),
MODULE_DISTROI.version())
self.assertEqual(distro.version(best=True),
MODULE_DISTROI.version(best=True))
self.assertEqual(distro.version_parts(),
# specific release files. Instead, we let the functions use
# the release files of the distro this test runs on, and
# compare the result of the global functions with the result
# of the methods on the global LinuxDistribution object.
self.assertEqual(distro.linux_distribution(),
MODULE_DISTROI.linux_distribution(full_distribution_name=True))
self.assertEqual(distro.linux_distribution(full_distribution_name=True),
MODULE_DISTROI.linux_distribution())
self.assertEqual(distro.linux_distribution(full_distribution_name=False),
MODULE_DISTROI.linux_distribution(full_distribution_name=False))
self.assertEqual(distro.id(),
MODULE_DISTROI.id())
self.assertEqual(distro.name(),
MODULE_DISTROI.name(pretty=False))
self.assertEqual(distro.name(pretty=False),
MODULE_DISTROI.name())
self.assertEqual(distro.name(pretty=True),
MODULE_DISTROI.name(pretty=True))
self.assertEqual(distro.version(),
MODULE_DISTROI.version(pretty=False))
self.assertEqual(distro.version(pretty=False),
MODULE_DISTROI.version())
self.assertEqual(distro.version(pretty=True),
MODULE_DISTROI.version(pretty=True))
self.assertEqual(distro.version(),
MODULE_DISTROI.version(best=False))
self.assertEqual(distro.version(best=False),
MODULE_DISTROI.version())
def test_cli(self):
command = [sys.executable, '-m', 'distro']
desired_output = 'Name: ' + distro.name(pretty=True)
distro_version = distro.version(pretty=True)
distro_codename = distro.codename()
desired_output += '\n' + 'Version: ' + distro_version
desired_output += '\n' + 'Codename: ' + distro_codename
desired_output += '\n'
assert self._run(command) == desired_output
def get_distro_project():
try:
import distro
project = '{0}-{1}'.format(distro.name(), distro.version())
except ImportError:
project = '-'.join(platform.linux_distribution()[0:2])
return slugify(project)
def get_os_info():
if os.name == 'nt' or sys.platform == 'darwin':
return platform.system() + " " + platform.release()
if os.name == 'posix':
try:
import distro
return distro.name(pretty=True)
except ImportError:
return platform.system()
return ''
def get_family():
"""
Get family of running operating system.
Family is the base Linux distribution of a Linux distribution, with a set of common
"""
redhat_list = ("red hat", "redhat", "scientific linux", "fedora", "centos", "virtuozzo")
distro_name = distro.name().lower()
for item in redhat_list:
if item in distro_name:
return "redhat"
if "debian" in distro_name or "ubuntu" in distro_name:
return "debian"
if "suse" in distro.like():
return "suse"
return distro_name
def _grub2_ovmf_tuple():
"""
Returns (1) the absolute filename of the OVMF image to use
and (2) the package name (of the current distro) to install
if the file is missing, as a 2-tuple.
"""
_DEBIAN = 'Debian GNU/Linux'
distro_map = {
'Arch Linux': ('/usr/share/edk2-ovmf/x64/OVMF_CODE.fd', 'edk2-ovmf'),
_DEBIAN: ('/usr/share/OVMF/OVMF_CODE.fd', 'ovmf'),
'Fedora': ('/usr/share/edk2/ovmf/OVMF_CODE.fd', 'edk2-ovmf'),
'Gentoo': ('/usr/share/edk2-ovmf/OVMF_CODE.fd', 'sys-firmware/edk2-ovmf'),
}
distro_map['Ubuntu'] = distro_map[_DEBIAN]
return distro_map.get(distro.name(), distro_map[_DEBIAN])
def get_system_info(): # noqa: D103
system_info = []
if sys.version_info.minor < 8:
distname = platform.linux_distribution()[0]
version = platform.linux_distribution()[1]
else:
import distro
distname = distro.name()
version = distro.version()
if distname != "" and version != "":
os_version = "%s %s (%s %s)" % (platform.system(), platform.release(), distname, version)
else:
os_version = "%s %s" % (platform.system(), platform.release())
system_info.append(("OS Version", os_version))
if hasattr(os, "path"):
system_info.append(("OS Path", os.environ["PATH"]))
if hasattr(sys, "version"):
system_info.append(("Python Version", sys.version))
if hasattr(sys, "subversion"):
system_info.append(("Python Subversion", sys.subversion[0]))
def get_distro_name():
"""Simple wrapper to `distro` to return the current distribution _pretty_ name"""
return distro.name(pretty=True) or None
# Avoid returning 'localhost' when there is a better value to use.
fqdn = socket.gethostname()
system = uname[0]
architecture, _ = platform.architecture()
if system == "Windows":
service_pack = platform.win32_ver()[2]
kernel = uname[3] # 5.1.2600
release = uname[2] # XP, 2000, 7
version = uname[3] + service_pack # 5.1.2600 SP3, 6.1.7601 SP1
elif system == "Darwin":
kernel = uname[2] # 12.2.0
release = "OSX" # OSX
version = platform.mac_ver()[0] # 10.8.2
elif system == "Linux":
kernel = uname[2] # 3.2.5
release = distro.name()
version = distro.version()
# Emulate PEP 425 naming conventions - e.g. cp27-cp27mu-linux_x86_64.
if pep425tags:
pep425tag = "%s%s-%s-%s" % (
pep425tags.get_abbr_impl(), pep425tags.get_impl_ver(),
str(pep425tags.get_abi_tag()).lower(), pep425tags.get_platform())
else:
# For example: windows_7_amd64
pep425tag = "%s_%s_%s" % (system, release, architecture)
return cls(
system=system,
architecture=architecture,
release=release,
version=version,