Skip to content

Commit

Permalink
fixup! Provide a way of checking if the catalogs are up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
kjagiello committed Jan 28, 2022
1 parent ef2da77 commit 30e120a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
31 changes: 13 additions & 18 deletions babel/messages/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,12 @@ def __eq__(self, other):
def __ne__(self, other):
return self.__cmp__(other) != 0

def is_eq(self, other):
def values_to_compare(obj):
return (
obj.id,
obj.string,
obj.locations,
obj.flags,
obj.auto_comments,
obj.user_comments,
obj.previous_id,
obj.lineno,
obj.context,
)
return values_to_compare(self) == values_to_compare(other)
def is_identical(self, other):
"""Checks whether messages are identical, taking into account all
properties.
"""
assert isinstance(other, Message)
return self.__dict__ == self.__dict__

def clone(self):
return Message(*map(copy, (self.id, self.string, self.locations,
Expand Down Expand Up @@ -856,15 +848,18 @@ def _key_for(self, id, context=None):
key = (key, context)
return key

def is_eq(self, other):
def is_identical(self, other):
"""Checks if catalogs are identical, taking into account messages and
headers.
"""
assert isinstance(other, Catalog)
for key in self._messages.keys() | other._messages.keys():
message_1 = self[key]
message_2 = other[key]
message_1 = self.get(key)
message_2 = other.get(key)
if (
message_1 is None
or message_2 is None
or not message_1.is_eq(message_2)
or not message_1.is_identical(message_2)
):
return False
return dict(self.mime_headers) == dict(other.mime_headers)
2 changes: 1 addition & 1 deletion babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def run(self):
with open(tmpname, "rb") as newfile:
updated_catalog = read_po(newfile)
updated_catalog.revision_date = original_catalog.revision_date
check_status[filename] = updated_catalog.is_eq(original_catalog)
check_status[filename] = updated_catalog.is_identical(original_catalog)
os.remove(tmpname)
continue

Expand Down

0 comments on commit 30e120a

Please sign in to comment.