Skip to content

Commit

Permalink
update translations; use http_archive
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Dec 23, 2020
1 parent f6318af commit 5dd0eaf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
32 changes: 24 additions & 8 deletions ftl/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
import sys
from typing import Optional, Tuple
import requests
from hashlib import sha256

root = os.environ["BUILD_WORKSPACE_DIRECTORY"]
repos_bzl = os.path.join(root, "repos.bzl")
Expand Down Expand Up @@ -64,18 +66,32 @@ def update_git_repos():
@dataclass
class GitInfo:
sha1: str
shallow_since: str
zip_sha256: str


def git_url_to_zip_url(repo: str, commit: str) -> str:
repo = repo.replace("[email protected]:", "https://github.com/")
return f"{repo}/archive/{commit}.zip"


def get_zip_sha(zip_url: str) -> str:
resp = requests.get(zip_url)
resp.raise_for_status()
return sha256(resp.content).hexdigest()


def module_git_info(module: Module) -> GitInfo:
folder = module.folder()
sha = subprocess.check_output(
sha1 = subprocess.check_output(
["git", "log", "-n", "1", "--pretty=format:%H"], cwd=folder
).decode("utf8")
zip_url = git_url_to_zip_url(module.repo, sha1)
zip_sha = get_zip_sha(zip_url)

return GitInfo(
sha1=sha1,
zip_sha256=zip_sha,
)
shallow = subprocess.check_output(
["git", "log", "-n", "1", "--pretty=format:%cd", "--date=raw"], cwd=folder
)
return GitInfo(sha1=sha.decode("utf8"), shallow_since=shallow.decode("utf8"))


def update_repos_bzl():
Expand All @@ -85,12 +101,12 @@ def update_repos_bzl():
git = module_git_info(module)
prefix = f"{module.name}_i18n_"
entries[prefix + "commit"] = git.sha1
entries[prefix + "shallow_since"] = git.shallow_since
entries[prefix + "zip_csum"] = git.zip_sha256

# apply
out = []
path = repos_bzl
reg = re.compile(r'(\s+)(\S+_(?:commit|shallow_since)) = "(.*)"')
reg = re.compile(r'(\s+)(\S+_(?:commit|zip_csum)) = "(.*)"')
for line in open(path).readlines():
if m := reg.match(line):
(indent, key, _oldvalue) = m.groups()
Expand Down
34 changes: 23 additions & 11 deletions repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ def register_repos():
# translations
################

core_i18n_repo = "anki-core-i18n"
core_i18n_commit = "b1c03cebb554e8568529e293756ac36cdf62341a"
core_i18n_shallow_since = "1608607833 +1000"
core_i18n_zip_csum = "ce9c846e6985af9bda2d51390df4dd8a65e91ce9f8f217a0ef46565271303e43"

qtftl_i18n_commit = "e7dda1058c0510665f2ea8d8ffd74e506e578f7a"
qtftl_i18n_shallow_since = "1608607833 +1000"
qtftl_i18n_repo = "anki-desktop-ftl"
qtftl_i18n_commit = "e8fa8cb9a9a5eb4d6f9b4c14111aa2c48ac62cc9"
qtftl_i18n_zip_csum = "557b7ae01324e38d23009805c7bef87d32413682a8bb68726df8724fbb9424c7"

i18n_build_content = """
filegroup(
Expand All @@ -147,19 +149,29 @@ exports_files(["l10n.toml"])
"""

maybe(
new_git_repository,
http_archive,
name = "rslib_ftl",
build_file_content = i18n_build_content,
commit = core_i18n_commit,
shallow_since = core_i18n_shallow_since,
remote = "https://github.com/ankitects/anki-core-i18n",
strip_prefix = core_i18n_repo + "-" + core_i18n_commit,
urls = [
"https://github.com/ankitects/{}/archive/{}.zip".format(
core_i18n_repo,
core_i18n_commit,
),
],
sha256 = core_i18n_zip_csum,
)

maybe(
new_git_repository,
http_archive,
name = "extra_ftl",
build_file_content = i18n_build_content,
commit = qtftl_i18n_commit,
shallow_since = qtftl_i18n_shallow_since,
remote = "https://github.com/ankitects/anki-desktop-ftl",
strip_prefix = qtftl_i18n_repo + "-" + qtftl_i18n_commit,
urls = [
"https://github.com/ankitects/{}/archive/{}.zip".format(
qtftl_i18n_repo,
qtftl_i18n_commit,
),
],
sha256 = qtftl_i18n_zip_csum,
)

0 comments on commit 5dd0eaf

Please sign in to comment.