Salome HOME
Merge from V6_3_BR 19/07/2011
[modules/kernel.git] / bin / salomeConsole.py
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2011  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.
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 import os
26 import sys
27 #-------------------------------
28 # Python completion and others if you want
29 # You should have set PYTHONSTARTUP env variable
30 # or import user should try to import $HOME/.pythonrc.py
31 #-------------------------------
32 import user
33
34 #-------------------------------
35 # Get major CORBA objects
36 #-------------------------------
37 import CORBA
38 import CosNaming
39 # There are cyclic dependencies between Engines, SALOME and SALOMEDS.
40 # import first Engines, then SALOME and then SALOMEDS
41 # Or use reload(Engines) to be safe.
42 import Engines
43 import SALOME
44 import SALOMEDS
45 import SALOME_ModuleCatalog
46 reload(Engines)
47 reload(SALOME)
48 reload(SALOMEDS)
49 import salome_utils
50
51 import LifeCycleCORBA
52 import orbmodule
53 from runSalome import *
54
55 import Utils_Identity
56 files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),
57                                "USERS",".omniORB_"+salome_utils.getUserName()+"_*.cfg"))
58
59 filename=""
60 if len(files)==1:
61   filename=files[0]
62 else:
63   print "You have %d sessions running" % len(files)
64   for f in files:
65      print "Session:",f
66      rep= raw_input("Do you want to connect to this session [y|n]")
67      if rep == "y":
68         filename=f
69         break
70      
71 if filename != "":
72   os.environ['OMNIORB_CONFIG']=filename
73 else:
74   rep= raw_input("Do you want to try a local session on port 2810 ? [y|n]")
75   if rep == "y":
76      # Try a local session running on port 2810
77      sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810']
78   else:
79      sys.exit(1)
80
81 print sys.argv
82
83 #direct adress from clt.orb.object_to_string(clt.rootContext)
84 #sys.argv=sys.argv+['-ORBInitRef','NameService=IOR:010000000100000000000000010000000000000023000000010100000a0000006c6f63616c686f737400fa0a0b0000004e616d6553657276696365']
85
86 class client(orbmodule.client):
87    def initNS(self,args):
88       # Obtain a reference to the root naming context
89       obj         = self.orb.resolve_initial_references("NameService")
90       try:
91           self.rootContext = obj._narrow(CosNaming.NamingContext)
92           return
93       except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
94           print "It's not a valid naming service"
95           self.rootContext = None
96           raise
97
98 clt=client()
99 print "Naming Service address: ",clt.orb.object_to_string(clt.rootContext)
100
101 clt.showNS()
102
103 session=clt.waitNS("/Kernel/Session")
104 catalog=clt.waitNS("/Kernel/ModulCatalog")
105 studyMgr=clt.waitNS("/myStudyManager")
106 import salome
107 salome.salome_init()
108 from salome import lcc