def _get_app_list(excluded_apps): """ :return: OrderedDict(app_config, model), ...) """ app_list = OrderedDict() for label in APP_LABELS_WITH_FILTER_KWARGS_TO_DUMP: app_label, model_label = label.split('.') try: app_config = apps.get_app_config(app_label) except LookupError: raise DomainDumpError("Unknown application: %s" % app_label) if app_config in excluded_apps: continue try: model = app_config.get_model(model_label) except LookupError: raise DomainDumpError("Unknown model: %s.%s" % (app_label, model_label)) app_list_value = app_list.setdefault(app_config, []) if model not in app_list_value: app_list_value.append(model) return app_list
def get_excluded_apps_and_models(excludes): """ :param excludes: list of app labels ("app_label.model_name" or "app_label") to exclude :return: Tuple containing two sets: Set of AppConfigs to exclude, Set of model classes to excluded. """ excluded_apps = set() excluded_models = set() for exclude in excludes: if '.' in exclude: try: model = apps.get_model(exclude) except LookupError: raise DomainDumpError('Unknown model in excludes: %s' % exclude) excluded_models.add(model) else: try: app_config = apps.get_app_config(exclude) except LookupError: from corehq.util.couch import get_document_class_by_doc_type from corehq.util.exceptions import DocumentClassNotFound # ignore this if it's a couch doc type try: get_document_class_by_doc_type(exclude) except DocumentClassNotFound: raise DomainDumpError('Unknown app in excludes: %s' % exclude) excluded_apps.add(app_config) return excluded_apps, excluded_models
def get_apps_and_models(app_or_model_label): """ :param app_or_model_label: list of app labels ("app_label.model_name" or "app_label") :return: Tuple containing two sets: Set of AppConfigs, Set of model classes """ specified_apps = set() specified_models = set() for label in app_or_model_label: if '.' in label: try: model = apps.get_model(label) except LookupError: raise DomainDumpError('Unknown model: %s' % label) specified_models.add(model) else: try: app_config = apps.get_app_config(label) except LookupError: from corehq.util.couch import get_document_class_by_doc_type from corehq.util.exceptions import DocumentClassNotFound # ignore this if it's a couch doc type try: get_document_class_by_doc_type(label) except DocumentClassNotFound: raise DomainDumpError('Unknown app in excludes: %s' % label) specified_apps.add(app_config) return specified_apps, specified_models
def _get_model(model_label): app_label, model_label = model_label.split('.') try: app_config = apps.get_app_config(app_label) except LookupError: raise DomainDumpError("Unknown application: %s" % app_label) try: model = app_config.get_model(model_label) except LookupError: raise DomainDumpError("Unknown model: %s.%s" % (app_label, model_label)) return app_config, model
def get_all_model_iterators_builders_for_domain(model_class, domain, builders, limit_to_db=None): if settings.USE_PARTITIONED_DATABASE and hasattr(model_class, 'partition_attr'): using = plproxy_config.form_processing_dbs else: using = [router.db_for_read(model_class)] if limit_to_db: if limit_to_db not in using: raise DomainDumpError('DB specified is not valide for ' 'model class: {} not in {}'.format( limit_to_db, using)) using = [limit_to_db] for db_alias in using: if model_class._meta.proxy: continue master_db = settings.DATABASES[db_alias].get('STANDBY', {}).get('MASTER') if not router.allow_migrate_model(master_db or db_alias, model_class): continue for builder in builders: yield model_class, builder.build(domain, model_class, db_alias)
def dump(self, output_stream): from corehq.apps.domain.models import Domain domain_obj = Domain.get_by_name(self.domain, strict=True) if not domain_obj: raise DomainDumpError("Domain not found: {}".format(self.domain)) json.dump(domain_obj.to_json(), output_stream) output_stream.write('\n') self.stdout.write('Dumping {} Domain\n'.format(1)) return Counter({'Domain': 1})
def get_excluded_apps_and_models(excludes): """ :param excludes: list of app labels ("app_label.model_name" or "app_label") to exclude :return: Tuple containing two sets: Set of AppConfigs to exclude, Set of model classes to excluded. """ excluded_apps = set() excluded_models = set() for exclude in excludes: if '.' in exclude: try: model = apps.get_model(exclude) except LookupError: raise DomainDumpError('Unknown model in excludes: %s' % exclude) excluded_models.add(model) else: try: app_config = apps.get_app_config(exclude) except LookupError: raise DomainDumpError('Unknown app in excludes: %s' % exclude) excluded_apps.add(app_config) return excluded_apps, excluded_models
def get_all_model_iterators_builders_for_domain(model_class, domain, limit_to_db=None): if settings.USE_PARTITIONED_DATABASE and hasattr(model_class, 'partition_attr'): using = plproxy_config.form_processing_dbs else: using = [router.db_for_read(model_class)] if limit_to_db: if limit_to_db not in using: raise DomainDumpError('DB specified is not valide for ' 'model class: {} not in {}'.format(limit_to_db, using)) using = [limit_to_db] for db_alias in using: if not model_class._meta.proxy and router.allow_migrate_model(db_alias, model_class): iterator_builders = APP_LABELS_WITH_FILTER_KWARGS_TO_DUMP[get_model_label(model_class)] for builder in iterator_builders: yield model_class, builder.build(domain, model_class, db_alias)