Example #1
0
    def test_freedesktop_os_release(self):
        self.addCleanup(self.clear_caches)
        self.clear_caches()

        if any(os.path.isfile(fn) for fn in platform._os_release_candidates):
            info = platform.freedesktop_os_release()
            self.assertIn("NAME", info)
            self.assertIn("ID", info)

            info["CPYTHON_TEST"] = "test"
            self.assertNotIn("CPYTHON_TEST", platform.freedesktop_os_release())
        else:
            with self.assertRaises(OSError):
                platform.freedesktop_os_release()
Example #2
0
    def get_linux_name():
        """Returns the name of the linux distribution. Hopefully."""
        # First try: The optional distro package (should always work if available)
        try:
            import distro
        except ImportError:
            pass
        else:
            return distro.name(True)

        # Second try: the new function in platform (py v3.10+ only)
        if hasattr(platform, 'freedesktop_os_release'):
            try:
                return osrelease_dict_to_str(platform.freedesktop_os_release())
            except OSError:
                pass

        # Third try: the old function in platform (until py v3.7 only)
        if hasattr(platform, 'linux_distribution'):
            linux_dist = platform.linux_distribution()
            if any((x for x in linux_dist if x)):
                return '%s %s' % (linux_dist[0], linux_dist[1])

        # Fourth try: read the os-release file directly (to fill the gap btw. 3.7 and 3.10)
        try:
            return osrelease_dict_to_str(read_osrelease())
        except OSError:
            pass

        # We tried hard, but it wasn't enough.
        return None
Example #3
0
    def get_os_release(cls) -> dict:
        """
        Get the freedesktop release info. Mainly for linux operating systems.
        https://www.freedesktop.org/software/systemd/man/os-release.html

        In python 3.10 they introduced the 'freedesktop_os_release' function so if
        we have it we use it. But for older versions I've included a polyfill.

        :return: A dict of release information
        :rtype: dict
        """
        if cls.type() not in ['linux', 'freebsd']:
            return {}

        if hasattr(platform, 'freedesktop_os_release'):
            try:
                return platform.freedesktop_os_release()
            except OSError:
                return {}

        # For backward compatibility with older versions of python
        if os.path.exists('/etc/os-release'):
            path = '/etc/os-release'
        elif os.path.exists('/usr/lib/os-release'):
            path = '/usr/lib/os-release'
        else:
            path = None

        if not path:
            return {}

        with open(path) as f:
            reader = csv.reader(f, delimiter="=")
            return {key: value for key, value in reader}
Example #4
0
class clean(_clean):
    def run(self):
        self.execute(_clean_bins, (), msg="Cleaning binary files and headers")
        self.execute(_clean_native_build, (), msg="Cleaning native build")
        _clean.run(self)

# the build directory needs to exist
#try: os.makedirs(os.path.join(ROOT_DIR, 'build'))
#except OSError: pass

# platform.freedesktop_os_release was added in 3.10
os_id = ''
if hasattr(platform, 'freedesktop_os_release'):
    try:
        osr = platform.freedesktop_os_release()
        print(osr)
        os_id = osr['ID']
    except OSError:
        pass

if 'bdist_wheel' in sys.argv and '--plat-name' not in sys.argv:
    if RELEASE_DIR is None:
        name = get_platform()
        if 'linux' in name:
            # linux_* platform tags are disallowed because the python ecosystem is fubar
            # linux builds should be built in the centos 5 vm for maximum compatibility
            # see https://github.com/pypa/manylinux
            # see also https://github.com/angr/angr-dev/blob/master/admin/bdist.py
            plat_name = 'manylinux1_' + platform.machine()
        elif 'mingw' in name: