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