Salome HOME
Minor corrections for particular file and system support
[modules/adao.git] / src / daComposant / daCore / PlatformInfo.py
index e6468e693d5ace174036900204a507e8d570043f..f08b80a57659ec7b0cbb9007425ef8563e96b5ef 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2008-2018 EDF R&D
+# Copyright (C) 2008-2020 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
@@ -48,6 +48,7 @@ import os
 import sys
 import platform
 import locale
+import logging
 
 # ==============================================================================
 class PlatformInfo(object):
@@ -92,7 +93,7 @@ class PlatformInfo(object):
             if hasattr(platform, 'linux_distribution'):
                 __msg += "\n%s%30s : %s" %(__prefix,
                     "platform.linux_distribution",str(platform.linux_distribution()))
-            else:
+            elif hasattr(platform, 'dist'):
                 __msg += "\n%s%30s : %s" %(__prefix,"platform.dist",str(platform.dist()))
         elif sys.platform.startswith('darwin'):
             if hasattr(platform, 'mac_ver'):
@@ -103,7 +104,7 @@ class PlatformInfo(object):
                     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]+")"))
-            else:
+            elif hasattr(platform, 'dist'):
                 __msg += "\n%s%30s : %s" %(__prefix,"platform.dist",str(platform.dist()))
         elif os.name == 'nt':
             __msg += "\n%s%30s : %s" %(__prefix,"platform.win32_ver",platform.win32_ver()[1])
@@ -283,6 +284,39 @@ def date2int( __date, __lang="FR" ):
         raise ValueError("Cannot convert \"%s\" as a D/M/Y H:M date"%d)
     return __number
 
+def checkFileNameConformity( __filename, __warnInsteadOfPrint=True ):
+    if sys.platform.startswith("win") and len(__filename) > 256:
+        __conform = False
+        __msg = (" For some shared or older file systems on Windows, a file "+\
+            "name longer than 256 characters can lead to access problems."+\
+            "\n  The name of the file in question is the following:"+\
+            "\n  %s")%(__filename,)
+        if __warnInsteadOfPrint: logging.warning(__msg)
+        else:                    print(__msg)
+    else:
+        __conform = True
+    #
+    return __conform
+
+def checkFileNameImportability( __filename, __warnInsteadOfPrint=True ):
+    if str(__filename).count(".") > 1:
+        __conform = False
+        __msg = (" The file name contains %i point(s) before the extension "+\
+            "separator, which can potentially lead to problems when "+\
+            "importing this file into Python, as it can then be recognized "+\
+            "as a sub-module (generating a \"ModuleNotFoundError\"). If it "+\
+            "is intentional, make sure that there is no module with the "+\
+            "same name as the part before the first point, and that there is "+\
+            "no \"__init__.py\" file in the same directory."+\
+            "\n  The name of the file in question is the following:"+\
+            "\n  %s")%(int(str(__filename).count(".")-1), __filename)
+        if __warnInsteadOfPrint: logging.warning(__msg)
+        else:                    print(__msg)
+    else:
+        __conform = True
+    #
+    return __conform
+
 # ==============================================================================
 class PathManagement(object):
     """
@@ -409,4 +443,4 @@ class SystemUsage(object):
 
 # ==============================================================================
 if __name__ == "__main__":
-    print('\n AUTODIAGNOSTIC \n')
+    print('\n AUTODIAGNOSTIC\n')