From db1e5d59d9ff35aed83557d24a7bf7429095bcb4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sun, 10 Jun 2018 17:21:56 +0200 Subject: [PATCH] Internal variable names improvements --- src/daComposant/daCore/Interfaces.py | 22 ++++++++++++---------- src/daComposant/daCore/PlatformInfo.py | 26 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/daComposant/daCore/Interfaces.py b/src/daComposant/daCore/Interfaces.py index 0184a30..589e718 100644 --- a/src/daComposant/daCore/Interfaces.py +++ b/src/daComposant/daCore/Interfaces.py @@ -496,40 +496,42 @@ class _YACSViewer(GenericCaseViewer): __fid.close() return __text +# ============================================================================== class ImportFromScript(object): """ - Obtention d'une variable nommee depuis un fichier script importe + Obtention d'une variable nommee depuis un fichier script importé """ + __slots__ = ("__basename", "__filenspace", "__filestring") def __init__(self, __filename=None): "Verifie l'existence et importe le script" if __filename is None: raise ValueError("The name of the file, containing the variable to be read, has to be specified.") if not os.path.isfile(__filename): - raise ValueError("The file containing the variable to be imported doesn't seem to exist. Please check the file. The given file name is:\n \"%s\""%__filename) + raise ValueError("The file containing the variable to be imported doesn't seem to exist. Please check the file. The given file name is:\n \"%s\""%str(__filename)) if os.path.dirname(__filename) != '': sys.path.insert(0, os.path.dirname(__filename)) __basename = os.path.basename(__filename).rstrip(".py") else: __basename = __filename.rstrip(".py") self.__basename = __basename - self.__scriptfile = __import__(__basename, globals(), locals(), []) - self.__scriptstring = open(__filename,'r').read() + self.__filenspace = __import__(__basename, globals(), locals(), []) + self.__filestring = open(__filename,'r').read() def getvalue(self, __varname=None, __synonym=None ): - "Renvoie la variable demandee" + "Renvoie la variable demandee par son nom ou son synonyme" if __varname is None: raise ValueError("The name of the variable to be read has to be specified. Please check the content of the file and the syntax.") - if not hasattr(self.__scriptfile, __varname): + if not hasattr(self.__filenspace, __varname): if __synonym is None: raise ValueError("The imported script file \"%s\" doesn't contain the mandatory variable \"%s\" to be read. Please check the content of the file and the syntax."%(str(self.__basename)+".py",__varname)) - elif not hasattr(self.__scriptfile, __synonym): + elif not hasattr(self.__filenspace, __synonym): raise ValueError("The imported script file \"%s\" doesn't contain the mandatory variable \"%s\" to be read. Please check the content of the file and the syntax."%(str(self.__basename)+".py",__synonym)) else: - return getattr(self.__scriptfile, __synonym) + return getattr(self.__filenspace, __synonym) else: - return getattr(self.__scriptfile, __varname) + return getattr(self.__filenspace, __varname) def getstring(self): "Renvoie le script complet" - return self.__scriptstring + return self.__filestring # ============================================================================== if __name__ == "__main__": diff --git a/src/daComposant/daCore/PlatformInfo.py b/src/daComposant/daCore/PlatformInfo.py index 6192753..fc776bb 100644 --- a/src/daComposant/daCore/PlatformInfo.py +++ b/src/daComposant/daCore/PlatformInfo.py @@ -71,6 +71,11 @@ class PlatformInfo(object): import daCore.version as dav return dav.date + def getYear(self): + "Retourne l'année de création de la version" + import daCore.version as dav + return dav.year + def getPythonVersion(self): "Retourne la version de python disponible" return ".".join([str(x) for x in sys.version_info[0:3]]) # map(str,sys.version_info[0:3])) @@ -189,12 +194,29 @@ has_adao = bool( "ADAO_ROOT_DIR" in os.environ ) has_eficas = bool( "EFICAS_ROOT_DIR" in os.environ ) # ============================================================================== -def uniq(sequence): +def uniq(__sequence): """ Fonction pour rendre unique chaque élément d'une liste, en préservant l'ordre """ __seen = set() - return [x for x in sequence if x not in __seen and not __seen.add(x)] + return [x for x in __sequence if x not in __seen and not __seen.add(x)] + +def date2int(__date, __lang="FR"): + """ + Fonction de secours, conversion pure : dd/mm/yy hh:mm ---> int(yyyymmddhhmm) + """ + __date = __date.strip() + if __date.count('/') == 2 and __date.count(':') == 0 and __date.count(' ') == 0: + d,m,y = __date.split("/") + __number = (10**4)*int(y)+(10**2)*int(m)+int(d) + elif __date.count('/') == 2 and __date.count(':') == 1 and __date.count(' ') > 0: + part1, part2 = __date.split() + d,m,y = part1.strip().split("/") + h,n = part2.strip().split(":") + __number = (10**8)*int(y)+(10**6)*int(m)+(10**4)*int(d)+(10**2)*int(h)+int(n) + else: + raise ValueError("Cannot convert \"%s\" as a D/M/Y H:M date"%d) + return __number # ============================================================================== class PathManagement(object): -- 2.39.2