Back to index

salome-kernel  6.5.0
salome_version.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  File   : salome_version.py
00025 #  Author : Vadim SANDLER
00026 #  Module : SALOME
00027 #
00028 __ALL__ = [
00029     "getVersion",
00030     "getVersionMajor",
00031     "getVersionMinor",
00032     "getVersionRelease",
00033     "getVersions",
00034     "getXVersion",
00035     "isDevelopmentVersion",
00036     ]
00037 
00038 _salome_versions = {}
00039 
00040 def getVersion( mod = "KERNEL", full = False ):
00041     """
00042     Get SALOME module version number
00043     Parameters:
00044     - mod  : SALOME module name, default is 'KERNEL'
00045     - full : take into account development marker (in this case 'dev' is added
00046              to the end of version value for development version), False by default
00047     Returns: version number string or None if VERSION file is not found
00048     """
00049     global _salome_versions
00050     mod = mod.upper()
00051     dev_flag = { True : "dev", False : "" }
00052     if not _salome_versions.has_key( mod ):
00053         _salome_versions[ mod ] = [ None, "" ]
00054         import os
00055         root_dir = os.getenv( "%s_ROOT_DIR" % mod )
00056         if root_dir:
00057             try:
00058                 filename = root_dir + "/bin/salome/VERSION"
00059                 if not os.path.exists( filename ):
00060                     filename = root_dir + "/bin/VERSION"
00061                 f = open( filename )
00062                 data = f.readlines()
00063                 f.close()
00064                 for l in data:
00065                     if l.strip().startswith("#") or ":" not in l: continue
00066                     key = ":".join( l.split( ":" )[ :-1 ] ).strip()
00067                     val = l.split( ":" )[ -1 ].strip()
00068                     if "development" in key.lower():
00069                         _salome_versions[ mod ][ 1 ] = dev_flag[ val == "1" ]
00070                     elif "version" in key.lower() or mod in key:
00071                         _salome_versions[ mod ][ 0 ] = val
00072                     pass
00073             except:
00074                 pass
00075     v = _salome_versions[ mod ][ 0 ]
00076     if full and v is not None:
00077         v += _salome_versions[ mod ][ 1 ]
00078     return v
00079 
00080 def getVersionMajor( mod = "KERNEL" ):
00081     """
00082     Get SALOME module major version number
00083     Parameters:
00084     - mod  : SALOME module name, default is 'KERNEL'
00085     Returns: version major number string or None if VERSION file is not found
00086     """
00087     ver = getVersion( mod )
00088     try:
00089         return ver.split( "." )[ 0 ]
00090     except:
00091         pass
00092     return None
00093 
00094 def getVersionMinor( mod = "KERNEL" ):
00095     """
00096     Get SALOME module minor version number
00097     Parameters:
00098     - mod  : SALOME module name, default is 'KERNEL'
00099     Returns: version minor number string or None if VERSION file is not found
00100     """
00101     ver = getVersion( mod )
00102     try:
00103         return ver.split( "." )[ 1 ]
00104     except:
00105         pass
00106     return None
00107 
00108 def getVersionRelease( mod = "KERNEL" ):
00109     """
00110     Get SALOME module release version number
00111     Parameters:
00112     - mod  : SALOME module name, default is 'KERNEL'
00113     Returns: version release number string or None if VERSION file is not found
00114     """
00115     ver = getVersion( mod )
00116     try:
00117         return ver.split( "." )[ 2 ]
00118     except:
00119         pass
00120     return None
00121 
00122 def getVersions( mod = "KERNEL" ):
00123     """
00124     Get SALOME module version as list of [major, minor, release] numbers
00125     Parameters:
00126     - mod  : SALOME module name, default is 'KERNEL'
00127     Returns: version numbers list
00128     """
00129     try:
00130         major = int( getVersionMajor( mod ) )
00131     except:
00132         major = 0
00133         pass
00134     try:
00135         minor = int( getVersionMinor( mod ) )
00136     except:
00137         minor = 0
00138         pass
00139     try:
00140         rel = int( getVersionRelease( mod ) )
00141     except:
00142         rel = 0
00143         pass
00144     return [ major, minor, rel ]
00145     
00146 def getXVersion( mod = "KERNEL" ):
00147     """
00148     Get SALOME module version as list of [major, minor, release] numbers
00149     Parameters:
00150     - mod  : SALOME module name, default is 'KERNEL'
00151     Returns: version numbers list
00152     """
00153     major, minor, rel = getVersions( mod )
00154     return hex( (major<<16) + (minor<<8) + rel )
00155 
00156 def isDevelopmentVersion( mod = "KERNEL" ):
00157     """
00158     Checks if the version of SALOME module is marked as development one
00159     Parameters:
00160     - mod  : SALOME module name, default is 'KERNEL'
00161     Returns: Return True for delopment version of module or False otherwise
00162     """
00163     ver = getVersion( mod, True )
00164     return ver.endswith( "dev" )