How to use the distro.version function in distro

To help you get started, we’ve selected a few distro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nir0s / distro / tests / test_distro.py View on Github external
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
github mrJean1 / PyGeodesy / test / base.py View on Github external
def nix_ver():  # *nix release
        try:  # no subprocess.check_output ...
            v = distro.version()
        except AttributeError:  # ... Python 2.6
            v = ''
        return anstr(v), _os_bitstr
github asottile / pip-custom-platform / pip_custom_platform / default_platform.py View on Github external
On OS X and Windows, just uses the default platform name. On Linux, uses
    information from the `platform` module to try to make something reasonable.
    """
    def grab_version(string, num):
        """Grab the `num` most significant components of a version string.

        >>> grab_version('12.04.1', 2)
        '12.04'
        >>> grab_version('8.2', 1)
        '8'
        """
        return '.'.join(string.split('.')[:num])

    if platform.system() == 'Linux':
        dist, version = distro.id(), distro.version()
        dist = re.sub('linux$', '', dist.lower()).strip()

        # Try to determine a good "release" name. This is highly dependent on
        # distribution and what guarantees they provide between versions.
        release = None

        if dist in {'debian', 'rhel', 'centos', 'fedora', 'opensuse'}:
            release = grab_version(version, 1)  # one version component
        elif dist in {'ubuntu', 'amzn'}:
            release = grab_version(version, 2)  # two version components

        if release:
            return 'linux_{dist}_{release}_{arch}'.format(
                dist=_sanitize_platform(dist),
                release=_sanitize_platform(release),
                arch=_sanitize_platform(platform.machine()),
github rockstor / rockstor-core / src / rockstor / smart_manager / data_collector.py View on Github external
def send_distroinfo(self):
        while self.start:
            data = {'distro': self.os_distro_name, 'version': distro.version()}
            self.emit('distro_info',
                      {'key': 'sysinfo:distro_info', 'data': data})
            gevent.sleep(600)
github conan-io / conan / conans / client / tools / oss.py View on Github external
def _get_linux_distro_info(self):
        import distro
        self.linux_distro = distro.id()
        self.os_version = Version(distro.version())
        version_name = distro.codename()
        self.os_version_name = version_name if version_name != "n/a" else ""
        if not self.os_version_name and self.linux_distro == "debian":
            self.os_version_name = self.get_debian_version_name(self.os_version)
github rpm-software-management / mock / mock / py / mockbuild / util.py View on Github external
def _prepare_nspawn_command(chrootPath, user, cmd, nspawn_args=None, env=None, cwd=None):
    cmd_is_list = isinstance(cmd, list)
    if nspawn_args is None:
        nspawn_args = []
    if user:
        # user can be either id or name
        if cmd_is_list:
            cmd = ['-u', str(user)] + cmd
        else:
            raise exception.Error('Internal Error: command must be list or shell=True.')
    elif not cmd_is_list:
        cmd = [cmd]
    nspawn_argv = ['/usr/bin/systemd-nspawn', '-q', '-M', uuid.uuid4().hex, '-D', chrootPath]
    distro_label = distro.linux_distribution(full_distribution_name=False)[0]
    try:
        distro_version = float(distro.version() or 0)
    except ValueError:
        distro_version = 0
    if distro_label not in RHEL_CLONES or distro_version >= 7.5:
        # EL < 7.5 does not support the nspawn -a option. See BZ 1417387
        nspawn_argv += ['-a']
    nspawn_argv.extend(nspawn_args)
    if cwd:
        nspawn_argv.append('--chdir={0}'.format(cwd))
    if env:
        for k, v in env.items():
            nspawn_argv.append('--setenv={0}={1}'.format(k, v))
    cmd = nspawn_argv + cmd
    if cmd_is_list:
        return cmd
    else:
        return " ".join(cmd)
github iterative / dvc / dvc / analytics.py View on Github external
"os": "windows",
            "windows_version_build": version.build,
            "windows_version_major": version.major,
            "windows_version_minor": version.minor,
            "windows_version_service_pack": version.service_pack,
        }

    if system == "Darwin":
        return {"os": "mac", "mac_version": platform.mac_ver()[0]}

    if system == "Linux":
        return {
            "os": "linux",
            "linux_distro": distro.id(),
            "linux_distro_like": distro.like(),
            "linux_distro_version": distro.version(),
        }

    # We don't collect data for any other system.
    raise NotImplementedError
github cobbler / cobbler / cobbler / utils.py View on Github external
def os_release():
    family = get_family()
    distro_name = distro.name().lower()
    distro_version = distro.version()
    if family == "redhat":
        if "fedora" in distro_name:
            make = "fedora"
        elif "centos" in distro_name:
            make = "centos"
        elif "virtuozzo" in distro_name:
            make = "virtuozzo"
        else:
            make = "redhat"
        return make, float(distro_version)

    elif family == "debian":
        if "debian" in distro_name:
            return "debian", float(distro_version)
        elif "ubuntu" in distro_name:
            return "ubuntu", float(distro_version)