2 # Copyright (C) 2015-2019 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 # args=["--gui", "--show-desktop=1", "--splash=0"]
26 # args=["--terminal","--modules=FIELDS,PARAVIS,GUI"]
27 class SalomeInstance(object):
38 def start(shutdown_servers=False, with_gui=False, args=[]):
40 log = tempfile.NamedTemporaryFile(suffix='_nsport', delete=True)
43 port_log = port_log + "-%s.log"%(os.getpid())
45 "--ns-port-log=%s"%port_log,
46 "--shutdown-servers=%d"%shutdown_servers
49 salome_instance = SalomeInstance()
50 salome_instance.__run(args=instance_args, with_gui=with_gui)
53 with open(port_log) as f:
54 salome_instance.port = int(f.readline())
59 return salome_instance
62 def __run(self, args=None, with_gui=False):
66 sys.argv = ['runSalome'] + args
69 # :WARNING: NOT TESTED YET
71 sys.argv += ["--show-desktop=1"]
72 sys.argv += ["--splash=0"]
73 #sys.argv += ["--standalone=study"]
74 #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"]
76 sys.argv += ["--terminal"]
77 #sys.argv += ["--shutdown-servers=1"]
78 #sys.argv += ["--modules=FIELDS,PARAVIS,GUI"]
89 session_server = salome.naming_service.Resolve('/Kernel/Session')
91 session_server.emitMessage("connect_to_study")
92 session_server.emitMessage("activate_viewer/ParaView")
97 from multiprocessing import Process
98 from killSalomeWithPort import killMyPort
100 with tempfile.NamedTemporaryFile():
101 p = Process(target = killMyPort, args=(self.port,))
109 if __name__ == "__main__":
110 print("##### Start instance...")
111 salome_instance = SalomeInstance.start()
112 port = salome_instance.get_port()
113 print("##### ...instance started on port %s"%port)
115 print("##### Terminate instance running on port %s"%port)
116 salome_instance.stop()