Salome HOME
modify salome_test to skip SUPERV tests in SALOME series5x
[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
87
88 def getVersions( mod = "KERNEL" ):
89     """
90     Get SALOME module version as list of [major, minor, release] numbers
91     Returns: version numbers list
92     """
93     try:
94         major = int( getVersionMajor( mod ) )
95     except:
96         major = 0
97         pass
98     try:
99         minor = int( getVersionMinor( mod ) )
100     except:
101         minor = 0
102         pass
103     try:
104         rel = int( getVersionRelease( mod ) )
105     except:
106         rel = 0
107         pass
108     return [ major, minor, rel ]
109