forked from hacs/default
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_repo.py
107 lines (86 loc) · 2.73 KB
/
remove_repo.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
import json
# Information https://hacs.xyz/docs/publish/remove
if len(sys.argv) < 3:
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,
}
orgs = ["custom-cards", "custom-components"]
foundcategory = None
categorycontent = None
blacklistcontent = None
removedcontent = None
for category in [
"appdaemon",
"integration",
"netdaemon",
"plugin",
"python_script",
"template",
"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
content.remove(remove["repository"])
with open(category, "w") as outfile:
outfile.write(json.dumps(sorted(content, key=str.casefold), indent=2))
break
if remove["repository"].split("/")[0] not in orgs:
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())
if remove["repository"] in blacklistcontent:
print(f"{remove['repository']} has already been removed")
exit(0)
blacklistcontent.append(remove["repository"])
if remove["repository"].split("/")[0] not in orgs:
if remove["repository"] in categorycontent:
categorycontent.remove(remove["repository"])
data = {"repository": remove["repository"]}
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))
if remove["repository"].split("/")[0] not in orgs:
with open(foundcategory, "w") as cat_file:
cat_file.write(json.dumps(sorted(categorycontent, key=str.casefold), indent=2))