Commit 4320d833 authored by Michal Čihař's avatar Michal Čihař

Add support for hooking scripts post repository update

This might be useful for automatically rebuilding the translations on
source change.

Fixes #687
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 6a383117
...@@ -405,6 +405,16 @@ information about Piwik see <http://piwik.org/>. ...@@ -405,6 +405,16 @@ information about Piwik see <http://piwik.org/>.
.. seealso:: :setting:`PIWIK_SITE_ID` .. seealso:: :setting:`PIWIK_SITE_ID`
.. setting:: POST_UPDATE_SCRIPTS
POST_UPDATE_SCRIPTS
-------------------
.. versionadded:: 2.3
List of scripts which are allowed as post update scripts. The script needs to be
later enabled in component configuration.
.. setting:: PRE_COMMIT_SCRIPTS .. setting:: PRE_COMMIT_SCRIPTS
PRE_COMMIT_SCRIPTS PRE_COMMIT_SCRIPTS
......
...@@ -122,6 +122,9 @@ Allow translation propagation ...@@ -122,6 +122,9 @@ Allow translation propagation
It's usually good idea to disable this for monolingual translations unless It's usually good idea to disable this for monolingual translations unless
you are using same IDs across whole project. you are using same IDs across whole project.
Post-update script
One of scripts defined in :setting:`POST_UPDATE_SCRIPTS` which is executed
after receiving update. This can be used to update the translation files.
Pre-commit script Pre-commit script
One of scripts defined in :setting:`PRE_COMMIT_SCRIPTS` which is executed One of scripts defined in :setting:`PRE_COMMIT_SCRIPTS` which is executed
before commit. This can be used to generate some metadata about translation before commit. This can be used to generate some metadata about translation
......
...@@ -139,6 +139,10 @@ MACHINE_TRANSLATION_SERVICES = getvalue('MACHINE_TRANSLATION_SERVICES', ( ...@@ -139,6 +139,10 @@ MACHINE_TRANSLATION_SERVICES = getvalue('MACHINE_TRANSLATION_SERVICES', (
MACHINE_TRANSLATION_ENABLED = len(MACHINE_TRANSLATION_SERVICES) > 0 MACHINE_TRANSLATION_ENABLED = len(MACHINE_TRANSLATION_SERVICES) > 0
# List of scripts to use in custom processing # List of scripts to use in custom processing
POST_UPDATE_SCRIPTS = getvalue('POST_UPDATE_SCRIPTS', ())
POST_UPDATE_SCRIPT_CHOICES = [
(script, get_script_name(script)) for script in POST_UPDATE_SCRIPTS
] + [('', '')]
PRE_COMMIT_SCRIPTS = getvalue('PRE_COMMIT_SCRIPTS', ()) PRE_COMMIT_SCRIPTS = getvalue('PRE_COMMIT_SCRIPTS', ())
PRE_COMMIT_SCRIPT_CHOICES = [ PRE_COMMIT_SCRIPT_CHOICES = [
(script, get_script_name(script)) for script in PRE_COMMIT_SCRIPTS (script, get_script_name(script)) for script in PRE_COMMIT_SCRIPTS
......
...@@ -488,6 +488,8 @@ CRISPY_TEMPLATE_PACK = 'bootstrap3' ...@@ -488,6 +488,8 @@ CRISPY_TEMPLATE_PACK = 'bootstrap3'
# ) # )
# List of scripts to use in custom processing # List of scripts to use in custom processing
# POST_UPDATE_SCRIPTS = (
# )
# PRE_COMMIT_SCRIPTS = ( # PRE_COMMIT_SCRIPTS = (
# ) # )
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('trans', '0024_subproject_edit_template'),
]
operations = [
migrations.AddField(
model_name='subproject',
name='post_update_script',
field=models.CharField(default=b'', choices=[(b'', b'')], max_length=200, blank=True, help_text='Script to be executed afrer receiving repository update, please check documentation for more details.', verbose_name='Post-update script'),
preserve_default=True,
),
]
...@@ -44,7 +44,10 @@ from weblate.trans.validators import ( ...@@ -44,7 +44,10 @@ from weblate.trans.validators import (
validate_check_flags, validate_commit_message, validate_check_flags, validate_commit_message,
) )
from weblate.lang.models import Language from weblate.lang.models import Language
from weblate.appsettings import PRE_COMMIT_SCRIPT_CHOICES, HIDE_REPO_CREDENTIALS from weblate.appsettings import (
PRE_COMMIT_SCRIPT_CHOICES, POST_UPDATE_SCRIPT_CHOICES,
HIDE_REPO_CREDENTIALS,
)
from weblate.accounts.models import notify_merge_failure from weblate.accounts.models import notify_merge_failure
from weblate.trans.models.changes import Change from weblate.trans.models.changes import Change
...@@ -211,6 +214,17 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -211,6 +214,17 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'documentation for more details.', 'documentation for more details.',
) )
) )
post_update_script = models.CharField(
verbose_name=ugettext_lazy('Post-update script'),
max_length=200,
default='',
blank=True,
choices=POST_UPDATE_SCRIPT_CHOICES,
help_text=ugettext_lazy(
'Script to be executed afrer receiving repository update, '
'please check documentation for more details.'
),
)
pre_commit_script = models.CharField( pre_commit_script = models.CharField(
verbose_name=ugettext_lazy('Pre-commit script'), verbose_name=ugettext_lazy('Pre-commit script'),
max_length=200, max_length=200,
...@@ -637,6 +651,9 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -637,6 +651,9 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
# update remote branch # update remote branch
ret = self.update_branch(request, method=method) ret = self.update_branch(request, method=method)
# run post update hook
self.run_hook(self.post_update_script)
# create translation objects for all files # create translation objects for all files
self.create_translations(request=request) self.create_translations(request=request)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment