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