2024-03-10 13:26:58 +01:00
|
|
|
#!/bin/python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
2024-06-01 13:50:06 +02:00
|
|
|
import sys
|
2024-03-10 13:26:58 +01:00
|
|
|
import zipfile
|
|
|
|
from urllib.request import urlretrieve
|
|
|
|
|
|
|
|
|
|
|
|
# git diff should be empty, and there should be no errors
|
|
|
|
def check_git():
|
|
|
|
result = subprocess.run(["git", "diff", "--name-only"], capture_output=True)
|
|
|
|
if result.returncode != 0 or len(result.stdout) != 0:
|
2024-06-01 13:50:06 +02:00
|
|
|
cont = input("uncommitted changes found, continue? [y/N] ")
|
|
|
|
if cont != "y":
|
|
|
|
sys.exit()
|
2024-03-10 13:26:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
# download and update translations
|
|
|
|
def update_translations():
|
|
|
|
url = "https://translate.codeberg.org/download/heliboard/?format=zip"
|
|
|
|
zip_file_name = "translations.zip"
|
|
|
|
urlretrieve(url, zip_file_name)
|
2024-04-19 22:58:58 +02:00
|
|
|
# extract all in heliboard/heliboard/app/src/main/res and heliboard/heliboard/fastlane/metadata
|
2024-03-10 13:26:58 +01:00
|
|
|
with zipfile.ZipFile(zip_file_name, "r") as f:
|
|
|
|
for file in f.filelist:
|
2024-04-19 22:58:58 +02:00
|
|
|
if not file.filename.startswith("heliboard/heliboard/app/src/main/res")\
|
|
|
|
and not file.filename.startswith("heliboard/heliboard/fastlane/metadata"):
|
2024-03-10 13:26:58 +01:00
|
|
|
continue
|
|
|
|
file.filename = file.filename.replace("heliboard/heliboard/", "")
|
|
|
|
f.extract(file)
|
|
|
|
os.remove(zip_file_name)
|
|
|
|
|
|
|
|
|
|
|
|
# git diff to make sure default strings are the same
|
|
|
|
def check_default_values_diff():
|
|
|
|
result = subprocess.run(["git", "diff", "--name-only", "app/src/main/res/values"], capture_output=True)
|
|
|
|
if result.returncode != 0 or len(result.stdout) != 0:
|
|
|
|
raise ValueError("default strings changed after translation import, something is wrong")
|
|
|
|
|
|
|
|
|
2024-06-01 13:50:06 +02:00
|
|
|
def read_dicts_readme() -> list[str]:
|
|
|
|
dicts_readme_file = "../dictionaries/README.md"
|
|
|
|
if os.path.isfile(dicts_readme_file):
|
|
|
|
f = open(dicts_readme_file)
|
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
|
|
|
return lines
|
|
|
|
readme_url = "https://codeberg.org/Helium314/aosp-dictionaries/raw/branch/main/README.md"
|
|
|
|
tmp_readme = "dicts_readme_tmp.md"
|
|
|
|
urlretrieve(readme_url, tmp_readme)
|
|
|
|
f = open(tmp_readme)
|
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
|
|
|
os.remove(tmp_readme)
|
|
|
|
return lines
|
|
|
|
|
|
|
|
|
|
|
|
# generate a list of dictionaries available in the dictionaries repository at (https://codeberg.org/Helium314/aosp-dictionaries
|
|
|
|
# for convenient linking when adding dictionaries in HeliBoard.
|
2024-03-10 13:26:58 +01:00
|
|
|
def update_dict_list():
|
2024-06-01 13:50:06 +02:00
|
|
|
lines = read_dicts_readme()
|
|
|
|
mode = 0
|
|
|
|
dicts = []
|
|
|
|
for line in lines:
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith("#"):
|
|
|
|
if line == "# Dictionaries":
|
|
|
|
mode = 1
|
|
|
|
elif line == "# Experimental dictionaries":
|
|
|
|
mode = 2
|
|
|
|
else:
|
|
|
|
mode = 0
|
|
|
|
if mode == 0 or not line.startswith("*"):
|
|
|
|
continue
|
|
|
|
dict_name = line.split("]")[1].split("(")[1].split(")")[0].split("/")[-1].split(".dict")[0]
|
|
|
|
(dict_type, locale) = dict_name.split("_", 1)
|
|
|
|
if "_" in locale:
|
|
|
|
sp = locale.split("_")
|
|
|
|
locale = sp[0]
|
|
|
|
for s in sp[1:]:
|
|
|
|
locale = locale + "_" + s.upper()
|
|
|
|
if mode == 2:
|
|
|
|
dicts.append(f"{dict_type},{locale},exp\n")
|
|
|
|
else:
|
|
|
|
dicts.append(f"{dict_type},{locale},\n")
|
|
|
|
target_file = "app/src/main/assets/dictionaries_in_dict_repo.csv"
|
|
|
|
with open(target_file, 'w') as f:
|
|
|
|
f.writelines(dicts)
|
2024-03-10 13:26:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
# check whether there is a changelog file for current version and print result and version code
|
|
|
|
def check_changelog():
|
|
|
|
changelog_dir = "fastlane/metadata/android/en-US/changelogs"
|
|
|
|
assert os.path.isdir(changelog_dir)
|
2024-06-01 13:50:06 +02:00
|
|
|
filenames = []
|
|
|
|
for file in os.scandir(changelog_dir):
|
|
|
|
filenames.append(file.name)
|
2024-03-10 13:26:58 +01:00
|
|
|
filenames.sort()
|
2024-06-01 13:50:06 +02:00
|
|
|
changelog_version = filenames[-1].replace(".txt", "")
|
2024-03-11 23:04:14 +01:00
|
|
|
version = ""
|
2025-03-02 07:33:10 +01:00
|
|
|
with open("app/build.gradle.kts") as f:
|
2024-03-10 13:26:58 +01:00
|
|
|
for line in f:
|
|
|
|
line = line.lstrip()
|
|
|
|
if line.startswith("versionCode"):
|
2025-03-02 07:33:10 +01:00
|
|
|
version = line.split(" ")[2].rstrip()
|
2024-03-10 13:26:58 +01:00
|
|
|
break
|
2024-03-11 23:04:14 +01:00
|
|
|
if changelog_version == version:
|
|
|
|
print("changelog for", version, "exists")
|
|
|
|
else:
|
|
|
|
print("changelog for", version, "does not exist")
|
2024-03-10 13:26:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2024-06-01 13:50:06 +02:00
|
|
|
if os.getcwd().endswith("tools"):
|
|
|
|
os.chdir("../")
|
2024-03-10 13:26:58 +01:00
|
|
|
check_git()
|
|
|
|
update_translations()
|
|
|
|
check_default_values_diff()
|
|
|
|
update_dict_list()
|
|
|
|
check_changelog()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|