#!/usr/bin/env python3

import re
import sys

from io import StringIO


def Config(filename):
    globals = {}
    module = "/usr/share/checkbox/install/config"
    exec(open(module), globals)
    config = globals["Config"]()
    config.read(filename)

    return config

def main(args):
    config_file = "/etc/checkbox.d/%s.ini" % args[0]
    config = Config(config_file)

    if config.has_section("checkbox/plugins/suites_prompt"):
        old_blacklist = config.get("checkbox/plugins/suites_prompt", "blacklist")
        new_blacklist = set(re.split(r"\s+", old_blacklist))
        new_blacklist.add("autotest")
        new_blacklist.add("ltp")
        new_blacklist.add("phoronix")
        new_blacklist.add("qa-regression-testing")
        
        config.set("checkbox/plugins/suites_prompt", "blacklist",
            " ".join(new_blacklist))

    # Rename options
    file = open(config_file, "w")
    config.write(file)


if __name__ == "__main__":
    main(sys.argv[1:])
