Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/kernel.git] / bin / salomeConsole.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
4 #           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either 
8 # version 2.1 of the License.
9
10 # This library is distributed in the hope that it will be useful 
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public  
16 # License along with this library; if not, write to the Free Software 
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20
21
22 import os
23 import sys
24 #-------------------------------
25 # Python completion and others if you want
26 # You should have set PYTHONSTARTUP env variable
27 # or import user should try to import $HOME/.pythonrc.py
28 #-------------------------------
29 import user
30
31 #-------------------------------
32 # Get major CORBA objects
33 #-------------------------------
34 import CORBA
35 import CosNaming
36 # There are cyclic dependencies between Engines, SALOME and SALOMEDS.
37 # import first Engines, then SALOME and then SALOMEDS
38 # Or use reload(Engines) to be safe.
39 import Engines
40 import SALOME
41 import SALOMEDS
42 import SALOME_ModuleCatalog
43 reload(Engines)
44 reload(SALOME)
45 reload(SALOMEDS)
46
47 import LifeCycleCORBA
48 import orbmodule
49 from runSalome import *
50
51 import Utils_Identity
52 files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),".omni*.cfg"))
53
54 filename=""
55 if len(files)==1:
56   filename=files[0]
57 else:
58   print "You have %d sessions running" % len(files)
59   for f in files:
60      print "Session:",f
61      rep= raw_input("Do you want to connect to this session [y|n]")
62      if rep == "y":
63         filename=f
64         break
65      
66 if filename != "":
67   os.environ['OMNIORB_CONFIG']=filename
68 else:
69   rep= raw_input("Do you want to try a local session on port 2810 ? [y|n]")
70   if rep == "y":
71      # Try a local session running on port 2810
72      sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810']
73   else:
74      sys.exit(1)
75
76 print sys.argv
77
78 #direct adress from clt.orb.object_to_string(clt.rootContext)
79 #sys.argv=sys.argv+['-ORBInitRef','NameService=IOR:010000000100000000000000010000000000000023000000010100000a0000006c6f63616c686f737400fa0a0b0000004e616d6553657276696365']
80
81 class client(orbmodule.client):
82    def initNS(self):
83       # Obtain a reference to the root naming context
84       obj         = self.orb.resolve_initial_references("NameService")
85       try:
86           self.rootContext = obj._narrow(CosNaming.NamingContext)
87           return
88       except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
89           print "It's not a valid naming service"
90           self.rootContext = None
91           raise
92
93 clt=client()
94 print "Naming Service address: ",clt.orb.object_to_string(clt.rootContext)
95
96 clt.showNS()
97
98 session=clt.waitNS("/Kernel/Session")
99 catalog=clt.waitNS("/Kernel/ModulCatalog")
100 studyMgr=clt.waitNS("/myStudyManager")
101 import salome
102 salome.salome_init()
103 from salome import lcc