+ # Check all possible versions of pidict file
+ # new-style - dot-prefixed pidict file: hidden is True, auto hostname
+ # old-style - not dot-prefixed pidict file: hidden is False, auto hostname
+ # old-style - dot-prefixed pidict file: hidden is True, short hostname
+ # old-style - not dot-prefixed pidict file: hidden is False, short hostname
+ # old-style - dot-prefixed pidict file: hidden is True, long hostname
+ # old-style - not dot-prefixed pidict file: hidden is False, long hostname
+ for hostname, hidden in itertools.product((None, getShortHostName(), getHostName()),
+ (True, False)):
+ filedict = getPiDict(port, hidden=hidden, hostname=hostname)
+ if not osp.exists(filedict):
+ if verbose():
+ print('Trying {}... not found'.format(filedict))
+ continue
+ if verbose():
+ print('Trying {}... OK'.format(filedict))
+ return filedict
+
+ return None
+
+def killMyPortSSL(*ports):
+ """ Called by runSalome.py after CTRL-C"""
+ for port in ports:
+ # ensure port is an integer
+ with suppress(ValueError):
+ port = int(port)
+
+ with suppress(Exception):
+ # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
+ from PortManager import releasePort
+ # get pidict file
+ filedict = getPiDict(port)
+ if not osp.isfile(filedict): # removed by previous call, see (1) above
+ if verbose():
+ print("SALOME session on port {} is already stopped".format(port))
+ # remove port from PortManager config file
+ with suppress(ImportError):
+ if verbose():
+ print("Removing port from PortManager configuration file")
+ releasePort(port)
+ return
+ try:
+ # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
+ import PortManager # pragma pylint: disable=unused-import
+ for file_path in glob('{}*'.format(getPiDict(port))):
+ __killMyPort(port, file_path)
+ except ImportError:
+ __killMyPort(port, __guessPiDictFilename(port))
+
+ # clear-up omniOrb config files
+ appliCleanOmniOrbConfig(port)
+
+def killMyPort(*ports):
+ """
+ Kill SALOME session running on the specified port.
+ :param ports : port numbers
+ """
+ for port in ports:
+ # ensure port is an integer
+ with suppress(ValueError):
+ port = int(port)
+
+ with suppress(Exception):
+ # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
+ from PortManager import releasePort
+ # get pidict file
+ filedict = getPiDict(port)
+ if not osp.isfile(filedict): # removed by previous call, see (1) above
+ if verbose():
+ print("SALOME session on port {} is already stopped".format(port))
+ # remove port from PortManager config file
+ with suppress(ImportError):
+ if verbose():
+ print("Removing port from PortManager configuration file")
+ releasePort(port)
+ return
+
+ # try to shutdown session normally
+ Thread(target=shutdownMyPort, args=(port, True)).start()
+ # wait a little...
+ sleep(3)
+ # ... then kill processes (should be done if shutdown procedure hangs up)
+ try:
+ # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
+ import PortManager # pragma pylint: disable=unused-import
+ for file_path in glob('{}*'.format(getPiDict(port))):
+ __killMyPort(port, file_path)
+ except ImportError:
+ __killMyPort(port, __guessPiDictFilename(port))
+
+ # clear-up omniOrb config files
+ appliCleanOmniOrbConfig(port)
+
+def cleanApplication(port):
+ """
+ Clean application running on the specified port.
+ :param port : port number
+ """
+ # ensure port is an integer
+ with suppress(ValueError):
+ port = int(port)
+
+ # remove pidict file
+ with suppress(Exception):
+ filedict = getPiDict(port)
+ os.remove(filedict)