Back to index

salome-kernel  6.5.0
waitContainers.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 ## \file waitContainers.py
00026 # \brief command to wait until containers are launched
00027 #
00028 # the container names (in naming service) are passed on the command line as in :
00029 # waitContainers.py FactoryServer
00030 
00031 import sys
00032 import time
00033 import orbmodule
00034 import CosNaming
00035 clt = orbmodule.client()
00036 clt.waitNS("/ContainerManager")
00037 obj = clt.orb.resolve_initial_references("NameService")
00038 rootContext = obj._narrow(CosNaming.NamingContext)
00039 cname = []
00040 cname.append(CosNaming.NameComponent('Containers', 'dir'))
00041 
00042 while(1):
00043   try:
00044     ccontext = rootContext.resolve(cname)
00045     break
00046   except CosNaming.NamingContext.NotFound, ex:
00047     time.sleep(1)
00048   except CosNaming.NamingContext.InvalidName, ex:
00049     time.sleep(1)
00050   except CosNaming.NamingContext.CannotProceed, ex:
00051     time.sleep(1)
00052   except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00053     time.sleep(1)
00054 
00055 def waitContainer(mycont):
00056   while(1):
00057     bl,bi=ccontext.list(0)
00058     if bi is not None:
00059       ok,b=bi.next_one()
00060       while(ok):
00061         for s in b.binding_name :
00062           if s.kind == "dir":
00063             obj=ccontext.resolve([s])
00064             scontext = obj._narrow(CosNaming.NamingContext)
00065             bll,bii=scontext.list(0)
00066             if bii is not None:
00067               ok,bb=bii.next_one()
00068               while(ok):
00069                 for s in bb.binding_name :
00070                    if s.id == mycont:
00071                      print s.id
00072                      return
00073                 ok,bb=bii.next_one()
00074         ok,b=bi.next_one()
00075     sys.stdout.write('+')
00076     sys.stdout.flush()
00077     time.sleep(1)
00078 
00079 for cont in sys.argv:
00080   if cont != sys.argv[0]:
00081     waitContainer(cont)
00082