Salome HOME
[windows] Increase the time salome try to find the objects in naming service. It...
[modules/kernel.git] / bin / salomeConsole.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 import os
24 import sys
25 #-------------------------------
26 # Python completion and others if you want
27 # You should have set PYTHONSTARTUP env variable
28 # or import user should try to import $HOME/.pythonrc.py
29 #-------------------------------
30 import user
31
32 #-------------------------------
33 # Get major CORBA objects
34 #-------------------------------
35 import CORBA
36 import CosNaming
37 # There are cyclic dependencies between Engines, SALOME and SALOMEDS.
38 # import first Engines, then SALOME and then SALOMEDS
39 # Or use reload(Engines) to be safe.
40 import Engines
41 import SALOME
42 import SALOMEDS
43 import SALOME_ModuleCatalog
44 reload(Engines)
45 reload(SALOME)
46 reload(SALOMEDS)
47 import salome_utils
48
49 import LifeCycleCORBA
50 import orbmodule
51 from runSalome import *
52
53 import Utils_Identity
54 files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),
55                                "USERS",".omniORB_"+salome_utils.getUserName()+"_*.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 print sys.argv
80
81 #direct adress from clt.orb.object_to_string(clt.rootContext)
82 #sys.argv=sys.argv+['-ORBInitRef','NameService=IOR:010000000100000000000000010000000000000023000000010100000a0000006c6f63616c686f737400fa0a0b0000004e616d6553657276696365']
83
84 class client(orbmodule.client):
85    def initNS(self,args):
86       # Obtain a reference to the root naming context
87       obj         = self.orb.resolve_initial_references("NameService")
88       try:
89           self.rootContext = obj._narrow(CosNaming.NamingContext)
90           return
91       except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
92           print "It's not a valid naming service"
93           self.rootContext = None
94           raise
95
96 clt=client()
97 print "Naming Service address: ",clt.orb.object_to_string(clt.rootContext)
98
99 clt.showNS()
100
101 session=clt.waitNS("/Kernel/Session")
102 catalog=clt.waitNS("/Kernel/ModulCatalog")
103 studyMgr=clt.waitNS("/myStudyManager")
104 import salome
105 salome.salome_init()
106 from salome import lcc