Esempio n. 1
0
def get_SALOME_CORBA_port( the_user, the_hostname ) :
  import re
  a_pattern = "\." + the_user + "_" + the_hostname + "_(\d+)_SALOME_pidict"
  a_regexp = re.compile( a_pattern )

  # To find a default value for CORBA port
  args = { "port" : 2810 }
  from runSalome import searchFreePort
  searchFreePort( args, 0 )
  a_SALOME_CORBA_port = int( args[ "port" ] )

  a_latest_time = -1
  
  import tempfile 
  a_dir = os.path.join( tempfile.gettempdir(), "logs", the_user )
  if os.path.exists( a_dir ) :
      a_files = os.listdir( a_dir )
      for a_file in a_files :
          a_match = a_regexp.match( a_file )
          if a_match :
              # To chose the most recent instance of the SALOME
              a_full_filename = os.path.join( a_dir, a_file )
              a_creation_time = os.stat( a_full_filename )[-1]
              if a_creation_time > a_latest_time :
                  a_SALOME_CORBA_port = int( a_match.group( 1 ) )
                  a_latest_time = a_creation_time
                  pass
              pass
          pass
      pass
  
  return a_SALOME_CORBA_port
Esempio n. 2
0
  def initNS( self, args ) :
    """
    Obtains a reference to the root naming context
    """
    try :
      # Try to connect to the existing SALOME session 
      obj = self.orb.resolve_initial_references( "NameService" )
      self.rootContext = obj._narrow( CosNaming.NamingContext )

      # Try to connect to already existing SALOME study
      from salome import salome_init
      salome_init( theStudyId = 1 )
    except :
      # Try to launch a new session of SALOME 

      # Obtain SALOME configuration parameters
      from setenv import get_config
      args, modules_list, modules_root_dir = get_config()

      from runSalome import kill_salome
      kill_salome( args )

      # To generate a new SALOME configuration
      from runSalome import searchFreePort
      searchFreePort( args, 0 )

      # Starting of SALOME application 
      from runSalome import startSalome
      startSalome( args, modules_list, modules_root_dir )

      # To call the carresponding method of base class
      orbmodule.client.initNS( self, args )

      # Try to create a new SALOME study
      from salome import salome_init
      salome_init( theStudyId = 0 )
      pass

    self.showNS() # Prints debug information (can be commented)

    # It is necessary to wait untill it will be possible 
    # to get access to some important SALOME services
    self.waitNS( "/Kernel/Session" )
    self.waitNS( "/Kernel/ModulCatalog" )
    self.waitNS( "/myStudyManager" )

    pass