Salome HOME
Test EXPORTS definition with target name as suggested by cmake
[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
41 import time
42 import string
43
44 def getShortHostName():
45     """
46     gives Hostname without domain extension.
47
48     SALOME naming service needs short Hostnames (without domain extension).
49     HOSTNAME is not allways defined in environment,
50     socket.gethostname() gives short or complete Hostname, depending on
51     defined aliases.
52     """
53     return string.split(socket.gethostname(),'.')[0]
54
55 class Identity:
56     def __init__(self,name):
57         self._name = name
58         self._pid =  os.getpid()
59         self._machine = socket.gethostname()
60         self._adip =  socket.gethostbyname(self._machine) # IP adress        
61         if sys.platform == "win32":
62           self._uid  = os.getpid() 
63           self._pwname = os.environ["USER"]
64         else:
65           self._uid = os.getuid()
66           list = pwd.getpwuid(self._uid)
67           self._pwname  = list[0] # user name
68
69         self._tc_start = time.time()
70         self._cstart    = time.ctime(self._tc_start)
71         self._cdir = os.getcwd()
72
73 def getapplipath():
74     """
75       Gives short application path (the complete path is $HOME/$APPLI)
76     """
77     return os.environ.get("APPLI",".salome_"+versnb)
78
79 try:
80   file = open(os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","VERSION"), "r")
81   s = file.readline()
82   versnb = string.strip(string.split(s, ":")[1])
83   dirname=".salome_"+versnb
84 except:
85   versnb = ""
86   dirname=".salome"
87
88 def version():
89     """
90       Gives salome version number
91     """
92     return versnb