def handle(self, domain, **options): domain = options.get('domain') case_ids = options.get('case_id') db = options.get('db') if case_ids: form_ids = set() for case in CaseAccessorSQL.get_cases(case_ids): assert not domain or case.domain == domain, 'Case "%s" not in domain "%s"' % ( case.case_id, domain) form_ids.update(case.xform_ids) check_and_process_forms(form_ids) else: if domain: domains = [domain] else: domains = iter_domains() for domain in domains: print(u"Checking domain: %s" % domain) form_ids_to_check = set() dbs = [db] if db else get_db_aliases_for_partitioned_query() for dbname in dbs: form_ids_to_check.update( XFormInstanceSQL.objects.using(dbname).filter( domain=domain, state=XFormInstanceSQL.DEPRECATED).values_list( 'orig_id', flat=True)) print(' Found %s forms to check' % len(form_ids_to_check)) for chunk in chunked(form_ids_to_check, 500): check_and_process_forms(chunk)
def get_all_case_ids_by_domain(start, end): all_case_ids_by_domain = {} for domain in iter_domains(): print('Pulling cases for {}'.format(domain)) all_case_ids_by_domain[domain] = use_json_cache_file( filename='all_case_ids_last_modified_{}_to_{}__{}.json'.format(start, end, domain), fn=lambda: get_all_case_ids_for_domain(domain, start, end) ) return all_case_ids_by_domain
def generate_all_form_ids_by_domain(start, end): form_ids_by_domain = { domain: get_form_ids_by_type(domain, 'XFormInstance', start, end) for domain in iter_domains() } return { domain: form_ids for domain, form_ids in form_ids_by_domain.items() if form_ids }
def get_all_case_ids_by_domain(start, end): all_case_ids_by_domain = {} for domain in iter_domains(): print('Pulling cases for {}'.format(domain)) all_case_ids_by_domain[domain] = use_json_cache_file( filename='all_case_ids_last_modified_{}_to_{}__{}.json'.format(start, end, domain), fn=lambda: get_all_case_ids_for_domain(domain, start, end) ) return all_case_ids_by_domain
def generate_all_form_ids_by_domain(start, end): form_ids_by_domain = { domain: get_form_ids_by_type(domain, 'XFormInstance', start, end) for domain in iter_domains() } return { domain: form_ids for domain, form_ids in form_ids_by_domain.items() if form_ids }
def handle(self, domain, **options): domain = options.get('domain') case_ids = options.get('case_id') db = options.get('db') self.log_filename = 'undo_uuid_clash.{}.log'.format( datetime.utcnow().isoformat()) print('\nWriting output to log file: {}\n'.format(self.log_filename)) if case_ids: form_ids = set() for case in CaseAccessorSQL.get_cases(case_ids): assert not domain or case.domain == domain, 'Case "%s" not in domain "%s"' % ( case.case_id, domain) form_ids.update(case.xform_ids) with self: check_and_process_forms(form_ids, self) else: if domain: domains = [domain] else: domains = iter_domains() for domain in domains: print(u"Checking domain: %s" % domain) form_ids_to_check = set() dbs = [db] if db else get_db_aliases_for_partitioned_query() for dbname in dbs: form_ids_to_check.update( XFormInstanceSQL.objects.using(dbname).filter( domain=domain, state=XFormInstanceSQL.DEPRECATED).values_list( 'orig_id', flat=True)) print(' Found %s forms to check' % len(form_ids_to_check)) with self: for chunk in chunked(form_ids_to_check, 500): check_and_process_forms(chunk, self) def __enter__(self): self._log_file = open(self.log_filename, 'w') def __exit__(self, exc_type, exc_val, exc_tb): self._log_file.close() def log(message): self._log_file.write(message)
def handle(self, domain, **options): debug = options.get('debug') domain = options.get('domain') case_ids = options.get('case_id') db = options.get('db') self.log_filename = 'undo_uuid_clash.{}.log'.format(datetime.utcnow().isoformat()) print('\nWriting output to log file: {}\n'.format(self.log_filename)) if case_ids: form_ids = set() for case in CaseAccessorSQL.get_cases(case_ids): assert not domain or case.domain == domain, 'Case "%s" not in domain "%s"' % (case.case_id, domain) form_ids.update(case.xform_ids) with self: check_and_process_forms(form_ids, self, debug) else: if domain: domains = [domain] else: domains = iter_domains() for domain in domains: print("Checking domain: %s" % domain) form_ids_to_check = set() dbs = [db] if db else get_db_aliases_for_partitioned_query() for dbname in dbs: form_ids_to_check.update( XFormInstanceSQL.objects.using(dbname) .filter(domain=domain, state=XFormInstanceSQL.DEPRECATED) .values_list('orig_id', flat=True) ) print(' Found %s forms to check' % len(form_ids_to_check)) with self: for chunk in chunked(form_ids_to_check, 500): check_and_process_forms(chunk, self, debug)