diff -r 9c1f429cb56b -r b47dfa7a137d src/eric7/Globals/__init__.py --- a/src/eric7/Globals/__init__.py Sun Dec 18 14:19:10 2022 +0100 +++ b/src/eric7/Globals/__init__.py Sun Dec 18 19:33:46 2022 +0100 @@ -14,17 +14,33 @@ import contextlib import os import re -import sys -import sysconfig + +from PyQt6.QtCore import QByteArray, QCoreApplication, QProcess, qVersion + +from eric7.SystemUtilities.DesktopUtilities import ( # __IGNORE_FLAKES_WARNING__ + desktopName, + isGnomeDesktop, + isKdeDesktop, + isWaylandSession, + sessionType, +) -from PyQt6.QtCore import ( - QT_VERSION, - QByteArray, - QCoreApplication, - QDir, - QLibraryInfo, - QProcess, - qVersion, +# imports from eric7.SystemUtilities are for backward compatibility +from eric7.SystemUtilities.OSUtilities import ( # __IGNORE_FLAKES_WARNING__ + isLinuxPlatform, + isMacPlatform, + isWindowsPlatform, +) +from eric7.SystemUtilities.PythonUtilities import ( # __IGNORE_FLAKES_WARNING__ + getPythonExecutable, + getPythonLibraryDirectory, + getPythonScriptsDirectory, +) +from eric7.SystemUtilities.QtUtilities import ( # __IGNORE_FLAKES_WARNING__ + getPyQt6ModulesDirectory, + getPyQtToolsPath, + getQtBinariesPath, + qVersionTuple, ) try: @@ -54,162 +70,6 @@ configDir = None -def isWindowsPlatform(): - """ - Function to check, if this is a Windows platform. - - @return flag indicating Windows platform - @rtype bool - """ - return sys.platform.startswith(("win", "cygwin")) - - -def isMacPlatform(): - """ - Function to check, if this is a Mac platform. - - @return flag indicating Mac platform - @rtype bool - """ - return sys.platform == "darwin" - - -def isLinuxPlatform(): - """ - Function to check, if this is a Linux platform. - - @return flag indicating Linux platform - @rtype bool - """ - return sys.platform.startswith("linux") - - -def desktopName(): - """ - Function to determine the name of the desktop environment used - (Linux only). - - @return name of the desktop environment - @rtype str - """ - if not isLinuxPlatform(): - return "" - - currDesktop = os.environ.get("XDG_CURRENT_DESKTOP", "") - if currDesktop: - return currDesktop - - currDesktop = os.environ.get("XDG_SESSION_DESKTOP", "") - if currDesktop: - return currDesktop - - currDesktop = os.environ.get("GDMSESSION", "") - if currDesktop: - return currDesktop - - currDesktop = os.environ.get("GNOME_DESKTOP_SESSION_ID", "") - if currDesktop: - return currDesktop - - currDesktop = os.environ.get("KDE_FULL_SESSION", "") - if currDesktop: - if currDesktop == "true": - return "KDE" - - return currDesktop - - currDesktop = os.environ.get("DESKTOP_SESSION", "") - if currDesktop: - return currDesktop - - return "" - - -def isKdeDesktop(): - """ - Function to check, if the current session is a KDE desktop (Linux only). - - @return flag indicating a KDE desktop - @rtype bool - """ - if not isLinuxPlatform(): - return False - - isKDE = False - - desktop = ( - os.environ.get("XDG_CURRENT_DESKTOP", "").lower() - or os.environ.get("XDG_SESSION_DESKTOP", "").lower() - or os.environ.get("DESKTOP_SESSION", "").lower() - ) - isKDE = ( - "kde" in desktop or "plasma" in desktop - if desktop - else bool(os.environ.get("KDE_FULL_SESSION", "")) - ) - - return isKDE - - -def isGnomeDesktop(): - """ - Function to check, if the current session is a Gnome desktop (Linux only). - - @return flag indicating a Gnome desktop - @rtype bool - """ - if not isLinuxPlatform(): - return False - - isGnome = False - - desktop = ( - os.environ.get("XDG_CURRENT_DESKTOP", "").lower() - or os.environ.get("XDG_SESSION_DESKTOP", "").lower() - or os.environ.get("GDMSESSION", "").lower() - ) - isGnome = ( - "gnome" in desktop - if desktop - else bool(os.environ.get("GNOME_DESKTOP_SESSION_ID", "")) - ) - - return isGnome - - -def sessionType(): - """ - Function to determine the name of the running session (Linux only). - - @return name of the desktop environment - @rtype str - """ - if not isLinuxPlatform(): - return "" - - sessionType = os.environ.get("XDG_SESSION_TYPE", "").lower() - if "x11" in sessionType: - return "X11" - elif "wayland" in sessionType: - return "Wayland" - - sessionType = os.environ.get("WAYLAND_DISPLAY", "").lower() - if "wayland" in sessionType: - return "Wayland" - - return "" - - -def isWaylandSession(): - """ - Function to check, if the current session is a wayland session. - - @return flag indicating a wayland session - @rtype bool - """ - return sessionType() == "Wayland" - - def getConfigDir(): """ Module function to get the name of the directory storing the config data. @@ -256,169 +116,6 @@ configDir = os.path.expanduser(d) -def getPythonExecutable(): - """ - Function to determine the path of the (non-windowed) Python executable. - - @return path of the Python executable - @rtype str - """ - if sys.platform.startswith("linux"): - return sys.executable - elif sys.platform == "darwin": - return sys.executable.replace("pythonw", "python") - else: - return sys.executable.replace("pythonw.exe", "python.exe") - - -def getPythonLibraryDirectory(): - """ - Function to determine the path to Python's library directory. - - @return path to the Python library directory - @rtype str - """ - return sysconfig.get_path("platlib") - - -def getPythonScriptsDirectory(): - """ - Function to determine the path to Python's scripts directory. - - @return path to the Python scripts directory - @rtype str - """ - return sysconfig.get_path("scripts") - - -def getPyQt6ModulesDirectory(): - """ - Function to determine the path to PyQt6 modules directory. - - @return path to the PyQt6 modules directory - @rtype str - """ - pyqtPath = os.path.join(sysconfig.get_path("platlib"), "PyQt6") - if os.path.exists(pyqtPath): - return pyqtPath - - return "" - - -def getPyQtToolsPath(version=5): - """ - Module function to get the path of the PyQt tools. - - @param version PyQt major version - @type int - @return path to the PyQt tools - @rtype str - """ - from eric7 import Preferences - from eric7.EricWidgets.EricApplication import ericApp - - toolsPath = "" - - # step 1: check, if the user has configured a tools path - if version == 5: - toolsPath = Preferences.getQt("PyQtToolsDir") - venvName = Preferences.getQt("PyQtVenvName") - elif version == 6: - toolsPath = Preferences.getQt("PyQt6ToolsDir") - venvName = Preferences.getQt("PyQt6VenvName") - - # step 2: determine from used Python interpreter (pylupdate is test object) - if not toolsPath: - program = "pylupdate{0}".format(version) - if venvName: - venvManager = ericApp().getObject("VirtualEnvManager") - dirName = venvManager.getVirtualenvDirectory(venvName) - else: - dirName = os.path.dirname(sys.executable) - - if isWindowsPlatform(): - program += ".exe" - if os.path.exists(os.path.join(dirName, program)): - toolsPath = dirName - elif os.path.exists(os.path.join(dirName, "Scripts", program)): - toolsPath = os.path.join(dirName, "Scripts") - else: - if os.path.exists(os.path.join(dirName, program)): - toolsPath = dirName - elif os.path.exists(os.path.join(dirName, "bin", program)): - toolsPath = os.path.join(dirName, "bin") - - return toolsPath - - -def getQtBinariesPath(libexec=False): - """ - Module function to get the path of the Qt binaries. - - @param libexec flag indicating to get the path of the executable library - (defaults to False) - @type bool (optional) - @return path of the Qt binaries - @rtype str - """ - from eric7 import Preferences - - binPath = "" - - # step 1: check, if the user has configured a tools path - qtToolsDir = Preferences.getQt("QtToolsDir") - if qtToolsDir: - if libexec: - binPath = os.path.join(qtToolsDir, "..", "libexec") - if not os.path.exists(binPath): - binPath = qtToolsDir - else: - binPath = Preferences.getQt("QtToolsDir") - if not os.path.exists(binPath): - binPath = "" - - # step 2: try the qt6_applications package - if not binPath: - with contextlib.suppress(ImportError): - # if qt6-applications is not installed just go to the next step - import qt6_applications # __IGNORE_WARNING_I10__ - - if libexec: - binPath = os.path.join( - os.path.dirname(qt6_applications.__file__), "Qt", "libexec" - ) - if not os.path.exists(binPath): - binPath = os.path.join( - os.path.dirname(qt6_applications.__file__), "Qt", "bin" - ) - else: - binPath = os.path.join( - os.path.dirname(qt6_applications.__file__), "Qt", "bin" - ) - if not os.path.exists(binPath): - binPath = "" - - # step3: determine via QLibraryInfo - if not binPath: - binPath = ( - QLibraryInfo.path(QLibraryInfo.LibraryPath.LibraryExecutablesPath) - if libexec - else QLibraryInfo.path(QLibraryInfo.LibraryPath.BinariesPath) - ) - - # step 4: determine from used Python interpreter (designer is test object) - if not binPath: - program = "designer" - if isWindowsPlatform(): - program += ".exe" - - progPath = os.path.join(getPythonScriptsDirectory(), program) - if os.path.exists(progPath): - binPath = getPythonScriptsDirectory() - - return QDir.toNativeSeparators(binPath) - - ############################################################################### ## functions for version handling ############################################################################### @@ -451,20 +148,6 @@ return tuple(versionParts[:length]) -def qVersionTuple(): - """ - Module function to get the Qt version as a tuple. - - @return Qt version as a tuple - @rtype tuple of int - """ - return ( - (QT_VERSION & 0xFF0000) >> 16, - (QT_VERSION & 0xFF00) >> 8, - QT_VERSION & 0xFF, - ) - - ############################################################################### ## functions for extended string handling ############################################################################### @@ -548,9 +231,9 @@ @return converted data @rtype bool """ - if value in ["true", "1", "True"]: + if value in ["True", "true", "1", "Yes", "yes"]: return True - elif value in ["false", "0", "False"]: + elif value in ["False", "false", "0", "No", "no"]: return False else: return bool(value)