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 = """
|
|
|
|
Render messages to a file.
|
2016-11-22 01:44:16 +01:00
|
|
|
Usage: ./manage.py render_messages <destination> <--amount>
|
2016-10-24 18:32:09 +02:00
|
|
|
"""
|
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
2016-10-24 18:32:09 +02:00
|
|
|
parser.add_argument('dump1', help='First file to compare')
|
|
|
|
parser.add_argument('dump2', help='Second file to compare')
|
|
|
|
|
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
|
2020-04-09 21:51:58 +02:00
|
|
|
with open(options['dump1']) as dump1, open(options['dump2']) as dump2:
|
2016-10-24 18:32:09 +02:00
|
|
|
for m1, m2 in zip(ijson.items(dump1, 'item'), ijson.items(dump2, 'item')):
|
|
|
|
total_count += 1
|
|
|
|
if m1['id'] != m2['id']:
|
|
|
|
self.stderr.write('Inconsistent messages dump')
|
|
|
|
break
|
|
|
|
if m1['content'] != m2['content']:
|
|
|
|
changed_count += 1
|
|
|
|
self.stdout.write('Changed message id: {id}'.format(id=m1['id']))
|
2020-06-09 00:25:09 +02:00
|
|
|
self.stdout.write(f'Total messages: {total_count}')
|
|
|
|
self.stdout.write(f'Changed messages: {changed_count}')
|