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