Back to index

salome-kernel  6.5.0
salomeConsole.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #  -*- coding: iso-8859-1 -*-
00003 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00004 #
00005 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00006 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00007 #
00008 # This library is free software; you can redistribute it and/or
00009 # modify it under the terms of the GNU Lesser General Public
00010 # License as published by the Free Software Foundation; either
00011 # version 2.1 of the License.
00012 #
00013 # This library is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 # Lesser General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU Lesser General Public
00019 # License along with this library; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00021 #
00022 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00023 #
00024 
00025 import os
00026 import sys
00027 #-------------------------------
00028 # Python completion and others if you want
00029 # You should have set PYTHONSTARTUP env variable
00030 # or import user should try to import $HOME/.pythonrc.py
00031 #-------------------------------
00032 import user
00033 
00034 #-------------------------------
00035 # Get major CORBA objects
00036 #-------------------------------
00037 import CORBA
00038 import CosNaming
00039 # There are cyclic dependencies between Engines, SALOME and SALOMEDS.
00040 # import first Engines, then SALOME and then SALOMEDS
00041 # Or use reload(Engines) to be safe.
00042 import Engines
00043 import SALOME
00044 import SALOMEDS
00045 import SALOME_ModuleCatalog
00046 reload(Engines)
00047 reload(SALOME)
00048 reload(SALOMEDS)
00049 import salome_utils
00050 
00051 import LifeCycleCORBA
00052 import orbmodule
00053 from runSalome import *
00054 
00055 import Utils_Identity
00056 files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),
00057                                "USERS",".omniORB_"+salome_utils.getUserName()+"_*.cfg"))
00058 
00059 filename=""
00060 if len(files)==1:
00061   filename=files[0]
00062 else:
00063   print "You have %d sessions running" % len(files)
00064   for f in files:
00065      print "Session:",f
00066      rep= raw_input("Do you want to connect to this session [y|n]")
00067      if rep == "y":
00068         filename=f
00069         break
00070      
00071 if filename != "":
00072   os.environ['OMNIORB_CONFIG']=filename
00073 else:
00074   rep= raw_input("Do you want to try a local session on port 2810 ? [y|n]")
00075   if rep == "y":
00076      # Try a local session running on port 2810
00077      sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810']
00078   else:
00079      sys.exit(1)
00080 
00081 print sys.argv
00082 
00083 #direct adress from clt.orb.object_to_string(clt.rootContext)
00084 #sys.argv=sys.argv+['-ORBInitRef','NameService=IOR:010000000100000000000000010000000000000023000000010100000a0000006c6f63616c686f737400fa0a0b0000004e616d6553657276696365']
00085 
00086 class client(orbmodule.client):
00087    def initNS(self,args):
00088       # Obtain a reference to the root naming context
00089       obj         = self.orb.resolve_initial_references("NameService")
00090       try:
00091           self.rootContext = obj._narrow(CosNaming.NamingContext)
00092           return
00093       except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00094           print "It's not a valid naming service"
00095           self.rootContext = None
00096           raise
00097 
00098 clt=client()
00099 print "Naming Service address: ",clt.orb.object_to_string(clt.rootContext)
00100 
00101 clt.showNS()
00102 
00103 session=clt.waitNS("/Kernel/Session")
00104 catalog=clt.waitNS("/Kernel/ModulCatalog")
00105 studyMgr=clt.waitNS("/myStudyManager")
00106 import salome
00107 salome.salome_init()
00108 from salome import lcc