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