Salome HOME
Code improvements, review and simplifications (2)
[modules/adao.git] / src / daComposant / daCore / PlatformInfo.py
index 45eafeeaa6d4f73372ea4177f446920aaca1581d..3a01d6a268852e56de7d0328693dde2c6b368313 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2008-2021 EDF R&D
+# Copyright (C) 2008-2022 EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -21,7 +21,7 @@
 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
 
 """
 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
 
 """
-    Informations sur le code et la plateforme, et mise à jour des chemins
+    Informations sur le code et la plateforme, et mise à jour des chemins.
 
     La classe "PlatformInfo" permet de récupérer les informations générales sur
     le code et la plateforme sous forme de strings, ou d'afficher directement
 
     La classe "PlatformInfo" permet de récupérer les informations générales sur
     le code et la plateforme sous forme de strings, ou d'afficher directement
@@ -49,6 +49,7 @@ import sys
 import platform
 import locale
 import logging
 import platform
 import locale
 import logging
+import re
 
 # ==============================================================================
 class PlatformInfo(object):
 
 # ==============================================================================
 class PlatformInfo(object):
@@ -97,13 +98,18 @@ class PlatformInfo(object):
                 __msg += "\n%s%30s : %s" %(__prefix,"platform.dist",str(platform.dist()))
         elif sys.platform.startswith('darwin'):
             if hasattr(platform, 'mac_ver'):
                 __msg += "\n%s%30s : %s" %(__prefix,"platform.dist",str(platform.dist()))
         elif sys.platform.startswith('darwin'):
             if hasattr(platform, 'mac_ver'):
-                __macosxv = {'5': 'Leopard',       '6': 'Snow Leopard', '7': 'Lion',
-                             '8': 'Mountain Lion', '9': 'Mavericks',   '10': 'Yosemite',
-                             '11': 'El Capitan',  '12': 'Sierra'}
+                __macosxv = {
+                     '0': 'Cheetah',       '1': 'Puma',         '2': 'Jaguar',
+                     '3': 'Panther',       '4': 'Tiger',        '5': 'Leopard',
+                     '6': 'Snow Leopard',  '7': 'Lion',         '8': 'Mountain Lion',
+                     '9': 'Mavericks',    '10': 'Yosemite',    '11': 'El Capitan',
+                    '12': 'Sierra',       '13': 'High Sierra', '14': 'Mojave',
+                    '15': 'Catalina',     '16': 'Big Sur',     '17': 'Monterey',
+                    }
                 for key in __macosxv:
                     if (platform.mac_ver()[0].split('.')[1] == key):
                         __msg += "\n%s%30s : %s" %(__prefix,
                 for key in __macosxv:
                     if (platform.mac_ver()[0].split('.')[1] == key):
                         __msg += "\n%s%30s : %s" %(__prefix,
-                            "platform.mac_ver",str(platform.mac_ver()[0]+"(" + macosx_dict[key]+")"))
+                            "platform.mac_ver",str(platform.mac_ver()[0]+"(" + __macosxv[key]+")"))
             elif hasattr(platform, 'dist'):
                 __msg += "\n%s%30s : %s" %(__prefix,"platform.dist",str(platform.dist()))
         elif os.name == 'nt':
             elif hasattr(platform, 'dist'):
                 __msg += "\n%s%30s : %s" %(__prefix,"platform.dist",str(platform.dist()))
         elif os.name == 'nt':
@@ -116,6 +122,12 @@ class PlatformInfo(object):
         __msg += "\n%s%30s : %s" %(__prefix,"sys.getfilesystemencoding",str(sys.getfilesystemencoding()))
         __msg += "\n%s%30s : %s" %(__prefix,"locale.getdefaultlocale",str(locale.getdefaultlocale()))
         __msg += "\n"
         __msg += "\n%s%30s : %s" %(__prefix,"sys.getfilesystemencoding",str(sys.getfilesystemencoding()))
         __msg += "\n%s%30s : %s" %(__prefix,"locale.getdefaultlocale",str(locale.getdefaultlocale()))
         __msg += "\n"
+        __msg += "\n%s%30s : %s" %(__prefix,"os.cpu_count",os.cpu_count())
+        if hasattr(os, 'sched_getaffinity'):
+            __msg += "\n%s%30s : %s" %(__prefix,"len(os.sched_getaffinity(0))",len(os.sched_getaffinity(0)))
+        else:
+            __msg += "\n%s%30s : %s" %(__prefix,"len(os.sched_getaffinity(0))","Unsupported on this platform")
+        __msg += "\n"
         __msg += "\n%s%30s : %s" %(__prefix,"platform.node",platform.node())
         __msg += "\n%s%30s : %s" %(__prefix,"os.path.expanduser",os.path.expanduser('~'))
         return __msg
         __msg += "\n%s%30s : %s" %(__prefix,"platform.node",platform.node())
         __msg += "\n%s%30s : %s" %(__prefix,"os.path.expanduser",os.path.expanduser('~'))
         return __msg
@@ -287,6 +299,34 @@ def date2int( __date, __lang="FR" ):
         raise ValueError("Cannot convert \"%s\" as a D/M/Y H:M date"%d)
     return __number
 
         raise ValueError("Cannot convert \"%s\" as a D/M/Y H:M date"%d)
     return __number
 
+def strvect2liststr( __strvect ):
+    """
+    Fonction de secours, conversion d'une chaîne de caractères de
+    représentation de vecteur en une liste de chaînes de caractères de
+    représentation de flottants
+    """
+    for s in ("array", "matrix", "list", "tuple", "[", "]", "(", ")"):
+        __strvect = __strvect.replace(s,"")  # Rien
+    for s in (",", ";"):
+        __strvect = __strvect.replace(s," ") # Blanc
+    return __strvect.split()
+
+def strmatrix2liststr( __strvect ):
+    """
+    Fonction de secours, conversion d'une chaîne de caractères de
+    représentation de matrice en une liste de chaînes de caractères de
+    représentation de flottants
+    """
+    for s in ("array", "matrix", "list", "tuple", "[", "(", "'", '"'):
+        __strvect = __strvect.replace(s,"")  # Rien
+    __strvect = __strvect.replace(","," ") # Blanc
+    for s in ("]", ")"):
+        __strvect = __strvect.replace(s,";") # "]" et ")" par ";"
+    __strvect = re.sub(';\s*;',';',__strvect)
+    __strvect = __strvect.rstrip(";") # Après ^ et avant v
+    __strmat = [l.split() for l in __strvect.split(";")]
+    return __strmat
+
 def checkFileNameConformity( __filename, __warnInsteadOfPrint=True ):
     if sys.platform.startswith("win") and len(__filename) > 256:
         __conform = False
 def checkFileNameConformity( __filename, __warnInsteadOfPrint=True ):
     if sys.platform.startswith("win") and len(__filename) > 256:
         __conform = False