X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2F__init__.py;h=fb5316936c1d56348647adfde5c5f649821eef05;hb=d0af985239882d85f2b5d8ef75ed230102e78ed8;hp=0b61594e5495604eaeb2cee02aa075dfa2faeccf;hpb=6c55499bee9cc4aa143c11da9eb12abc8cdc6816;p=tools%2Fsat.git diff --git a/src/__init__.py b/src/__init__.py index 0b61594..fb53169 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -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 @@ -62,6 +68,19 @@ def check_config_has_application( config, details = None ): details.append(message) raise SatException( message ) +def check_config_has_profile( config, details = None ): + '''check that the config has the key APPLICATION.profile. + Else, raise an exception. + + :param config class 'common.pyconf.Config': The config. + ''' + check_config_has_application(config) + if 'profile' not in config.APPLICATION: + message = _("A profile section is required in your application.\n") + if details : + details.append(message) + raise SatException( message ) + def config_has_application( config ): return 'APPLICATION' in config @@ -101,13 +120,51 @@ def get_base_path(config): :return: The path of the product base. :rtype: str ''' - if "base" in config.APPLICATION: - base_name = config.APPLICATION.base - base_path = config.USER.bases[base_name] + 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.bases.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') + +def read_config_from_a_file(filePath): + try: + cfg_file = pyconf.Config(filePath) + except pyconf.ConfigError as e: + raise SatException(_("Error in configuration file: %(file)s\n %(error)s") % \ + { 'file': filePath, 'error': str(e) }) + return cfg_file + +def get_tmp_filename(cfg, name): + if not os.path.exists(cfg.VARS.tmp_root): + os.makedirs(cfg.VARS.tmp_root) + + return os.path.join(cfg.VARS.tmp_root, name) ## # Utils class to simplify path manipulations. @@ -136,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)] @@ -219,10 +279,83 @@ class Path: except: return False +def find_file_in_lpath(file_name, lpath, additional_dir = ""): + """Find in all the directories in lpath list the file that has the same name + as file_name. If it is found, return the full path of the file, else, + return False. + The additional_dir (optional) is the name of the directory to add to all + paths in lpath. + + :param file_name str: The file name to search + :param lpath List: The list of directories where to search + :param additional_dir str: The name of the additional directory + :return: the full path of the file or False if not found + :rtype: str + """ + for directory in lpath: + dir_complete = os.path.join(directory, additional_dir) + if not os.path.isdir(directory) or not os.path.isdir(dir_complete): + continue + l_files = os.listdir(dir_complete) + for file_n in l_files: + if file_n == file_name: + return os.path.join(dir_complete, file_name) + return False + def handleRemoveReadonly(func, path, exc): excvalue = exc[1] if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES: os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777 func(path) else: - raise \ No newline at end of file + raise + +def deepcopy_list(input_list): + """ Do a deep copy of a list + + :param input_list List: The list to copy + :return: The copy of the list + :rtype: List + """ + res = [] + for elem in input_list: + res.append(elem) + 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 by in file + ''' + 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