Commit 4a4280dd authored by Michal Čihař's avatar Michal Čihař

Add command to commit pending changes after some delay (issue #182)

parent 77c25521
......@@ -302,6 +302,9 @@ fulfilled:
* translation for a language is completed
* explicit commit is requested
You can also additionally set a cron job to commit pending changes after some
delay, see :djadmin:`commit_pending`.
.. _fulltext:
Fulltext search
......
......@@ -25,6 +25,23 @@ Commits any possible pending changes to backend git repository.
You can either define which project or subproject to update (eg.
``weblate/master``) or use ``--all`` to update all existing subprojects.
commit_pending <project|project/subproject>
-------------------------------------------
.. django-admin:: commit_pending
Commits pending changes older than given age (using ``--age`` parameter,
defaults to 24 hours).
You can either define which project or subproject to update (eg.
``weblate/master``) or use ``--all`` to update all existing subprojects.
This is most useful if executed periodically from cron or similar tool:
.. code-block:: sh
./manage.py commit_pending --all --age=48
cleanuptrans
------------
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://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 <http://www.gnu.org/licenses/>.
#
from weblate.trans.management.commands import WeblateCommand
from django.utils import timezone
from datetime import timedelta
from optparse import make_option
class Command(WeblateCommand):
help = 'commits pending changes older than given age'
option_list = WeblateCommand.option_list + (
make_option('--age',
action='store',
type='int',
dest='age',
default=24,
help='Age of changes to commit in hours (default is 24 hours)'
),
make_option('--lang',
action='store',
type='string',
dest='lang',
default=None,
help='Limit only to given languages (comma separated list)'
),
)
def handle(self, *args, **options):
age = timezone.now() - timedelta(hours=options['age'])
langs = None
if options['lang'] is not None:
langs = options['lang'].split(',')
for subproject in self.get_subprojects(*args, **options):
if langs is None:
translations = subproject.translation_set.all()
else:
translations = subproject.translation_set.filter(
language_code__in = langs
)
for translation in translations:
if not translation.git_needs_commit():
continue
last_change = translation.get_last_change()
if last_change > age:
continue
print 'Committing %s' % translation
translation.commit_pending()
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