- user = os.getenv('USER')
- filedict = "^%s$"%(getPiDict('(\d*)',full=False))
- fnamere = re.compile(filedict)
- for file in os.listdir(os.getenv("HOME")):
- mo = re.match(fnamere,file)
- if mo and len(mo.groups()):
- killMyPort(mo.groups()[0])
- pass
-
- if not sys.platform == 'win32':
- cmd = "pid=`ps -fea | grep '"+os.getenv('USER')+"' | grep 'ghs3d' | grep 'f /tmp/GHS3D_' | grep -v 'grep' | awk '{print $2}'` ; echo $pid > /tmp/logs/"+os.getenv('USER')+"/_"+"Pid_ghs3d.log"
- a = os.system(cmd)
- try:
- fpidomniNames=open('/tmp/logs/'+os.getenv('USER')+"/_"+"Pid_ghs3d.log")
- prc = fpidomniNames.read()
- fpidomniNames.close()
- if prc != None :
- for field in prc.split(" ") :
- field = field.strip()
- if field != None and len(field) != 0:
- os.system('kill -9 '+field)
- except:
- pass
- pass
-
-if __name__ == "__main__":
+ """
+ Stop all running SALOME sessions owned by the current user.
+ """
+ # detect ports used by SALOME session and kill processes
+ for hidden in (True, False):
+ pidict_t = getPiDict(port='#####', hidden=hidden)
+ dir_pidict_t = osp.dirname(pidict_t)
+ fn_pidict_t = osp.basename(pidict_t).replace('#####', r'(\d*)')
+ fn_rex = re.compile('^{}'.format(fn_pidict_t))
+ with suppress(IOError):
+ for fname in os.listdir(dir_pidict_t):
+ m_res = fn_rex.match(fname)
+ if m_res:
+ killMyPort(m_res.group(1))
+
+ # kill possibly unkilled processes
+ killUnkilledProcesses()
+
+ # other clean-up actions
+ # - delete uri files needed by ompi-server
+ for path in glob(osp.join(osp.expanduser('~'), '.urifile_*')):
+ with suppress(IOError):
+ os.remove(path)
+
+def main():
+ """
+ Main function
+ """
+ from argparse import ArgumentParser
+ parser = ArgumentParser(description='Forcibly stop all running SALOME sessions')
+ parser.parse_args()
+
+ try:
+ from salomeContextUtils import setOmniOrbUserPath
+ setOmniOrbUserPath()
+ except Exception as exc: # pragma pylint: disable=broad-except
+ print(exc)
+ sys.exit(1)
+