Salome HOME
limit the impact for users not having psutil
[tools/sat.git] / src / __init__.py
index 02f27a6e521a8ae290942c1331fa2c4c930b1bd2..9a4a846ed54b7d8bce23b4609cd9e062f45a2cc0 100644 (file)
@@ -55,8 +55,13 @@ KNOWNFAILURE_STATUS = "KF"
 TIMEOUT_STATUS = "TIMEOUT"
 
 class SatException(Exception):
-    """rename Exception Class"""
-    pass
+    """sat exception class"""
+    def message(self, arg):
+        if sys.version_info[0] >= 3:
+            # message method is not available for python 3.8+
+            return super().msg(arg)
+        else:
+            return super(SatException,self).message(arg)
 
 def ensure_path_exists(p):
     """Create a path if not existing
@@ -91,6 +96,27 @@ def check_config_has_profile( config, details = None ):
             details.append(message)
         raise SatException( message )
 
+def appli_test_property(config,property_name, property_value):
+    """Generic function to test if an application has a property set to a value
+    :param config class 'common.pyconf.Config': The config.
+    :param property_name : The name of the property to check
+    :param property_value : The value of the property to test
+    :return: True if the application has the property set to property_value
+    :rtype: boolean
+    """
+    # first check if application has property_value
+    if not ("APPLICATION"  in config and
+            "properties"   in config.APPLICATION and
+            property_name  in config.APPLICATION.properties):
+        return False
+
+    # then check to the property is set to property_value
+    eval_expression = 'config.APPLICATION.properties.%s == "%s"' %\
+                      (property_name,property_value)
+    result = eval(eval_expression)
+    return result
+    
+
 def config_has_application( config ):
     return 'APPLICATION' in config
 
@@ -209,6 +235,23 @@ def get_launcher_name(config):
 
     return launcher_name
 
+def get_launcher_exe(config):
+    """\
+    Returns the name of exe defined in profile section.
+    
+    :param config Config: The global Config instance.
+    :return: The name of the exe to use in launcher.
+    :rtype: str
+    """
+    check_config_has_application(config)
+    if 'profile' in config.APPLICATION and 'exe' in config.APPLICATION.profile:
+        exe_name = config.APPLICATION.profile.exe
+    else:
+        exe_name = None
+
+    return exe_name
+
+
 def get_log_path(config):
     """\
     Returns the path of the logs.
@@ -228,6 +271,15 @@ def get_log_path(config):
     
     return log_dir_path
 
+def get_salometool_version(config):
+   """Return the salomeTool version.
+
+   :param config Config: The global Config instance.
+   :return: the description of this version of sat in terms of tag and commit
+   """
+   return config.LOCAL.tag
+
+
 def get_salome_version(config):
     import versionMinorMajorPatch as VMMP
 
@@ -404,7 +456,7 @@ def find_file_in_lpath(file_name, lpath, additional_dir = ""):
                 return os.path.join(dir_complete, file_name)
     return False
 
-def find_file_in_ftppath(file_name, ftppath, installation_dir, logger):
+def find_file_in_ftppath(file_name, ftppath, installation_dir, logger, additional_dir = ""):
     """\
     Find in all ftp servers in ftppath the file called file_name
     If it is found then return the destination path of the file
@@ -443,8 +495,20 @@ def find_file_in_ftppath(file_name, ftppath, installation_dir, logger):
            for directory in ftp_archive_split[1:]:
                logger.write("   Change directory to %s\n" % directory, 3)
                ftp.cwd(directory)
+           if additional_dir:
+               ftp.cwd(additional_dir)
        except:
            logger.error("while connecting to ftp server %s\n" % ftp_server)
+           continue
+
+       try:  # get md5 file if it exists
+           file_name_md5=file_name + ".md5"
+           destination_md5=destination + ".md5"
+           if ftp.size(file_name_md5) > 0:
+               with open(destination_md5,'wb') as dest_file_md5:
+                   ftp.retrbinary("RETR "+file_name_md5, dest_file_md5.write)
+       except:
+           pass
 
        try:
            if ftp.size(file_name) > 0:
@@ -455,7 +519,6 @@ def find_file_in_ftppath(file_name, ftppath, installation_dir, logger):
                return destination
        except:
            logger.error("File not found in ftp_archive %s\n" % ftp_server)
-           pass
 
     return False