#! /usr/bin/python3

import sys
import json
import subprocess
from aptsources.sourceslist import SourcesList

def main():
    # Read the repositories data from stdin
    repositories = json.loads(sys.stdin.read())
    sources = SourcesList(deb822=True)

    repo_map = dict(repositories)
    for src in sources.list:
        if src.uri in repo_map:
            src.disabled = not repo_map[src.uri]

    sources.save()

    # Refresh the package cache
    subprocess.run(["apt-get", "update"], check=True)

if __name__ == "__main__":
    main()
