Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / bin / salomeConsole.py
1 #!/usr/bin/env python
2
3 import os
4 import sys
5 #-------------------------------
6 # Python completion and others if you want
7 # You should have set PYTHONSTARTUP env variable
8 # or import user should try to import $HOME/.pythonrc.py
9 #-------------------------------
10 import user
11
12 #-------------------------------
13 # Get major CORBA objects
14 #-------------------------------
15 import CORBA
16 import CosNaming
17 # There are cyclic dependencies between Engines, SALOME and SALOMEDS.
18 # import first Engines, then SALOME and then SALOMEDS
19 # Or use reload(Engines) to be safe.
20 import Engines
21 import SALOME
22 import SALOMEDS
23 import SALOME_ModuleCatalog
24 reload(Engines)
25 reload(SALOME)
26 reload(SALOMEDS)
27
28 import LifeCycleCORBA
29 import orbmodule
30 from runSalome import *
31
32 import Utils_Identity
33 files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),".omni*.cfg"))
34
35 filename=""
36 if len(files)==1:
37   filename=files[0]
38 else:
39   print "You have %d sessions running" % len(files)
40   for f in files:
41      print "Session:",f
42      rep= raw_input("Do you want to connect to this session [y|n]")
43      if rep == "y":
44         filename=f
45         break
46      
47 if filename != "":
48   os.environ['OMNIORB_CONFIG']=filename
49 else:
50   rep= raw_input("Do you want to try a local session on port 2810 ? [y|n]")
51   if rep == "y":
52      # Try a local session running on port 2810
53      sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810']
54   else:
55      sys.exit(1)
56
57 print sys.argv
58
59 #direct adress from clt.orb.object_to_string(clt.rootContext)
60 #sys.argv=sys.argv+['-ORBInitRef','NameService=IOR:010000000100000000000000010000000000000023000000010100000a0000006c6f63616c686f737400fa0a0b0000004e616d6553657276696365']
61
62 class client(orbmodule.client):
63    def initNS(self):
64       # Obtain a reference to the root naming context
65       obj         = self.orb.resolve_initial_references("NameService")
66       try:
67           self.rootContext = obj._narrow(CosNaming.NamingContext)
68           return
69       except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
70           print "It's not a valid naming service"
71           self.rootContext = None
72           raise
73
74 clt=client()
75 print "Naming Service address: ",clt.orb.object_to_string(clt.rootContext)
76
77 clt.showNS()
78
79 session=clt.waitNS("/Kernel/Session")
80 catalog=clt.waitNS("/Kernel/ModulCatalog")
81 studyMgr=clt.waitNS("/myStudyManager")
82 lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb)
83
84 #c=lcc.FindOrStartContainer("","totoPy")
85 #print c