Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/yacs.git] / bin / addToKillList.py
1 #!/usr/bin/env python
2
3 import os, sys, pickle, string
4
5 ########## adds to the kill list of SALOME one more process ##########
6 def addToKillList(command_pid, command):
7     command=(command.split(" "))[0]
8
9     my_port = 2809
10     try:
11       file = open(os.environ["OMNIORB_CONFIG"], "r")
12       s = file.read()
13       while len(s):
14         l = string.split(s, ":")
15         if string.split(l[0], " ")[0] == "ORBInitRef" or string.split(l[0], " ")[0] == "InitRef" :
16           my_port = int(l[len(l)-1])
17           pass
18         s = file.read()
19         pass
20     except:
21         pass
22     #print "myport = ", my_port
23
24     filedict=os.getenv("HOME")+'/'+os.getenv('USER')+"_"+str(my_port)+'_SALOME_pidict'
25     try:
26         fpid=open(filedict, 'r')
27         process_ids=pickle.load(fpid)
28         fpid.close()
29     except:
30         process_ids=[{}]
31         pass
32         
33     already_in=0
34     for process_id in process_ids:
35         print process_id
36         for pid, cmd in process_id.items():
37             #print "see process %s : %s"% (pid, cmd[0])
38             if pid == command_pid:
39                 already_in=1
40         pass
41
42     if already_in == 0:
43         try:
44             process_ids.append({command_pid: [command]})
45             fpid=open(filedict,'w')
46             pickle.dump(process_ids, fpid)
47             fpid.close()
48         except:
49             print "addToKillList: can not add command %s to the kill list"% filedict
50             pass
51         pass
52
53 if __name__ == "__main__":
54     print sys.argv
55     addToKillList(sys.argv[1], sys.argv[2])