Salome HOME
2c95b42196acd1e32dd77186a8726fb6b535dc09
[modules/kernel.git] / src / KERNEL_PY / salome_version.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  File   : salome_version.py
23 #  Author : Vadim SANDLER
24 #  Module : SALOME
25 #
26 _salome_versions = {}
27
28 def getVersion( mod = "KERNEL" ):
29     """
30     Get SALOME module version number
31     Returns: version number string or None if VERSION file is not found
32     """
33     global _salome_versions
34     mod = mod.upper()
35     if not _salome_versions.has_key( mod ):
36         _salome_versions[ mod ] = None
37         import os
38         root_dir = os.getenv( "%s_ROOT_DIR" % mod )
39         if root_dir:
40             try:
41                 filename = root_dir + "/bin/salome/VERSION"
42                 if not os.path.exists( filename ):
43                     filename = root_dir + "/bin/VERSION"
44                 file = open( filename )
45                 ver = file.readline()
46                 file.close()
47                 _salome_versions[ mod ] = ver.split( ":" )[ -1 ].strip()
48             except:
49                 pass
50     return _salome_versions[ mod ]
51
52 def getVersionMajor( mod = "KERNEL" ):
53     """
54     Get SALOME module major version number
55     Returns: version major number string or None if VERSION file is not found
56     """
57     ver = getVersion( mod )
58     try:
59         return ver.split( "." )[ 0 ]
60     except:
61         pass
62     return None
63
64 def getVersionMinor( mod = "KERNEL" ):
65     """
66     Get SALOME module minor version number
67     Returns: version minor number string or None if VERSION file is not found
68     """
69     ver = getVersion( mod )
70     try:
71         return ver.split( "." )[ 1 ]
72     except:
73         pass
74     return None
75
76 def getVersionRelease( mod = "KERNEL" ):
77     """
78     Get SALOME module release version number
79     Returns: version release number string or None if VERSION file is not found
80     """
81     ver = getVersion( mod )
82     try:
83         return ver.split( "." )[ 2 ]
84     except:
85         pass
86     return None