2016-10-24 18:32:09 +02:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
import ijson
|
|
|
|
from django.core.management.base import BaseCommand, CommandParser
|
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2016-10-24 18:32:09 +02:00
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """
|
2021-03-19 11:27:42 +01:00
|
|
|
Compare rendered messages from files.
|
|
|
|
Usage: ./manage.py compare_messages <dump1> <dump2>
|
2016-10-24 18:32:09 +02:00
|
|
|
"""
|
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("dump1", help="First file to compare")
|
|
|
|
parser.add_argument("dump2", help="Second file to compare")
|
2016-10-24 18:32:09 +02:00
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2016-10-24 18:32:09 +02:00
|
|
|
total_count = 0
|
|
|
|
changed_count = 0
|
2021-02-12 08:20:45 +01:00
|
|
|
with open(options["dump1"]) as dump1, open(options["dump2"]) as dump2:
|
|
|
|
for m1, m2 in zip(ijson.items(dump1, "item"), ijson.items(dump2, "item")):
|
2016-10-24 18:32:09 +02:00
|
|
|
total_count += 1
|
2021-02-12 08:20:45 +01:00
|
|
|
if m1["id"] != m2["id"]:
|
|
|
|
self.stderr.write("Inconsistent messages dump")
|
2016-10-24 18:32:09 +02:00
|
|
|
break
|
2021-02-12 08:20:45 +01:00
|
|
|
if m1["content"] != m2["content"]:
|
2016-10-24 18:32:09 +02:00
|
|
|
changed_count += 1
|
2021-02-12 08:20:45 +01:00
|
|
|
self.stdout.write("Changed message id: {id}".format(id=m1["id"]))
|
|
|
|
self.stdout.write(f"Total messages: {total_count}")
|
|
|
|
self.stdout.write(f"Changed messages: {changed_count}")
|