changes for 3.0
[monitor.git] / nodesets.py
1 #!/usr/bin/python
2
3 import sys
4 import os
5 from sets import Set
6 import parser as parsermodule
7 import util.file
8
9 def main():
10         parser = parsermodule.getParser()
11         parser.set_defaults(operation="and",)
12         parser.add_option("", "--operation", dest="operation", metavar="and", 
13                                                 help="""Which operation to perform on the two sets.  (and, or, minus""")
14
15         config = parsermodule.parse_args(parser)
16
17         f1 = config.args[0]
18         f2 = config.args[1]
19
20         s1 = util.file.getListFromFile(f1)
21         s2 = util.file.getListFromFile(f2)
22
23         s = nodesets(config.operation, s1, s2)
24
25         if config.operation == "and":
26                 print "Nodes in both sets", len(Set(s1) & Set(s2))
27         elif config.operation == "uniquetoone" or config.operation == "minus":
28                 print "Nodes unique to set 1", len(Set(s1) - Set(s2))
29         elif operation == "or":
30                 print "Union of nodes in both sets", len(Set(s1) | Set(s2))
31
32         for i in s:
33                 print i
34
35
36 def nodesets(operation, s1, s2):
37
38         if operation == "and":
39                 return Set(s1) & Set(s2)
40         elif operation == "uniquetoone" or operation == "minus":
41                 return Set(s1) - Set(s2)
42         elif operation == "or":
43                 return Set(s1) | Set(s2)
44         else:
45                 print "Unknown operation: %s " % operation
46         
47         return []
48
49 if __name__ == "__main__":
50         main()