summaryrefslogtreecommitdiff
path: root/subcapset.py
blob: 375dc1bacb6e7e4dfc47831c7ccd66f91b80e9c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
"""Detects and removes sub-capsets.

[00 01 10] is a subcapset of [00 01 10 22], and thus would be filtered."""

from sys import argv, stdout

def main():
    if len(argv) <= 1: infile = "capset.out"
    if len(argv) >  1: infile = argv[1]
    if len(argv) <= 2: outfile = "capset.filtered"
    if len(argv) >  2: outfile = argv[2]

    capsets = []
    capset_file = open(infile, "r")
    for line in capset_file:
        capsets.append(tuple(line[1:-2].split(" ")))
    capset_file.close()

    if outfile:
        stdout = open(outfile, "w")

    capsetSet = set(capsets)
    for capset in capsets:
        for i in range(len(capset)):
            capsetSet.discard(capset[:i] + capset[i+1:])
    for capset in capsets:
        if capset in capsetSet:
            print("[" + " ".join(capset) + "]", file=stdout)

if __name__ == "__main__":
    main()