Salome HOME
To avoid compilation pb on RedHat 8.0.
[modules/kernel.git] / src / Utils / Utils_Identity.py
1 #! /usr/bin/env python
2 #
3 #  SALOME Utils : general SALOME's definitions and tools
4 #
5 #  Copyright (C) 2003  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 #
25 #
26 #  File   : Utils_Identity.py
27 #  Author : Estelle Deville, CEA
28 #  Module : SALOME
29 #  $Header$
30
31 import sys
32 import os
33 import socket
34
35 if not sys.platform == "win32":
36     import pwd
37         
38 import time
39 import string
40
41 def getShortHostName():
42     """
43     gives Hostname without domain extension.
44     SALOME naming service needs short Hostnames (without domain extension).
45     HOSTNAME is not allways defined in environment,
46     socket.gethostname() gives short or complete Hostname, depending on
47     defined aliases.
48     """
49     return string.split(socket.gethostname(),'.')[0]
50
51 class Identity:
52     def __init__(self,name):
53         self._name = name
54         self._pid =  os.getpid()
55         self._machine = socket.gethostname()
56         self._adip      =  socket.gethostbyname(self._machine) # IP adress        
57         if sys.platform == "win32":
58             self._uid    = os.getpid() 
59             self._pwname = os.environ["USER"]
60         else:
61             self._uid   = os.getuid()
62             list = pwd.getpwuid(self._uid)
63             self._pwname        = list[0] # user name
64
65         self._tc_start  = time.time()
66         self._cstart    = time.ctime(self._tc_start)
67         self._cdir      = os.getcwd()
68
69 def getapplipath():
70     """
71       Gives short application path (the complete path is $HOME/$APPLI)
72     """
73     return os.environ.get("APPLI",".salome_"+versnb)
74
75 try:
76   file = open(os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","VERSION"), "r")
77   s = file.readline()
78   versnb = string.strip(string.split(s, ":")[1])
79   dirname=".salome_"+versnb
80 except:
81   versnb = ""
82   dirname=".salome"
83
84 def version():
85     """
86       Gives salome version number
87     """
88     return versnb