Salome HOME
jobs report, display error when jobs are missing somewhere in the week
[tools/sat.git] / src / __init__.py
index de1969cc4663261223d0a4be298b0eabfdd841b9..fb5316936c1d56348647adfde5c5f649821eef05 100644 (file)
@@ -32,10 +32,16 @@ from . import product
 from . import environment
 from . import fileEnviron
 from . import compilation
+from . import test_module
+from . import template
 
 OK_STATUS = "OK"
 KO_STATUS = "KO"
 NA_STATUS = "NA"
+KNOWNFAILURE_STATUS = "KF"
+TIMEOUT_STATUS = "TIMEOUT"
+
+CONFIG_FILENAME = "sat-config.pyconf"
 
 class SatException(Exception):
     '''rename Exception Class
@@ -114,12 +120,34 @@ def get_base_path(config):
     :return: The path of the product base.
     :rtype: str
     '''
-    if "base" in config.SITE:
-        base_path = config.SITE.base
+    if "base" not in config.SITE:
+        site_file_path = os.path.join(config.VARS.salometoolsway,
+                                      "data",
+                                      "site.pyconf")
+        msg = _("Please define a base path in the file %s" % site_file_path)
+        raise SatException(msg)
+
+    return config.SITE.base
+
+def get_salome_version(config):
+    if hasattr(config.APPLICATION, 'version_salome'):
+        Version = config.APPLICATION.version_salome
     else:
-        # default base
-        base_path = config.USER.base
-    return base_path
+        KERNEL_info = product.get_product_config(config, "KERNEL")
+        VERSION = os.path.join(
+                            KERNEL_info.install_dir,
+                            "bin",
+                            "salome",
+                            "VERSION")
+        if not os.path.isfile(VERSION):
+            return None
+            
+        fVERSION = open(VERSION)
+        Version = fVERSION.readline()
+        fVERSION.close()
+        
+    VersionSalome = int(only_numbers(Version))    
+    return VersionSalome
 
 def only_numbers(str_num):
     return ''.join([nb for nb in str_num if nb in '0123456789'] or '0')
@@ -165,6 +193,9 @@ class Path:
     def isdir(self):
         return os.path.isdir(self.path)
 
+    def isfile(self):
+        return os.path.isfile(self.path)
+
     def list(self):
         return [Path(p) for p in os.listdir(self.path)]
 
@@ -289,4 +320,42 @@ def deepcopy_list(input_list):
     res = []
     for elem in input_list:
         res.append(elem)
-    return res
\ No newline at end of file
+    return res
+
+def parse_date(date):
+    """Transform YYYYMMDD_hhmmss into YYYY-MM-DD hh:mm:ss.
+    
+    :param date str: The date to transform
+    :return: The date in the new format
+    :rtype: str
+    """
+    if len(date) != 15:
+        return date
+    res = "%s-%s-%s %s:%s:%s" % (date[0:4],
+                                 date[4:6],
+                                 date[6:8],
+                                 date[9:11],
+                                 date[11:13],
+                                 date[13:])
+    return res
+
+def merge_dicts(*dict_args):
+    '''
+    Given any number of dicts, shallow copy and merge into a new dict,
+    precedence goes to key value pairs in latter dicts.
+    '''
+    result = {}
+    for dictionary in dict_args:
+        result.update(dictionary)
+    return result
+
+def replace_in_file(filein, strin, strout):
+    '''Replace <strin> by <strout> in file <filein>
+    '''
+    shutil.move(filein, filein + "_old")
+    fileout= filein
+    filein = filein + "_old"
+    fin = open(filein, "r")
+    fout = open(fileout, "w")
+    for line in fin:
+        fout.write(line.replace(strin, strout))
\ No newline at end of file