Salome HOME
Merge branch 'agr/connect'
[modules/kernel.git] / bin / salomeConsole.py
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # Copyright (C) 2003-2007  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, or (at your option) any later version.
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 ############### IMPORTANT NOTE ################
27 ###############################################
28 # The salomeConsole.py script is obsolete.    #
29 # Please consider the new salome launcher.    #
30 ###############################################
31
32
33 import os
34 import sys
35 import glob
36
37 #-------------------------------
38 # Python completion and others if you want
39 # You should have set PYTHONSTARTUP env variable
40 # or import user should try to import $HOME/.pythonrc.py
41 #-------------------------------
42 import user
43
44 #-------------------------------
45 # Get major CORBA objects
46 #-------------------------------
47 from omniORB import CORBA
48 import CosNaming
49 import salome_utils
50
51 import orbmodule
52
53 def getRunningSession():
54   omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
55   files = glob.glob(os.path.join(omniorbUserPath,".omniORB_"+salome_utils.getUserName()+"_*[!last].cfg"))
56
57   filename=""
58   if len(files)==1:
59     filename=files[0]
60   else:
61     print "You have %d sessions running" % len(files)
62     for f in files:
63       print "Session:",f
64       rep= raw_input("Do you want to connect to this session [y|n]")
65       if rep == "y":
66         filename=f
67         break
68
69   if filename != "":
70     os.environ['OMNIORB_CONFIG']=filename
71   else:
72     rep= raw_input("Do you want to try a local session on port 2810 ? [y|n]")
73     if rep == "y":
74       # Try a local session running on port 2810
75       sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810']
76     else:
77       sys.exit(1)
78 #
79
80 class client(orbmodule.client):
81   def initNS(self,args):
82     # Obtain a reference to the root naming context
83     obj = self.orb.resolve_initial_references("NameService")
84     try:
85       self.rootContext = obj._narrow(CosNaming.NamingContext)
86       return
87     except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
88       print "It's not a valid naming service"
89       self.rootContext = None
90       raise
91 #
92
93 def startClient():
94   try:
95     clt=client()
96   except Exception:
97     sys.exit(1)
98   #
99   print "Naming Service address: ",clt.orb.object_to_string(clt.rootContext)
100
101   clt.showNS()
102
103   session_server = clt.Resolve('/Kernel/Session')
104   if session_server:
105     session=clt.waitNS("/Kernel/Session")
106   catalog=clt.waitNS("/Kernel/ModulCatalog")
107   studyMgr=clt.waitNS("/myStudyManager")
108   import salome
109   salome.salome_init()
110   from salome import lcc
111 #
112
113 getRunningSession()
114 startClient()