changes for 3.0
[monitor.git] / blacklist.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import string
6 import time
7 import database
8 import plc
9 import getopt
10
11 def usage():
12         print "blacklist.py --delete=<i>" 
13
14 def main():
15
16         try:
17                 longopts = ["delete=", "help"]
18                 (opts, argv) = getopt.getopt(sys.argv[1:], "d:h", longopts)
19         except getopt.GetoptError, err:
20                 print "Error: " + err.msg
21                 sys.exit(1)
22
23         l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
24
25         for (opt, optval) in opts:
26                 if opt in ["-d", "--delete"]:
27                         i = int(optval)
28                         del l_blacklist[i]
29                 else:
30                         usage()
31                         sys.exit(0)
32
33         i_cnt = 0
34         for i in l_blacklist:
35                 print i_cnt, " ", i
36                 i_cnt += 1
37
38         while 1:
39                 line = sys.stdin.readline()
40                 if not line:
41                         break
42                 line = line.strip()
43                 if not line in l_blacklist:
44                         l_blacklist.append(line)
45
46         print "Total %d nodes in blacklist" % (len(l_blacklist))
47         database.dbDump("l_blacklist")
48         
49 if __name__ == '__main__':
50         import os
51         #try:
52         main()
53         #except Exception, error:
54         #       print "Exception %s" % error
55         #       sys.exit(0)