2021-08-30 19:36:25 +02:00
|
|
|
from typing import Dict, List, Tuple
|
2021-08-25 12:21:56 +02:00
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from config import *
|
2021-08-31 17:58:11 +02:00
|
|
|
from priorities import priorities, Priority
|
2021-08-25 12:21:56 +02:00
|
|
|
|
|
|
|
s = requests.Session()
|
|
|
|
s.headers.update({"Authorization": "Token " + token})
|
|
|
|
|
2021-08-27 20:38:22 +02:00
|
|
|
PROJECT = "matomo" # "matomo-premium-plugins"
|
|
|
|
|
|
|
|
|
|
|
|
def diff_dicts(dict1, dict2):
|
|
|
|
return {key: dict1[key] for key in set(dict1) - set(dict2)}
|
|
|
|
|
2021-08-25 12:21:56 +02:00
|
|
|
|
|
|
|
def lock_component(component, unlock=False):
|
|
|
|
lock = not unlock
|
|
|
|
lock_url = component["lock_url"]
|
|
|
|
r = s.post(lock_url, data={"lock": lock})
|
|
|
|
print(r.json())
|
|
|
|
r.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
def update_setting(component, settings: Dict):
|
|
|
|
component_url = component["url"]
|
2021-08-27 20:38:22 +02:00
|
|
|
r = s.patch(component_url, json=settings)
|
|
|
|
if r.status_code > 200:
|
|
|
|
print(r.json())
|
|
|
|
r.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
def create_addon(component, name, configuration: Dict):
|
|
|
|
component_url = component["url"]
|
|
|
|
r = s.post(component_url + "addons/", json={"name": name, "configuration": configuration})
|
2021-08-25 12:21:56 +02:00
|
|
|
if r.status_code > 200:
|
|
|
|
print(r.json())
|
|
|
|
r.raise_for_status()
|
|
|
|
|
|
|
|
|
2021-08-30 19:36:25 +02:00
|
|
|
def get_addons(addons: List[str]) -> Tuple[Dict[str, int], Dict[str, Dict]]:
|
|
|
|
ids = {}
|
|
|
|
configs = {}
|
|
|
|
for addon in addons:
|
|
|
|
r = s.get(addon)
|
|
|
|
data = r.json()
|
|
|
|
ids[data["name"]] = data["id"]
|
|
|
|
configs[data["name"]] = data["configuration"]
|
|
|
|
return ids, configs
|
|
|
|
|
|
|
|
|
2021-08-25 12:21:56 +02:00
|
|
|
components = {}
|
|
|
|
|
2021-08-27 20:38:22 +02:00
|
|
|
r = s.get(url + f"projects/{PROJECT}/components/")
|
2021-08-25 12:21:56 +02:00
|
|
|
|
|
|
|
data = r.json()
|
|
|
|
count = data["count"]
|
|
|
|
for comp in data["results"]:
|
|
|
|
components[comp["slug"]] = comp
|
|
|
|
|
|
|
|
while data["next"]:
|
|
|
|
r = s.get(data["next"])
|
|
|
|
data = r.json()
|
|
|
|
for comp in data["results"]:
|
|
|
|
components[comp["slug"]] = comp
|
|
|
|
|
|
|
|
assert len(components) == count
|
|
|
|
|
|
|
|
phpcomponents = {slug: comp for slug, comp in components.items() if not comp["is_glossary"]}
|
|
|
|
|
|
|
|
community_components = {slug: comp for slug, comp in components.items() if "Community" in comp["name"]}
|
|
|
|
|
2021-08-27 20:38:22 +02:00
|
|
|
official_components = diff_dicts(phpcomponents, community_components)
|
2021-08-25 12:21:56 +02:00
|
|
|
|
2021-08-25 21:49:08 +02:00
|
|
|
core_repo_components = {slug: comp for slug, comp in components.items() if
|
|
|
|
"https://github.com/matomo-org/matomo/" == comp["repo"]}
|
|
|
|
|
2021-08-27 20:38:22 +02:00
|
|
|
non_core_repo_components = diff_dicts(phpcomponents, core_repo_components)
|
2021-08-30 19:36:25 +02:00
|
|
|
non_core_repo_components = diff_dicts(non_core_repo_components, community_components)
|
2021-08-27 20:38:22 +02:00
|
|
|
|
2021-08-30 19:36:25 +02:00
|
|
|
for slug, comp in phpcomponents.items():
|
2021-08-25 12:21:56 +02:00
|
|
|
print(slug, comp["name"])
|
2021-08-30 19:36:25 +02:00
|
|
|
addon_ids, addon_configs = get_addons(comp["addons"])
|
|
|
|
license = comp["license"]
|
|
|
|
if license != "GPL-3.0-or-later":
|
|
|
|
print(license)
|
2021-08-31 17:58:11 +02:00
|
|
|
if slug in priorities:
|
|
|
|
priority = priorities[slug]
|
|
|
|
else:
|
|
|
|
priority = Priority.medium
|
|
|
|
update_setting(comp, {
|
|
|
|
"check_flags": "php-format,safe-html,ignore-optional-plural",
|
|
|
|
# "license": "proprietary",
|
|
|
|
"manage_units": False, # Manage strings
|
2021-09-02 12:30:05 +02:00
|
|
|
"edit_template": False,
|
2021-08-31 17:58:11 +02:00
|
|
|
"enforced_checks": [
|
|
|
|
"php_format"
|
|
|
|
],
|
|
|
|
"priority": priority.value,
|
|
|
|
"language_code_style": "bcp",
|
|
|
|
"new_lang": "contact",
|
|
|
|
"push_on_commit": True,
|
2021-09-02 12:30:05 +02:00
|
|
|
"commit_message": "Translated using Weblate ({{ language_name }})\n\nCurrently translated at {{ stats.translated_percent }}% ({{ stats.translated }} of {{ stats.all }} strings)\n\nTranslation: {{ project_name }}/{{ component_name }}\nTranslate-URL: {{ url }}\n\n[ci skip]",
|
|
|
|
"add_message": "Added translation using Weblate ({{ language_name }})\n\n[ci skip]",
|
|
|
|
"delete_message": "Deleted translation using Weblate ({{ language_name }})\n\n[ci skip]",
|
|
|
|
"merge_message": "Merge branch '{{ component_remote_branch }}' into Weblate.\n\n[ci skip]",
|
|
|
|
"addon_message": "Update translation files\n\nUpdated by \"{{ addon_name }}\" hook in Weblate.\n\nTranslation: {{ project_name }}/{{ component_name }}\nTranslate-URL: {{ url }}\n\n[ci skip]",
|
2021-08-31 17:58:11 +02:00
|
|
|
})
|
2021-09-02 12:30:05 +02:00
|
|
|
is_wordpress = "Wordpress" in comp["name"]
|
|
|
|
if "weblate.cleanup.blank" not in addon_ids.keys() and not is_wordpress:
|
2021-08-31 17:58:11 +02:00
|
|
|
create_addon(comp, name="weblate.cleanup.blank", configuration={})
|
2021-09-02 12:30:05 +02:00
|
|
|
if "weblate.cleanup.generic" not in addon_ids.keys() and not is_wordpress:
|
2021-08-31 17:58:11 +02:00
|
|
|
create_addon(comp, name="weblate.cleanup.generic", configuration={})
|
2021-09-02 12:30:05 +02:00
|
|
|
if "weblate.json.customize" not in addon_ids.keys() and not is_wordpress:
|
2021-08-31 17:58:11 +02:00
|
|
|
create_addon(comp, name="weblate.json.customize", configuration={
|
|
|
|
"sort_keys": True,
|
|
|
|
"indent": 4,
|
|
|
|
"style": "spaces"
|
|
|
|
})
|
2021-09-02 12:30:05 +02:00
|
|
|
if "weblate.git.squash" not in addon_ids.keys() and PROJECT == "matomo":
|
2021-08-30 19:36:25 +02:00
|
|
|
print("add addon")
|
|
|
|
create_addon(comp, name="weblate.git.squash", configuration={
|
|
|
|
"squash": "language",
|
|
|
|
"append_trailers": True,
|
|
|
|
"commit_message": ""
|
|
|
|
})
|
|
|
|
# input("done\n")
|
2021-08-27 20:38:22 +02:00
|
|
|
# lock_component(comp, unlock=True)
|
2021-08-25 12:21:56 +02:00
|
|
|
# print("locked")
|
2021-08-27 20:38:22 +02:00
|
|
|
# exit()
|