1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2017 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 Informations sur le code et la plateforme, et mise à jour des chemins
26 La classe "PlatformInfo" permet de récupérer les informations générales sur
27 le code et la plateforme sous forme de strings, ou d'afficher directement
28 les informations disponibles par les méthodes. L'impression directe d'un
29 objet de cette classe affiche les informations minimales. Par exemple :
31 print PlatformInfo().getVersion()
32 created = PlatformInfo().getDate()
34 La classe "PathManagement" permet de mettre à jour les chemins système pour
35 ajouter les outils numériques, matrices... On l'utilise en instanciant
36 simplement cette classe, sans meme récupérer d'objet :
39 __author__ = "Jean-Philippe ARGAUD"
44 # ==============================================================================
45 class PlatformInfo(object):
47 Rassemblement des informations sur le code et la plateforme
54 "Retourne le nom de l'application"
55 import daCore.version as dav
59 "Retourne le numéro de la version"
60 import daCore.version as dav
64 "Retourne la date de création de la version"
65 import daCore.version as dav
68 def getPythonVersion(self):
69 "Retourne la version de python disponible"
70 return ".".join([str(x) for x in sys.version_info[0:3]]) # map(str,sys.version_info[0:3]))
72 def getNumpyVersion(self):
73 "Retourne la version de numpy disponible"
75 return numpy.version.version
77 def getScipyVersion(self):
78 "Retourne la version de scipy disponible"
81 return scipy.version.version
85 def getMatplotlibVersion(self):
86 "Retourne la version de matplotlib disponible"
89 return matplotlib.__version__
93 def getGnuplotVersion(self):
94 "Retourne la version de gnuplotpy disponible"
97 return Gnuplot.__version__
101 def getSphinxVersion(self):
102 "Retourne la version de sphinx disponible"
105 return sphinx.__version__
109 def getNloptVersion(self):
110 "Retourne la version de nlopt disponible"
114 nlopt.version_major(),
115 nlopt.version_minor(),
116 nlopt.version_bugfix(),
121 def getCurrentMemorySize(self):
122 "Retourne la taille mémoire courante utilisée"
125 def MaximumPrecision(self):
126 "Retourne la precision maximale flottante pour Numpy"
129 x = numpy.array([1.,], dtype='float128')
135 def MachinePrecision(self):
136 # Alternative sans module :
140 # eps = (1.0 + eps/2) - 1.0
141 return sys.float_info.epsilon
144 import daCore.version as dav
145 return "%s %s (%s)"%(dav.name,dav.version,dav.date)
147 # ==============================================================================
150 import scipy.optimize
157 has_matplotlib = True
159 has_matplotlib = False
179 # ==============================================================================
182 Fonction pour rendre unique chaque élément d'une liste, en préservant l'ordre
185 return [x for x in sequence if x not in __seen and not __seen.add(x)]
187 # ==============================================================================
188 class PathManagement(object):
190 Mise à jour du path système pour les répertoires d'outils
193 "Déclaration des répertoires statiques"
194 parent = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
196 self.__paths["daExternals"] = os.path.join(parent,"daExternals")
197 self.__paths["daMatrices"] = os.path.join(parent,"daMatrices")
198 self.__paths["daNumerics"] = os.path.join(parent,"daNumerics")
200 for v in self.__paths.values():
201 sys.path.insert(0, v )
203 # Conserve en unique exemplaire chaque chemin
204 sys.path = uniq( sys.path )
209 Renvoie le dictionnaire des chemins ajoutés
213 # ==============================================================================
214 class SystemUsage(object):
216 Permet de récupérer les différentes tailles mémoires du process courant
219 # Le module resource renvoie 0 pour les tailles mémoire. On utilise donc
220 # plutôt : http://code.activestate.com/recipes/286222/ et Wikipedia
222 _proc_status = '/proc/%d/status' % os.getpid()
223 _memo_status = '/proc/meminfo'
225 'o' : 1.0, # Multiples SI de l'octet
229 'kio': 1024.0, # Multiples binaires de l'octet
230 'Mio': 1024.0*1024.0,
231 'Gio': 1024.0*1024.0*1024.0,
232 'B': 1.0, # Multiples binaires du byte=octet
234 'MB' : 1024.0*1024.0,
235 'GB' : 1024.0*1024.0*1024.0,
242 def _VmA(self, VmKey, unit):
243 "Lecture des paramètres mémoire de la machine"
245 t = open(self._memo_status)
249 return 0.0 # non-Linux?
250 i = v.index(VmKey) # get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
251 v = v[i:].split(None, 3) # whitespace
253 return 0.0 # invalid format?
254 # convert Vm value to bytes
255 mem = float(v[1]) * self._scale[v[2]]
256 return mem / self._scale[unit]
258 def getAvailablePhysicalMemory(self, unit="o"):
259 "Renvoie la mémoire physique utilisable en octets"
260 return self._VmA('MemTotal:', unit)
262 def getAvailableSwapMemory(self, unit="o"):
263 "Renvoie la mémoire swap utilisable en octets"
264 return self._VmA('SwapTotal:', unit)
266 def getAvailableMemory(self, unit="o"):
267 "Renvoie la mémoire totale (physique+swap) utilisable en octets"
268 return self._VmA('MemTotal:', unit) + self._VmA('SwapTotal:', unit)
270 def getUsableMemory(self, unit="o"):
271 """Renvoie la mémoire utilisable en octets
272 Rq : il n'est pas sûr que ce décompte soit juste...
274 return self._VmA('MemFree:', unit) + self._VmA('SwapFree:', unit) + \
275 self._VmA('Cached:', unit) + self._VmA('SwapCached:', unit)
277 def _VmB(self, VmKey, unit):
278 "Lecture des paramètres mémoire du processus"
280 t = open(self._proc_status)
284 return 0.0 # non-Linux?
285 i = v.index(VmKey) # get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
286 v = v[i:].split(None, 3) # whitespace
288 return 0.0 # invalid format?
289 # convert Vm value to bytes
290 mem = float(v[1]) * self._scale[v[2]]
291 return mem / self._scale[unit]
293 def getUsedMemory(self, unit="o"):
294 "Renvoie la mémoire résidente utilisée en octets"
295 return self._VmB('VmRSS:', unit)
297 def getVirtualMemory(self, unit="o"):
298 "Renvoie la mémoire totale utilisée en octets"
299 return self._VmB('VmSize:', unit)
301 def getUsedStacksize(self, unit="o"):
302 "Renvoie la taille du stack utilisé en octets"
303 return self._VmB('VmStk:', unit)
305 def getMaxUsedMemory(self, unit="o"):
306 "Renvoie la mémoire résidente maximale mesurée"
307 return self._VmB('VmHWM:', unit)
309 def getMaxVirtualMemory(self, unit="o"):
310 "Renvoie la mémoire totale maximale mesurée"
311 return self._VmB('VmPeak:', unit)
313 # ==============================================================================
314 if __name__ == "__main__":
315 print('\n AUTODIAGNOSTIC \n')