From eaabc5fb7886ceba673994fbf2e63d8d4213a3b6 Mon Sep 17 00:00:00 2001 From: Aris Katsikaridis Date: Tue, 24 Feb 2026 14:33:42 +0200 Subject: [PATCH] Implement command to force source update --- tests/native/core/test_core.py | 4 ++-- tests/native/django/test_commands/__init__.py | 1 + transifex/native/cds.py | 6 +++++- transifex/native/core.py | 7 +++++-- transifex/native/django/management/utils/push.py | 7 ++++++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/native/core/test_core.py b/tests/native/core/test_core.py index fb31a7e..050698a 100644 --- a/tests/native/core/test_core.py +++ b/tests/native/core/test_core.py @@ -380,8 +380,8 @@ def test_push_strings_reaches_cds_handler( strings = [SourceString('a'), SourceString('b')] mytx = self._get_tx() - mytx.push_source_strings(strings, False, True, True, True) - mock_push_strings.assert_called_once_with(strings, False, True, True, True) + mytx.push_source_strings(strings, False, True, True, True, False) + mock_push_strings.assert_called_once_with(strings, False, True, True, True, False) @patch('transifex.native.core.MemoryCache.update') @patch('transifex.native.core.CDSHandler.fetch_translations') diff --git a/tests/native/django/test_commands/__init__.py b/tests/native/django/test_commands/__init__.py index 26bdb31..deba1e8 100644 --- a/tests/native/django/test_commands/__init__.py +++ b/tests/native/django/test_commands/__init__.py @@ -34,6 +34,7 @@ def get_transifex_command(): 'override_occurrences', 'do_not_keep_translations', 'symlinks', + 'force_source_update', # Invalidate 'purge', diff --git a/transifex/native/cds.py b/transifex/native/cds.py index 03cb514..ca26cdb 100644 --- a/transifex/native/cds.py +++ b/transifex/native/cds.py @@ -205,7 +205,8 @@ def fetch_translations(self, language_code=None): def push_source_strings(self, strings, purge=False, do_not_keep_translations=False, override_tags=False, - override_occurrences=False): + override_occurrences=False, + force_source_update=False): """Push source strings to CDS. :param list(SourceString) strings: a list of `SourceString` objects @@ -219,6 +220,8 @@ def push_source_strings(self, strings, purge=False, False appends them to existing tags. :param bool override_occurrences: True replaces all the occurrences of pushed strings. False appends them to existing occurrences. + :param bool force_source_update: True forces the update of the source strings. + False lets the normal revision logic handle the update. :return: the HTTP response object :rtype: requests.Response """ @@ -242,6 +245,7 @@ def push_source_strings(self, strings, purge=False, 'keep_translations': not do_not_keep_translations, 'override_tags': override_tags, 'override_occurrences': override_occurrences, + 'force_source_update': force_source_update, }, } ) diff --git a/transifex/native/core.py b/transifex/native/core.py index 3e431b9..7902e8c 100644 --- a/transifex/native/core.py +++ b/transifex/native/core.py @@ -199,7 +199,8 @@ def fetch_translations(self): def push_source_strings(self, strings, purge=False, do_not_keep_translations=False, override_tags=False, - override_occurrences=False): + override_occurrences=False, + force_source_update=False): """Push the given source strings to the CDS. :param list strings: a list of SourceString objects @@ -212,13 +213,15 @@ def push_source_strings(self, strings, purge=False, False appends them to existing tags. :param bool override_occurrences: True replaces all the occurrences of pushed strings. False appends them to existing occurrences. + :param bool force_source_update: True forces the update of the source strings. + False lets the normal revision logic handle the update. :return: a tuple containing the status code and the content of the response :rtype: tuple """ self._check_initialization() response = self._cds_handler.push_source_strings( - strings, purge, do_not_keep_translations, override_tags, override_occurrences) + strings, purge, do_not_keep_translations, override_tags, override_occurrences, force_source_update) return response.status_code, json.loads(response.content) def get_push_status(self, job_path): diff --git a/transifex/native/django/management/utils/push.py b/transifex/native/django/management/utils/push.py index 2bf2356..7ab1107 100644 --- a/transifex/native/django/management/utils/push.py +++ b/transifex/native/django/management/utils/push.py @@ -92,6 +92,10 @@ def add_arguments(self, subparsers): choices=['source', 'hash'], help=('Use "hash" or "source" based keys (default: source)'), ) + parser.add_argument( + '--force-source-update', action='store_true', dest='force_source_update', default=False, + help=('Force the update of the source strings'), + ) def handle(self, *args, **options): self.verbose_output = options['verbose_output'] @@ -108,6 +112,7 @@ def handle(self, *args, **options): self.do_not_keep_translations = options['do_not_keep_translations'] self.no_wait = options['no_wait'] self.key_generator = options['key_generator'] + self.force_source_update = options['force_source_update'] extensions = options['extensions'] if self.domain == 'djangojs': exts = extensions if extensions else ['js'] @@ -200,7 +205,7 @@ def push_strings(self): status_code, response_content = tx.push_source_strings( self.string_collection.strings.values(), self.purge, self.do_not_keep_translations, self.override_tags, - self.override_occurrences + self.override_occurrences, self.force_source_update ) if self.no_wait: