#!/usr/bin/env python
-import os, string, sys
+import os, string, sys, re
-from killSalomeWithPort import killMyPort
+from killSalomeWithPort import killMyPort, getPiDict
def killAllPorts():
user = os.getenv('USER')
+ filedict = "^%s$"%(getPiDict('(\d*)',full=False))
+ fnamere = re.compile(filedict)
for file in os.listdir(os.getenv("HOME")):
- l = string.split(file, "_")
- if len(l) >= 4:
- if file[:len(user)] == user:
- if l[len(l)-2] == "SALOME" and l[len(l)-1] == "pidict":
- killMyPort(l[len(l)-3])
+ mo = re.match(fnamere,file)
+ if mo and len(mo.groups()):
+ killMyPort(mo.groups()[0])
pass
if __name__ == "__main__":
#!/usr/bin/env python
import os, sys, pickle, signal, commands
+def getPiDict(port,appname='salome',full=True):
+ filedict = []
+ filedict.append( os.getenv('USER') ) # user name
+ filedict.append( os.getenv('HOSTNAME') ) # host name
+ filedict.append( str(port) ) # port number
+ filedict.append( appname.upper() ) # application name
+ filedict.append( 'pidict' ) # constant part
+
+ filedict = '_'.join(filedict)
+ if full:
+ filedict = os.getenv("HOME") + '/' + filedict
+ return filedict
+
########## kills all salome processes with the given port ##########
def killMyPort(port):
- filedict=os.getenv("HOME")+'/'+os.getenv('USER')+"_"+port+'_SALOME_pidict'
+ filedict=getPiDict(port)
found = 0
try:
fpid=open(filedict, 'r')
print "--- erreur au lancement Salome ---"
#print process_id
-
- filedict = os.getenv("HOME") + '/' + os.getenv('USER') + "_" + str(args['port']) \
- + '_' + args['appname'].upper() + '_pidict'
-
+
+ from killSalomeWithPort import getPiDict
+ filedict = getPiDict(args['port'], args['appname'])
+
process_ids = []
try:
fpid=open(filedict, 'r')