tweaks
[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
8 def main():
9         parser = parsermodule.getParser()
10         parser.set_defaults(operation="and",)
11         parser.add_option("", "--operation", dest="operation", metavar="and", 
12                                                 help="""Which operation to perform on the two sets.  (and, or, minus""")
13
14         config = parsermodule.parse_args(parser)
15
16         f1 = config.args[0]
17         f2 = config.args[1]
18
19         s1 = config.getListFromFile(f1)
20         s2 = config.getListFromFile(f2)
21
22         s = nodesets(config.operation, s1, s2)
23
24         if config.operation == "and":
25                 print "Nodes in both sets", len(Set(s1) & Set(s2))
26         elif config.operation == "uniquetoone" or config.operation == "minus":
27                 print "Nodes unique to set 1", len(Set(s1) - Set(s2))
28         elif operation == "or":
29                 print "Union of nodes in both sets", len(Set(s1) | Set(s2))
30
31         for i in s:
32                 print i
33
34
35 def nodesets(operation, s1, s2):
36
37         if operation == "and":
38                 return Set(s1) & Set(s2)
39         elif operation == "uniquetoone" or operation == "minus":
40                 return Set(s1) - Set(s2)
41         elif operation == "or":
42                 return Set(s1) | Set(s2)
43         else:
44                 print "Unknown operation: %s " % operation
45         
46         return []