<commit_before>from django.core.management.base import BaseCommand, CommandError
from casexml.apps.case.cleanup import rebuild_case
from corehq.apps.hqcase.utils import get_case_ids_in_domain


class Command(BaseCommand):
    args = '<domain>'
    help = ('Reprocesses all cases in a domain.')

    def handle(self, *args, **options):
        if len(args) == 1:
            domain = args[0]
        else:
            raise CommandError('Usage: %s\n%s' % (self.args, self.help))

        ids = get_case_ids_in_domain(domain)
        for count, case_id in enumerate(ids):
            rebuild_case(case_id)
            if count % 100 == 0:
                print 'rebuilt %s/%s cases' % (count, len(ids))
<commit_msg>trap exceptions in management command<commit_after>import logging
from django.core.management.base import BaseCommand, CommandError
from casexml.apps.case.cleanup import rebuild_case
from corehq.apps.hqcase.utils import get_case_ids_in_domain


class Command(BaseCommand):
    args = '<domain>'
    help = ('Reprocesses all cases in a domain.')

    def handle(self, *args, **options):
        if len(args) == 1:
            domain = args[0]
        else:
            raise CommandError('Usage: %s\n%s' % (self.args, self.help))

        ids = get_case_ids_in_domain(domain)
        for count, case_id in enumerate(ids):
            try:
                rebuild_case(case_id)
                if count % 100 == 0:
                    print 'rebuilt %s/%s cases' % (count, len(ids))
            except Exception, e:
                logging.exception("couldn't rebuild case {id}. {msg}".format(id=case_id, msg=str(e)))

{'fraction_non_alphanumeric': 0.1141804788213628, 'fraction_numerical': 0.007366482504604052, 'mean_word_length': 2.574561403508772, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368927', 'n_tokens_mistral': 519, 'n_tokens_neox': 491, 'n_words': 130}