from django.core.management.base import BaseCommand
from proso_common.models import get_integrity_checks
from django.conf import settings
from optparse import make_option
import logging
import random
import json
import sys


LOGGER = logging.getLogger('proso.internal')


class Command(BaseCommand):
    help = "Perform integrity checks"
    option_list = BaseCommand.option_list + (
        make_option(
            '--seed',
            type=int,
            default=None
        ),
    )

    def handle(self, *args, **options):
        if options['seed'] is None:
            seed = random.randint(1, 10 ** 10)
        else:
            seed = options['seed']
        failed = {}
        for integrity_check in get_integrity_checks():
            random.seed(seed)
            integrity_check.set_seed(seed)
            result = integrity_check.check()
            if result is not None:
                failed[str(integrity_check.__class__)] = result
                print('FAILED:', integrity_check.__class__)
            else:
                print('PASSED:', integrity_check.__class__)
        if len(failed) > 0:
            dest_file = '{}/integrity_check_{}.txt'.format(settings.DATA_DIR, seed)
            print('REPORT:', dest_file)
            with open(dest_file, 'w') as f:
                f.write(json.dumps({'failed_checks': failed}, sort_keys=True, indent=4))
            message = 'The integrity check failed, seed: {}'.format(seed)
            LOGGER.error(message)
            sys.exit(message)

@@ -912,11 +912,19 @@
 led%5B
-str
+_check_name
 (int
@@ -935,26 +935,16 @@
 ty_check
-.__class__
 )%5D = res
@@ -976,24 +976,36 @@
 ('FAILED:', 
+_check_name(
 integrity_ch
@@ -1003,34 +1003,25 @@
 egrity_check
-.__class__
+)
 )%0A          
@@ -1061,16 +1061,28 @@
 SSED:', 
+_check_name(
 integrit
@@ -1092,18 +1092,9 @@
 heck
-.__class__
+)
 )%0A  
@@ -1506,16 +1506,152 @@
 s.exit(message)%0A
+%0A%0Adef _check_name(integrity_check):%0A    return '%7B%7D.%7B%7D'.format(integrity_check.__class__.__module__, integrity_check.__class__.__name__)%0A

fix name of integrity check