Back to index

salome-kernel  6.5.0
Utils_Identity.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 #  -*- coding: iso-8859-1 -*-
00003 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00004 #
00005 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00006 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00007 #
00008 # This library is free software; you can redistribute it and/or
00009 # modify it under the terms of the GNU Lesser General Public
00010 # License as published by the Free Software Foundation; either
00011 # version 2.1 of the License.
00012 #
00013 # This library is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 # Lesser General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU Lesser General Public
00019 # License along with this library; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00021 #
00022 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00023 #
00024 
00025 #  SALOME Utils : general SALOME's definitions and tools
00026 #  File   : Utils_Identity.py
00027 #  Author : Estelle Deville, CEA
00028 #  Module : SALOME
00029 #  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Utils/Utils_Identity.py,v 1.8.2.4.14.3.12.1 2012-04-12 14:05:32 vsr Exp $
00030 ## @package Utils_Identity
00031 # \brief Module to get information about user and version
00032 #
00033 import sys
00034 import os
00035 import socket
00036 
00037 if not sys.platform == "win32":
00038     import pwd
00039 
00040 import time
00041 import string
00042 
00043 def getShortHostName():
00044     """
00045     gives Hostname without domain extension.
00046 
00047     SALOME naming service needs short Hostnames (without domain extension).
00048     HOSTNAME is not allways defined in environment,
00049     socket.gethostname() gives short or complete Hostname, depending on
00050     defined aliases.
00051     """
00052     return string.split(socket.gethostname(),'.')[0]
00053 
00054 class Identity:
00055     def __init__(self,name):
00056         self._name = name
00057         self._pid =  os.getpid()
00058         self._machine = socket.gethostname()
00059         self._adip =  socket.gethostbyname(self._machine) # IP adress        
00060         if sys.platform == "win32":
00061           self._uid  = os.getpid() 
00062           self._pwname = os.environ["USERNAME"]
00063         else:
00064           self._uid = os.getuid()
00065           list = pwd.getpwuid(self._uid)
00066           self._pwname  = list[0] # user name
00067 
00068         self._tc_start = time.time()
00069         self._cstart    = time.ctime(self._tc_start)
00070         self._cdir = os.getcwd()
00071 
00072 def getapplipath():
00073     """
00074       Gives short application path (the complete path is $HOME/$APPLI)
00075     """
00076     return os.environ.get("APPLI",".salome_"+versnb)
00077 
00078 try:
00079   file = open(os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","VERSION"), "r")
00080   s = file.readline()
00081   versnb = string.strip(string.split(s, ":")[1])
00082   dirname=".salome_"+versnb
00083 except:
00084   versnb = ""
00085   dirname=".salome"
00086 
00087 def version():
00088     """
00089       Gives salome version number
00090     """
00091     return versnb