<commit_before>import uuid
import re
from collections import defaultdict
from datetime import datetime
from itertools import chain

from couchdbkit import ResourceNotFound

from corehq.apps.app_manager.dbaccessors import get_app
from corehq.apps.app_manager.exceptions import FormNotFoundException
from corehq.apps.app_manager.models import Application
from corehq.apps.app_manager.util import get_correct_app_class
from corehq.apps.app_manager.xform import XForm, parse_xml
from corehq.apps.es import FormES
from corehq.apps.es.filters import NOT, doc_type
from corehq.util.couch import IterDB
from corehq.util.log import with_progress_bar
from corehq.util.quickcache import quickcache
from couchforms.const import ATTACHMENT_NAME
from couchforms.models import XFormInstance
from dimagi.utils.couch.database import iter_docs
from django.core.management.base import BaseCommand
from optparse import make_option


ONE_HOUR = 60 * 60


def xmlns_map_log_message(xmlns, unique_id):
    return "Using xmlns {} for form id {}\n".format(xmlns, unique_id)


def unique_ids_map_log_message(app_id, domain, form_unique_id):
    return "app_to_unique_ids_map[({}, {})].add({})\n".format(
        app_id, domain, form_unique_id
    )


class Command(BaseCommand):
    help = 'Fix forms with "undefined" xmlns'
    args = '<prev_log_path> <log_path>'

    option_list = (
        make_option(
            '--dry-run',
            action='store_true',
            dest='dry_run',
            default=False,
            help="Don't do the actual modifications, but still log what would be affected"
        ),
    )

    def handle(self, *args, **options):

        dry_run = options.get("dry_run", True)
        prev_log_path = args[0].strip()
        log_path = args[1].strip()

        unique_id_to_xmlns_map = {}
        app_to_unique_ids_map = defaultdict(set)<commit_msg>update fix_forms_and_apps_with_missing_xmlns.py for django 1.10<commit_after>import uuid
import re
from collections import defaultdict
from datetime import datetime
from itertools import chain

from couchdbkit import ResourceNotFound

from corehq.apps.app_manager.dbaccessors import get_app
from corehq.apps.app_manager.exceptions import FormNotFoundException
from corehq.apps.app_manager.models import Application
from corehq.apps.app_manager.util import get_correct_app_class
from corehq.apps.app_manager.xform import XForm, parse_xml
from corehq.apps.es import FormES
from corehq.apps.es.filters import NOT, doc_type
from corehq.util.couch import IterDB
from corehq.util.log import with_progress_bar
from corehq.util.quickcache import quickcache
from couchforms.const import ATTACHMENT_NAME
from couchforms.models import XFormInstance
from dimagi.utils.couch.database import iter_docs
from django.core.management.base import BaseCommand
from optparse import make_option


ONE_HOUR = 60 * 60


def xmlns_map_log_message(xmlns, unique_id):
    return "Using xmlns {} for form id {}\n".format(xmlns, unique_id)


def unique_ids_map_log_message(app_id, domain, form_unique_id):
    return "app_to_unique_ids_map[({}, {})].add({})\n".format(
        app_id, domain, form_unique_id
    )


class Command(BaseCommand):
    help = 'Fix forms with "undefined" xmlns'
    args = '<prev_log_path> <log_path>'

    option_list = (
        make_option(
            '--dry-run',
            action='store_true',
            dest='dry_run',
            default=False,
            help="Don't do the actual modifications, but still log what would be affected"
        ),
    )

    def add_arguments(self, parser):
        parser.add_argument('prev_log_path')
        parser.add_argument('log_path')

    def handle(self, prev_log_path, log_path, **options):

        dry_run = options.get("dry_run", True)
        prev_log_path = prev_log_path.strip()
        log_path = log_path.strip()

        unique_id_to_xmlns_map = {}
        app_to_unique_ids_map = defaultdict(set)
{'fraction_non_alphanumeric': 0.0835881753312946, 'fraction_numerical': 0.003312945973496432, 'mean_word_length': 3.943324937027708, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 15}, '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': '2280219', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1210, 'n_words': 307}