mirror of
https://gh.llkk.cc/https://github.com/WeblateOrg/hosted.git
synced 2026-03-06 15:16:20 +08:00
82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
#
|
|
# Copyright © Michal Čihař <michal@weblate.org>
|
|
#
|
|
# This file is part of Weblate <https://weblate.org/>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
#
|
|
"""Custom addons for Hosted Weblate."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
from weblate.addons.events import AddonEvent
|
|
from weblate.addons.scripts import BaseAddon, BaseScriptAddon
|
|
|
|
if TYPE_CHECKING:
|
|
from weblate.trans.models import Component, Project
|
|
|
|
|
|
class UnknownHorizonsTemplateAddon(BaseScriptAddon):
|
|
# Event used to trigger the script
|
|
events = {AddonEvent.EVENT_PRE_COMMIT}
|
|
# Name of the addon, has to be unique
|
|
name = "weblate.hosted.uh_scenario"
|
|
# Verbose name and long description
|
|
verbose = _("Generate Unknown Horizons scenario data")
|
|
description = _("Generate Unknown Horizons scenario data")
|
|
|
|
# Script to execute
|
|
script = "/home/weblate/data/bin/translate_scenario.py"
|
|
# File to add in commit (for pre commit event)
|
|
# does not have to be set
|
|
add_file = "content/scenarios/*_{{ language_code }}.yaml"
|
|
|
|
@classmethod
|
|
def can_install(
|
|
cls,
|
|
*,
|
|
component: Component | None = None,
|
|
project: Project | None = None,
|
|
) -> bool:
|
|
"""Only useful for Unknown Horizons project."""
|
|
if component is None or component.project.slug != "uh":
|
|
return False
|
|
return super().can_install(component=component, project=project)
|
|
|
|
|
|
class ResetAddon(BaseAddon):
|
|
# Event used to trigger the script
|
|
events = {AddonEvent.EVENT_DAILY}
|
|
# Name of the addon, has to be unique
|
|
name = "weblate.hosted.reset"
|
|
# Verbose name and long description
|
|
verbose = _("Reset repository to upstream")
|
|
description = _("Discards all changes in the Weblate repository each night.")
|
|
repo_scope = True
|
|
|
|
@classmethod
|
|
def can_install(
|
|
cls,
|
|
*,
|
|
component: Component | None = None,
|
|
project: Project | None = None,
|
|
) -> bool:
|
|
# Only instalable on the sandbox project
|
|
return component is not None and component.project.slug == "sandbox"
|
|
|
|
def daily(self, component: Component, activity_log_id: int | None = None) -> None:
|
|
component.do_reset()
|