-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathprotect.py
More file actions
60 lines (48 loc) · 1.72 KB
/
protect.py
File metadata and controls
60 lines (48 loc) · 1.72 KB
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
import os
import pathlib
import sys
from typing import Iterable
from deploy_util import get_wikis
from protect_page import (
protect_non_existing_page,
protect_existing_page,
handle_protect_errors,
)
WIKI_TO_PROTECT = os.getenv("WIKI_TO_PROTECT")
def check_for_local_version(module: str, wiki: str):
if wiki == "commons":
return False
return pathlib.Path(f"./lua/wikis/{wiki}/{module}.lua").exists()
def protect_if_has_no_local_version(module: str, wiki: str):
page = "Module:" + module
if not check_for_local_version(module, wiki):
protect_non_existing_page(page, wiki)
def main():
lua_files: Iterable[pathlib.Path]
if len(sys.argv[1:]) > 0:
lua_files = [pathlib.Path(arg) for arg in sys.argv[1:]]
elif WIKI_TO_PROTECT:
lua_files = pathlib.Path("./lua/wikis/").rglob("*.lua")
else:
print("Nothing to protect")
exit(0)
for file_to_protect in sorted(lua_files):
print(f"::group::Checking {str(file_to_protect)}")
wiki = file_to_protect.parts[2]
module = "/".join(file_to_protect.parts[3:])[:-4]
page = "Module:" + module
if WIKI_TO_PROTECT:
if wiki == WIKI_TO_PROTECT:
protect_existing_page(page, wiki)
elif wiki == "commons":
protect_if_has_no_local_version(module, WIKI_TO_PROTECT)
elif wiki != "commons":
protect_existing_page(page, wiki)
else: # commons case
protect_existing_page(page, wiki)
for deploy_wiki in get_wikis() - {"commons"}:
protect_if_has_no_local_version(module, deploy_wiki)
print("::endgroup::")
handle_protect_errors()
if __name__ == "__main__":
main()