diff --git a/bin/cron.py b/bin/cron.py index f2014608a1..e59e0250e7 100755 --- a/bin/cron.py +++ b/bin/cron.py @@ -118,6 +118,8 @@ def schedule_database_jobs(): def schedule_file_jobs(): + call_command('l10n_update --clean') + @scheduled_job('interval', minutes=DB_UPDATE_MINUTES) def update_locales(): call_command('l10n_update') diff --git a/lib/l10n_utils/management/commands/l10n_update.py b/lib/l10n_utils/management/commands/l10n_update.py index 206bafe1f5..24e50a073f 100644 --- a/lib/l10n_utils/management/commands/l10n_update.py +++ b/lib/l10n_utils/management/commands/l10n_update.py @@ -2,6 +2,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from io import StringIO +from shutil import rmtree from django.core.management.base import BaseCommand from django.conf import settings @@ -15,20 +16,30 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('-q', '--quiet', action='store_true', dest='quiet', default=False, help='If no error occurs, swallow all output.'), + parser.add_argument('-c', '--clean', action='store_true', dest='clean', default=False, + help='Remove old repos if they exist and do fresh clones.'), def handle(self, *args, **options): if options['quiet']: self.stdout._out = StringIO() - self.update_lang_files() - self.update_fluent_files() + self.update_lang_files(options['clean']) + self.update_fluent_files(options['clean']) - def update_lang_files(self): + def update_lang_files(self, clean=False): repo = GitRepo(settings.LOCALES_PATH, settings.LOCALES_REPO) + if clean: + rmtree(repo.path_str, ignore_errors=True) + self.stdout.write('Removed old .lang repo') + repo.update() self.stdout.write('Updated .lang files') - def update_fluent_files(self): + def update_fluent_files(self, clean=False): repo = GitRepo(settings.FLUENT_REPO_PATH, settings.FLUENT_REPO_URL) + if clean: + rmtree(repo.path_str, ignore_errors=True) + self.stdout.write('Removed old .ftl repo') + repo.update() self.stdout.write('Updated .ftl files')