Skip to content

Commit eaabc5f

Browse files
committed
Implement command to force source update
1 parent dbd2ca3 commit eaabc5f

5 files changed

Lines changed: 19 additions & 6 deletions

File tree

tests/native/core/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ def test_push_strings_reaches_cds_handler(
380380

381381
strings = [SourceString('a'), SourceString('b')]
382382
mytx = self._get_tx()
383-
mytx.push_source_strings(strings, False, True, True, True)
384-
mock_push_strings.assert_called_once_with(strings, False, True, True, True)
383+
mytx.push_source_strings(strings, False, True, True, True, False)
384+
mock_push_strings.assert_called_once_with(strings, False, True, True, True, False)
385385

386386
@patch('transifex.native.core.MemoryCache.update')
387387
@patch('transifex.native.core.CDSHandler.fetch_translations')

tests/native/django/test_commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def get_transifex_command():
3434
'override_occurrences',
3535
'do_not_keep_translations',
3636
'symlinks',
37+
'force_source_update',
3738

3839
# Invalidate
3940
'purge',

transifex/native/cds.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def fetch_translations(self, language_code=None):
205205
def push_source_strings(self, strings, purge=False,
206206
do_not_keep_translations=False,
207207
override_tags=False,
208-
override_occurrences=False):
208+
override_occurrences=False,
209+
force_source_update=False):
209210
"""Push source strings to CDS.
210211
211212
:param list(SourceString) strings: a list of `SourceString` objects
@@ -219,6 +220,8 @@ def push_source_strings(self, strings, purge=False,
219220
False appends them to existing tags.
220221
:param bool override_occurrences: True replaces all the occurrences of pushed strings.
221222
False appends them to existing occurrences.
223+
:param bool force_source_update: True forces the update of the source strings.
224+
False lets the normal revision logic handle the update.
222225
:return: the HTTP response object
223226
:rtype: requests.Response
224227
"""
@@ -242,6 +245,7 @@ def push_source_strings(self, strings, purge=False,
242245
'keep_translations': not do_not_keep_translations,
243246
'override_tags': override_tags,
244247
'override_occurrences': override_occurrences,
248+
'force_source_update': force_source_update,
245249
},
246250
}
247251
)

transifex/native/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ def fetch_translations(self):
199199
def push_source_strings(self, strings, purge=False,
200200
do_not_keep_translations=False,
201201
override_tags=False,
202-
override_occurrences=False):
202+
override_occurrences=False,
203+
force_source_update=False):
203204
"""Push the given source strings to the CDS.
204205
205206
:param list strings: a list of SourceString objects
@@ -212,13 +213,15 @@ def push_source_strings(self, strings, purge=False,
212213
False appends them to existing tags.
213214
:param bool override_occurrences: True replaces all the occurrences of pushed strings.
214215
False appends them to existing occurrences.
216+
:param bool force_source_update: True forces the update of the source strings.
217+
False lets the normal revision logic handle the update.
215218
:return: a tuple containing the status code and the content of the
216219
response
217220
:rtype: tuple
218221
"""
219222
self._check_initialization()
220223
response = self._cds_handler.push_source_strings(
221-
strings, purge, do_not_keep_translations, override_tags, override_occurrences)
224+
strings, purge, do_not_keep_translations, override_tags, override_occurrences, force_source_update)
222225
return response.status_code, json.loads(response.content)
223226

224227
def get_push_status(self, job_path):

transifex/native/django/management/utils/push.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def add_arguments(self, subparsers):
9292
choices=['source', 'hash'],
9393
help=('Use "hash" or "source" based keys (default: source)'),
9494
)
95+
parser.add_argument(
96+
'--force-source-update', action='store_true', dest='force_source_update', default=False,
97+
help=('Force the update of the source strings'),
98+
)
9599

96100
def handle(self, *args, **options):
97101
self.verbose_output = options['verbose_output']
@@ -108,6 +112,7 @@ def handle(self, *args, **options):
108112
self.do_not_keep_translations = options['do_not_keep_translations']
109113
self.no_wait = options['no_wait']
110114
self.key_generator = options['key_generator']
115+
self.force_source_update = options['force_source_update']
111116
extensions = options['extensions']
112117
if self.domain == 'djangojs':
113118
exts = extensions if extensions else ['js']
@@ -200,7 +205,7 @@ def push_strings(self):
200205
status_code, response_content = tx.push_source_strings(
201206
self.string_collection.strings.values(), self.purge,
202207
self.do_not_keep_translations, self.override_tags,
203-
self.override_occurrences
208+
self.override_occurrences, self.force_source_update
204209
)
205210

206211
if self.no_wait:

0 commit comments

Comments
 (0)