no_fuzzy_matching: bool = False,
update_header_comment: bool = False,
keep_user_comments: bool = True,
+ update_creation_date: bool = True,
) -> None:
"""Update the catalog based on the given template catalog.
# Make updated catalog's POT-Creation-Date equal to the template
# used to update the catalog
- self.creation_date = template.creation_date
+ if update_creation_date:
+ self.creation_date = template.creation_date
def _to_fuzzy_match_key(self, key: tuple[str, str] | str) -> str:
"""Converts a message key to a string suitable for fuzzy matching."""
'don\'t update the catalog, just return the status. Return code 0 '
'means nothing would change. Return code 1 means that the catalog '
'would be updated'),
+ ('ignore-pot-creation-date=', None,
+ 'ignore changes to POT-Creation-Date when updating or checking'),
]
boolean_options = [
'omit-header', 'no-wrap', 'ignore-obsolete', 'init-missing',
'no-fuzzy-matching', 'previous', 'update-header-comment',
- 'check',
+ 'check', 'ignore-pot-creation-date',
]
def initialize_options(self):
self.update_header_comment = False
self.previous = False
self.check = False
+ self.ignore_pot_creation_date = False
def finalize_options(self):
if not self.input_file:
catalog.update(
template, self.no_fuzzy_matching,
- update_header_comment=self.update_header_comment
+ update_header_comment=self.update_header_comment,
+ update_creation_date=not self.ignore_pot_creation_date,
)
tmpname = os.path.join(os.path.dirname(filename),
localized_catalog.update(template)
assert template.creation_date == localized_catalog.creation_date
+ def test_update_po_ignores_pot_creation_date(self):
+ template = catalog.Catalog()
+ localized_catalog = copy.deepcopy(template)
+ localized_catalog.locale = 'de_DE'
+ assert template.mime_headers != localized_catalog.mime_headers
+ assert template.creation_date == localized_catalog.creation_date
+ template.creation_date = datetime.datetime.now() - \
+ datetime.timedelta(minutes=5)
+ localized_catalog.update(template, update_creation_date=False)
+ assert template.creation_date != localized_catalog.creation_date
+
def test_update_po_keeps_po_revision_date(self):
template = catalog.Catalog()
localized_catalog = copy.deepcopy(template)
import sys
import time
import unittest
-from datetime import datetime
+from datetime import datetime, timedelta
from io import StringIO
import pytest
catalog = read_po(infp)
assert len(catalog) == 4 # Catalog was updated
+ def test_update_pot_creation_date(self):
+ template = Catalog()
+ template.add("1")
+ template.add("2")
+ template.add("3")
+ tmpl_file = os.path.join(i18n_dir, 'temp-template.pot')
+ with open(tmpl_file, "wb") as outfp:
+ write_po(outfp, template)
+ po_file = os.path.join(i18n_dir, 'temp1.po')
+ self.cli.run(sys.argv + ['init',
+ '-l', 'fi',
+ '-o', po_file,
+ '-i', tmpl_file
+ ])
+ with open(po_file) as infp:
+ catalog = read_po(infp)
+ assert len(catalog) == 3
+ original_catalog_creation_date = catalog.creation_date
+
+ # Update the template creation date
+ template.creation_date -= timedelta(minutes=3)
+ with open(tmpl_file, "wb") as outfp:
+ write_po(outfp, template)
+
+ self.cli.run(sys.argv + ['update',
+ '-l', 'fi_FI',
+ '-o', po_file,
+ '-i', tmpl_file])
+
+ with open(po_file) as infp:
+ catalog = read_po(infp)
+ # We didn't ignore the creation date, so expect a diff
+ assert catalog.creation_date != original_catalog_creation_date
+
+ # Reset the "original"
+ original_catalog_creation_date = catalog.creation_date
+
+ # Update the template creation date again
+ # This time, pass the ignore flag and expect the times are different
+ template.creation_date -= timedelta(minutes=5)
+ with open(tmpl_file, "wb") as outfp:
+ write_po(outfp, template)
+
+ self.cli.run(sys.argv + ['update',
+ '-l', 'fi_FI',
+ '-o', po_file,
+ '-i', tmpl_file,
+ '--ignore-pot-creation-date'])
+
+ with open(po_file) as infp:
+ catalog = read_po(infp)
+ # We ignored creation date, so it should not have changed
+ assert catalog.creation_date == original_catalog_creation_date
+
def test_check(self):
template = Catalog()
template.add("1")
'-o', po_file,
'-i', tmpl_file])
+ def test_check_pot_creation_date(self):
+ template = Catalog()
+ template.add("1")
+ template.add("2")
+ template.add("3")
+ tmpl_file = os.path.join(i18n_dir, 'temp-template.pot')
+ with open(tmpl_file, "wb") as outfp:
+ write_po(outfp, template)
+ po_file = os.path.join(i18n_dir, 'temp1.po')
+ self.cli.run(sys.argv + ['init',
+ '-l', 'fi_FI',
+ '-o', po_file,
+ '-i', tmpl_file
+ ])
+
+ # Update the catalog file
+ self.cli.run(sys.argv + ['update',
+ '-l', 'fi_FI',
+ '-o', po_file,
+ '-i', tmpl_file])
+
+ # Run a check without introducing any changes to the template
+ self.cli.run(sys.argv + ['update',
+ '--check',
+ '-l', 'fi_FI',
+ '-o', po_file,
+ '-i', tmpl_file])
+
+ # Run a check after changing the template creation date
+ template.creation_date = datetime.now() - timedelta(minutes=5)
+ with open(tmpl_file, "wb") as outfp:
+ write_po(outfp, template)
+
+ # Should fail without --ignore-pot-creation-date flag
+ with pytest.raises(BaseError):
+ self.cli.run(sys.argv + ['update',
+ '--check',
+ '-l', 'fi_FI',
+ '-o', po_file,
+ '-i', tmpl_file])
+ # Should pass with --ignore-pot-creation-date flag
+ self.cli.run(sys.argv + ['update',
+ '--check',
+ '-l', 'fi_FI',
+ '-o', po_file,
+ '-i', tmpl_file,
+ '--ignore-pot-creation-date'])
+
def test_update_init_missing(self):
template = Catalog()
template.add("1")