-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwrite_redirects.py
41 lines (36 loc) · 1.86 KB
/
write_redirects.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
import os
# For branch redirects. E.g. if we want to convert 'alpha' -> 'beta' in all URLs,
# but still maintain the old URLs just in case someone has not updated
# broken branch -> fixed branch
REDIRECTS = {
"twilightundefined": "twilight", # A bug there was with previous twilight updates
"alpha": "release", # Alpha -> Beta
"alpha-generic": "release", # Alpha -> Beta
"beta-generic": "release", # Beta (Generic) -> Beta
"twilight-generic": "twilight", # Twilight (Generic) -> Twilight
"beta": "release", # Beta -> Release
"release-generic": "release", # Generic release -> release
}
UPDATES_ROOT = "updates/browser"
for new, old in REDIRECTS.items():
print(f"Redirecting {old} -> {new}")
# just create and copy the content of the old file to the new file
# the structure of the updates server is updates/browser/<target_build>/<branch>/update.xml
# we want to replace the branch with the new branch
for target in os.listdir(UPDATES_ROOT):
target_path = os.path.join(UPDATES_ROOT, target)
for branch in os.listdir(target_path):
if branch == old:
# The directory doesnt exist, so we create a new one
new_branch_path = os.path.join(target_path, new)
old_branch_path = os.path.join(target_path, old)
os.makedirs(new_branch_path)
for update in os.listdir(old_branch_path):
update_path = os.path.join(old_branch_path, update)
with open(update_path, "r") as f:
content = f.read()
new_update_path = os.path.join(new_branch_path, update)
with open(new_update_path, "w") as nf:
nf.write(content)
print(f"Redirected {old} -> {new} in {target}/{branch}")
print("Done! Let's build the site next!")