2016-10-24 18:32:09 +02:00
|
|
|
from typing import Any
|
|
|
|
from six.moves import zip
|
|
|
|
|
|
|
|
import ijson
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand, CommandParser
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
"""
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
# type: (CommandParser) -> None
|
|
|
|
parser.add_argument('dump1', help='First file to compare')
|
|
|
|
parser.add_argument('dump2', help='Second file to compare')
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
# type: (*Any, **Any) -> None
|
|
|
|
total_count = 0
|
|
|
|
changed_count = 0
|
|
|
|
with open(options['dump1'], 'r') as dump1, open(options['dump2'], 'r') as dump2:
|
|
|
|
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']))
|
|
|
|
self.stdout.write('Total messages: {count}'.format(count=total_count))
|
|
|
|
self.stdout.write('Changed messages: {count}'.format(count=changed_count))
|