Back to index

salome-kernel  6.5.0
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes
runSalome.SessionServer Class Reference
Inheritance diagram for runSalome.SessionServer:
Inheritance graph
[legend]
Collaboration diagram for runSalome.SessionServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def setpath
def initArgs
def run
def daemonize

Static Public Member Functions

def set_server_launch_mode

Public Attributes

 args
 SCMD1
 SCMD2
 CMD
 PID
 ARGS

Static Public Attributes

string server_launch_mode = "daemon"

Detailed Description

Definition at line 237 of file runSalome.py.


Constructor & Destructor Documentation

def runSalome.SessionServer.__init__ (   self,
  args,
  modules_list,
  modules_root_dir 
)

Definition at line 238 of file runSalome.py.

00238 
00239     def __init__(self,args,modules_list,modules_root_dir):
00240         self.args = args.copy()
00241         # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge)
00242         #self.args['xterm']=0
00243         #
00244         self.initArgs()
00245         self.SCMD1=['SALOME_Session_Server']
00246         self.SCMD2=[]
00247         if 'registry' in self.args['embedded']:
00248             self.SCMD1+=['--with','Registry',
00249                          '(','--salome_session','theSession',')']
00250         if 'moduleCatalog' in self.args['embedded']:
00251             self.SCMD1+=['--with','ModuleCatalog','(','-common']
00252             home_dir=os.getenv('HOME')
00253             if home_dir is not None:
00254                 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] 
00255             self.SCMD2+=[')']
00256         if 'study' in self.args['embedded']:
00257             self.SCMD2+=['--with','SALOMEDS','(',')']
00258         if 'cppContainer' in self.args['embedded']:
00259             self.SCMD2+=['--with','Container','(','FactoryServer',')']
00260         if 'SalomeAppEngine' in self.args['embedded']:
00261             self.SCMD2+=['--with','SalomeAppEngine','(',')']
00262             
00263         if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
00264             self.SCMD2+=['CPP']
00265         if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
00266             self.SCMD2+=['PY']
00267         if self.args['gui']:
00268             session_gui = True
00269             if self.args.has_key('session_gui'):
00270                 session_gui = self.args['session_gui']
00271             if session_gui:
00272                 self.SCMD2+=['GUI']
00273                 if self.args['splash']:
00274                     self.SCMD2+=['SPLASH']
00275                     pass
00276                 if self.args['study_hdf'] is not None:
00277                     self.SCMD2+=['--study-hdf=%s'%self.args['study_hdf']]
00278                     pass
00279                 pass
00280             pass
00281         if self.args['noexcepthandler']:
00282             self.SCMD2+=['noexcepthandler']
00283         if self.args.has_key('user_config'):
00284             self.SCMD2+=['--resources=%s'%self.args['user_config']]
00285         if self.args.has_key('modules'):
00286             list_modules = []
00287             #keep only modules with GUI
00288             for m in modules_list:
00289               if m not in modules_root_dir:
00290                 list_modules.insert(0,m)
00291               else:
00292                 fr1 = os.path.join(modules_root_dir[m],"share","salome","resources",m.lower(),"SalomeApp.xml")
00293                 fr2 = os.path.join(modules_root_dir[m],"share","salome","resources","SalomeApp.xml")
00294                 if os.path.exists(fr1) or os.path.exists(fr2):
00295                   list_modules.insert(0,m)
00296             list_modules.reverse()
00297             self.SCMD2+=['--modules (%s)' % ":".join(list_modules)]
00298 
00299         if self.args.has_key('pyscript') and len(self.args['pyscript']) > 0:
00300             self.SCMD2+=['--pyscript=%s'%(",".join(self.args['pyscript']))]


Member Function Documentation

def server.Server.daemonize (   self,
  args 
) [inherited]

Definition at line 88 of file server.py.

00088 
00089     def daemonize(self,args):
00090         # to daemonize a process need to do the UNIX double-fork magic
00091         # see Stevens, "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177)
00092         # and UNIX Programming FAQ 1.7 How do I get my program to act like a daemon?
00093         #     http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
00094         #open a pipe
00095         c2pread, c2pwrite = os.pipe()
00096         #do first fork
00097         pid=os.fork()
00098         if pid > 0:
00099           #first parent
00100           os.close(c2pwrite)
00101           #receive real pid from child
00102           data=os.read(c2pread,24) #read 24 bytes
00103           os.waitpid(pid,0) #remove zombie
00104           os.close(c2pread)
00105           # return : first parent
00106           childpid=int(data)
00107           if childpid==-1:
00108             return None
00109           try:
00110             os.kill(childpid,0)
00111             return childpid
00112           except:
00113             return None
00114 
00115         #first child
00116         # decouple from parent environment
00117         os.setsid()
00118         os.close(c2pread)
00119 
00120         # do second fork : second child not a session leader
00121         try:
00122           pid = os.fork()
00123           if pid > 0:
00124             #send real pid to parent
00125             os.write(c2pwrite,"%d" % pid)
00126             os.close(c2pwrite)
00127             # exit from second parent
00128             os._exit(0)
00129         except OSError, e:
00130           print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
00131           os.write(c2pwrite,"-1")
00132           os.close(c2pwrite)
00133           sys.exit(1)
00134 
00135         #I am a daemon
00136         os.close(0) #close stdin
00137         os.open("/dev/null", os.O_RDWR)  # redirect standard input (0) to /dev/null
00138         try:
00139           os.execvp(args[0], args)
00140         except OSError, e:
00141           if args[0] != "notifd":
00142             print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror)
00143             pass
00144           os._exit(127)

Here is the caller graph for this function:

def server.Server.initArgs (   self) [inherited]

Reimplemented in nameserver.NamingServer.

Definition at line 39 of file server.py.

00039 
00040     def initArgs(self):
00041         self.PID=None
00042         self.CMD=[]
00043         self.ARGS=[]
00044         if self.args.get('xterm'):
00045           if sys.platform != "win32":
00046             self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
00047           else:
00048             self.ARGS=['cmd', '/c', 'start  cmd.exe', '/K']

def server.Server.run (   self) [inherited]

Reimplemented in runSalome.InterpServer.

Definition at line 60 of file server.py.

00060 
00061     def run(self):
00062         global process_id
00063         myargs=self.ARGS
00064         if self.args.get('xterm'):
00065             # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
00066             if sys.platform != "win32":
00067               env_ld_library_path=['env', 'LD_LIBRARY_PATH='
00068                                    + os.getenv("LD_LIBRARY_PATH")]
00069               myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
00070         command = myargs + self.CMD
00071         #print "command = ", command
00072         if sys.platform == "win32":
00073           import win32pm
00074           #cmd_str = "\"" + string.join(command, " ") + "\""
00075           #print cmd_str
00076           #pid = win32pm.spawnpid( cmd_str )
00077           pid = win32pm.spawnpid( string.join(command, " "), '-nc' )
00078           #pid = win32pm.spawnpid( string.join(command, " ") )
00079         elif Server.server_launch_mode == "fork":
00080           pid = os.spawnvp(os.P_NOWAIT, command[0], command)
00081         else: # Server launch mode is daemon
00082           pid=self.daemonize(command)
00083         if pid is not None:
00084           #store process pid if it really exists
00085           process_id[pid]=self.CMD
00086         self.PID = pid
00087         return pid

Here is the call graph for this function:

def server.Server.set_server_launch_mode (   mode) [static, inherited]

Definition at line 54 of file server.py.

00054 
00055     def set_server_launch_mode(mode):
00056       if mode == "daemon" or mode == "fork":
00057         Server.server_launch_mode = mode
00058       else:
00059         raise Exception("Unsupported server launch mode: %s" % mode)

def runSalome.SessionServer.setpath (   self,
  modules_list,
  modules_root_dir 
)

Definition at line 301 of file runSalome.py.

00301 
00302     def setpath(self,modules_list,modules_root_dir):
00303         list_modules = modules_list[:]
00304         list_modules.reverse()
00305         if self.args["gui"] :
00306             list_modules = ["KERNEL", "GUI"] + list_modules
00307         else :
00308             list_modules = ["KERNEL"] + list_modules
00309 
00310         cata_path=get_cata_path(list_modules,modules_root_dir)
00311 
00312         if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
00313             #Use '::' instead ":" because drive path with "D:\" is invalid on windows platform
00314             self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2
00315         else:
00316             self.CMD=self.SCMD1 + self.SCMD2
00317         if self.args.has_key('test'):
00318             self.CMD+=['-test'] + self.args['test']
00319         elif self.args.has_key('play'):
00320             self.CMD+=['-play'] + self.args['play']
00321 
00322         if self.args["gdb_session"] or self.args["ddd_session"]:
00323             f = open(".gdbinit4salome", "w")
00324             f.write("set args ")
00325             args = " ".join(self.CMD[1:])
00326             args = args.replace("(", "\(")
00327             args = args.replace(")", "\)")
00328             f.write(args)
00329             f.write("\n")
00330             f.close()
00331             if self.args["ddd_session"]:
00332                 self.CMD = ["ddd", "--command=.gdbinit4salome", self.CMD[0]]
00333             elif self.args["gdb_session"]:
00334                 self.CMD = ["xterm", "-e", "gdb", "--command=.gdbinit4salome", self.CMD[0]]
00335                 pass
00336             pass
00337         
00338         if self.args["valgrind_session"]:
00339             l = ["valgrind"]
00340             val = os.getenv("VALGRIND_OPTIONS")
00341             if val:
00342                 l += val.split()
00343                 pass
00344             self.CMD = l + self.CMD
00345             pass
00346         
00347 # ---

Here is the call graph for this function:


Member Data Documentation

server.Server.ARGS [inherited]

Definition at line 42 of file server.py.

Reimplemented from server.Server.

Definition at line 239 of file runSalome.py.

Reimplemented from server.Server.

Definition at line 313 of file runSalome.py.

server.Server.PID [inherited]

Reimplemented in runSalome.InterpServer.

Definition at line 40 of file server.py.

Definition at line 244 of file runSalome.py.

Definition at line 245 of file runSalome.py.

string server.Server.server_launch_mode = "daemon" [static, inherited]

Definition at line 37 of file server.py.


The documentation for this class was generated from the following file: