def _get_db_for_doc_type(self, doc_type): if doc_type not in self._dbs: couch_db = get_db_by_doc_type(doc_type) if couch_db is None: raise DocumentClassNotFound('No Document class with name "{}" could be found.'.format(doc_type)) callback = LoaderCallback(self.success_counter, self.stdout) db = IterDB(couch_db, new_edits=False, callback=callback) db.__enter__() self._dbs[doc_type] = db return self._dbs[doc_type]
def get_document_class_by_doc_type(doc_type): """ Given the doc_type of a document class, get the class itself. Raises a DocumentClassNotFound if not found """ try: return get_classes_by_doc_type()[doc_type] except KeyError: raise DocumentClassNotFound( 'No Document class with name "{}" could be found.'.format(doc_type))