-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinterlanguage.py
More file actions
executable file
·60 lines (49 loc) · 1.96 KB
/
Copy pathinterlanguage.py
File metadata and controls
executable file
·60 lines (49 loc) · 1.96 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
#! /usr/bin/env python3
import argparse
from ws.client import API
from ws.interactive import require_login
from ws.interlanguage.Categorization import Categorization
from ws.interlanguage.CategoryGraph import CategoryGraph
from ws.interlanguage.Decategorization import Decategorization
from ws.interlanguage.InterlanguageLinks import InterlanguageLinks
modes = ["update", "orphans", "rename"]
_modes_desc = {
"update": "fix categorization of i18n pages, init wanted categories and update all interlanguage links",
"orphans": "list all orphans",
"rename": "rename non-English pages to match the English title after renaming",
}
modes_description = "The available modes are:"
for m in modes:
modes_description += f"\n- '{m}': {_modes_desc[m]}"
def main(args: argparse.Namespace, api: API) -> None:
if args.mode == "update":
# first fix categorization
cat = Categorization(api)
cat.fix_allpages()
decat = Decategorization(api)
decat.fix_allpages()
# init wanted categories
cg = CategoryGraph(api)
cg.init_wanted_categories()
# update intelanguage links
il = InterlanguageLinks(api)
il.update_allpages()
elif args.mode == "orphans":
il = InterlanguageLinks(api)
for title in il.find_orphans():
print(f"* [[{title}]]")
elif args.mode == "rename":
il = InterlanguageLinks(api)
il.rename_non_english()
else:
raise Exception(f"Unknown mode: {args.mode}")
if __name__ == "__main__":
import ws.config
argparser = ws.config.getArgParser(description="Update interlanguage links", epilog=modes_description)
API.set_argparser(argparser)
_group = argparser.add_argument_group("interlanguage")
_group.add_argument("--mode", choices=modes, default="update", help="operation mode of the script")
args = ws.config.parse_args(argparser)
api = API.from_argparser(args)
require_login(api)
main(args, api)