2 # lightweight salome launcher
9 from searchFreePort import searchFreePort
11 import SALOME_ModuleCatalog
13 # define supported options
14 # [PYTHON_FILE [args] [PYTHON_FILE [args]...]]
15 usage = """Usage: salome.py [options] [python_file [args]] [python_file [args]] ...
16 Python file arguments, if any, must be comma-separated and prefixed by args
17 (without blank characters and quotes), e.g. myscript.py args:arg1,arg2=val
19 Starts salome and optionnally executes python scripts provided as trailing arguments"""
20 from optparse import OptionParser
21 parser = OptionParser(usage=usage)
22 parser.add_option("-g", "--gui", action="store_true", dest="gui", default=False,
23 help="Launch salome servers and start gui")
24 parser.add_option("-t", "--tui", action="store_true", dest="tui", default=False,
25 help="Launch salome servers")
26 parser.add_option("-e", "--environ", action="store_true", dest="env", default=False,
27 help="return a bash shell with Salome environement set")
31 (options, args) = parser.parse_args()
32 if not (options.gui or options.tui or options.env):
33 # all options are set to false! activate gui option
36 options.extra_args=None
37 if args: # parse optionnal python scripts args
38 options.extra_args=parse_extra_args(args)
44 if options.tui or options.gui:
45 clt=start_salome(options)
47 # print(" --- registered objects tree in Naming Service ---")
50 def parse_extra_args(args):
51 # these extra args represent python script files with optionnally their arguments
52 extra_args=[] # build a list of dicts (the form required by salome session server)
54 # pull first arg, check it is a file
58 if not os.path.isfile(pyfilename):
59 continue # if the arg is not a file name we skip it
60 if args and args[0].startswith("args:"):
61 #if the next arg is related to pyscript, pull it and process it
62 pyargs=args[0][5:].split(",")
64 extra_args.append({pyfilename:pyargs})
69 proc = subprocess.Popen(cmd, shell=False, close_fds=True)
71 return proc.returncode
73 def start_salome(options):
76 # Launch Registry Server, and wait for it available in Naming Service
77 RegistryServer().run()
78 clt.waitNS("/Registry")
80 # Launch Module Catalog Server, and wait for it available in Naming Service
82 clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
84 # launch SalomeDS server, wait for it available in Naming Service
85 SalomeDSServer().run()
89 ConnectionManagerServer().run()
91 # launch Session Server
93 # process our list of extra args into a string redeable by session server (json style)
95 if options.extra_args: # pyscripts were specified, we transfer the info to gui
96 pyscriptargs='--pyscript=%s' % json.dumps(options.extra_args)
97 SessionServer().run(pyscriptargs)
99 # start launcher server
100 LauncherServer().run()
101 # clt.waitNS("/LauncherServer")
104 # in tui mode, start FactoryServer standalone
105 # ContainerServer().run() CNC KO?
106 # run specified pyscripts, if any
107 if options.extra_args:
108 for file_args_dict in options.extra_args:
109 for f in file_args_dict.keys():
111 for arg in file_args_dict[f]:
113 print ("command to execute pyscript: ", command)
114 proc = subprocess.Popen(command, shell=True)
115 # addToKillList(proc.pid, command, args['port']) ??
117 if res: sys.exit(1) # if there's an error when executing script, we should explicitly exit
120 session=clt.waitNS("/Kernel/Session",SALOME.Session)
124 # initialise orb and naming service
126 print("Initialise ORB and Naming Service")
127 clt=orbmodule.client()
130 def generate_module_catalog():
131 salome_modules=os.getenv("SALOME_MODULES")
132 assert salome_modules != None, "SALOME_MODULES variable not found!"
134 for module in salome_modules.split(","):
135 module_root_dir = os.getenv(module + "_ROOT_DIR")
136 module_cata = module + "Catalog.xml"
137 cata_path.extend(glob.glob(os.path.join(module_root_dir,"share","salome",
138 "resources",module.lower(), module_cata)))
139 return ':'.join(cata_path)
141 # base class to start corba servers
146 pid = os.spawnvp(os.P_NOWAIT, args[0], args)
147 print ("start server ", args, " (pid = %s)" % pid)
149 class LauncherServer(Server):
150 CMD=['SALOME_LauncherServer']
152 class ConnectionManagerServer(Server):
153 CMD=['SALOME_ConnectionManagerServer']
155 class SalomeDSServer(Server):
156 CMD=['SALOMEDS_Server']
158 class RegistryServer(Server):
159 CMD=['SALOME_Registry_Server', '--salome_session','theSession']
161 class ContainerServer(Server):
162 CMD=['SALOME_Container','FactoryServer','-ORBInitRef','NameService=corbaname::localhost']
164 class LoggerServer(Server):
165 CMD=['SALOME_Logger_Server', 'logger.log']
167 class CatalogServer(Server):
168 CMD=['SALOME_ModuleCatalog_Server','-common']
170 self.CMD = self.CMD + [generate_module_catalog()]
173 class NotifyServer(Server):
174 CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior']
176 class SessionServer(Server):
177 CMD=['SALOME_Session_Server','--with','Container','(','FactoryServer',')','--with', 'SalomeAppEngine', '(', ')', 'CPP', 'GUI', 'SPLASH', '--language=fr']
178 def run(self, pyscriptopt):
179 if pyscriptopt: # communicate to gui the scripts to run
180 self.CMD = self.CMD + [pyscriptopt]
181 salome_modules=os.getenv("SALOME_MODULES")
182 assert salome_modules != None, "SALOME_MODULES variable not found!"
183 self.CMD = self.CMD + ['--modules (' + salome_modules.replace(",",":") + ')' ]
186 if __name__ == "__main__":