diff --git a/scripts/remove_repo.py b/scripts/remove_repo.py new file mode 100644 index 0000000..32c1a7e --- /dev/null +++ b/scripts/remove_repo.py @@ -0,0 +1,80 @@ +import sys +import json + + +if len(sys.argv) < 2: + print(' Usage: python3 scripts/remove_repo.py [repository] [removal_type] "[reason]" [link]') + exit(1) + +try: + repo = sys.argv[1] +except Exception: + repo = None + +try: + removal_type = sys.argv[2] +except Exception: + removal_type = None + +try: + reason = sys.argv[3] +except Exception: + reason = None + +try: + link = sys.argv[4] +except Exception: + link = None + +remove = { + "link": link, + "reason": reason, + "removal_type": removal_type, + "repository": repo +} + +foundcategory = None +categorycontent = None +blacklistcontent = None +removedcontent = None + +for category in ["blacklist", "appdaemon", "integration", "netdaemon", "plugin", "python_script", "theme"]: + with open(category, "r") as cat_file: + content = json.loads(cat_file.read()) + if remove["repository"] in content: + print(f"Found in {category}") + foundcategory = category + categorycontent = content + break + +if foundcategory is None or foundcategory is None: + print(f"Could not find repository {remove['repository']}") + exit(1) + +with open("blacklist", "r") as blacklist_file: + blacklistcontent = json.loads(blacklist_file.read()) + +with open("removed", "r") as removed_file: + removedcontent = json.loads(removed_file.read()) + +blacklistcontent.append(remove["repository"]) +categorycontent.remove(remove["repository"]) + +data = {"repository": repo} +if remove["reason"] is not None: + data["reason"] = remove["reason"] +if remove["removal_type"] is not None: + data["removal_type"] = remove["removal_type"] +if remove["link"] is not None: + data["link"] = remove["link"] + +removedcontent.append(data) + +with open("blacklist", "w") as blacklist_file: + blacklist_file.write(json.dumps(sorted(blacklistcontent, key=str.casefold), indent=2)) + +with open("removed", "w") as removed_file: + removed_file.write(json.dumps(removedcontent, indent=2)) + +with open(foundcategory, "w") as cat_file: + cat_file.write(json.dumps(sorted(categorycontent, key=str.casefold), indent=2))