Ejemplo n.º 1
0
 def unaffiliated_collection(cls, _db):
     """Find a special metadata-wrangler-specific Collection whose catalog
     contains identifiers that came in through anonymous lookup.
     """
     return Collection.by_name_and_protocol(
         _db, "Unaffiliated Identifiers", DataSource.INTERNAL_PROCESSING
     )
Ejemplo n.º 2
0
 def create_overdrive_api(self, overdrive_api_class):
     collection, is_new = Collection.by_name_and_protocol(
         self._db, self.DEFAULT_OVERDRIVE_COLLECTION_NAME,
         ExternalIntegration.OVERDRIVE)
     if is_new:
         raise ValueError(
             'Default Overdrive collection has not been configured.')
     return overdrive_api_class(self._db, collection)
Ejemplo n.º 3
0
    def __init__(self, _db, collection=None, *args, **kwargs):
        self.responses = []
        self.requests = []

        library = DatabaseTest.make_default_library(_db)
        collection, ignore = Collection.by_name_and_protocol(
            _db, name="Test Enki Collection", protocol=EnkiAPI.ENKI)
        collection.protocol = EnkiAPI.ENKI
        collection.external_account_id = u'c'
        library.collections.append(collection)
        super(MockEnkiAPI, self).__init__(_db, collection, *args, **kwargs)
Ejemplo n.º 4
0
    def __init__(self, _db, collection=None, *args, **kwargs):
        self.responses = []
        self.requests = []

        library = DatabaseTest.make_default_library(_db)
        if not collection:
            collection, ignore = Collection.by_name_and_protocol(
                _db, name="Test Enki Collection", protocol=EnkiAPI.ENKI
            )
            collection.protocol = EnkiAPI.ENKI
        if collection not in library.collections:
            library.collections.append(collection)

        # Set the "Enki library ID" variable between the default library
        # and this Enki collection.
        ConfigurationSetting.for_library_and_externalintegration(
            _db, self.ENKI_LIBRARY_ID_KEY, library, collection.external_integration
        ).value = "c"

        super(MockEnkiAPI, self).__init__(_db, collection, *args, **kwargs)
Ejemplo n.º 5
0
    def _get_lcp_collection(self, patron, collection_name):
        """Returns an LCP collection for a specified library
        NOTE: We assume that there is only ONE LCP collection per library

        :param patron: Patron object
        :type patron: core.model.patron.Patron

        :param collection_name: Name of the collection
        :type collection_name: string

        :return: LCP collection
        :rtype: core.model.collection.Collection
        """
        db = Session.object_session(patron)
        lcp_collection, _ = Collection.by_name_and_protocol(
            db, collection_name, ExternalIntegration.LCP)

        if not lcp_collection or lcp_collection not in patron.library.collections:
            return MISSING_COLLECTION

        return lcp_collection
Ejemplo n.º 6
0
    def __init__(self, _db, collection=None, *args, **kwargs):
        self.responses = []
        self.requests = []

        library = DatabaseTest.make_default_library(_db)
        if not collection:
            collection, ignore = Collection.by_name_and_protocol(
                _db, name="Test Enki Collection", protocol=EnkiAPI.ENKI
            )
            collection.protocol=EnkiAPI.ENKI
        if collection not in library.collections:
            library.collections.append(collection)

        # Set the "Enki library ID" variable between the default library
        # and this Enki collection.
        ConfigurationSetting.for_library_and_externalintegration(
            _db, self.ENKI_LIBRARY_ID_KEY, library,
            collection.external_integration
        ).value = 'c'

        super(MockEnkiAPI, self).__init__(
            _db, collection, *args, **kwargs
        )
    # Create Collections generated by OPDS import with importer classes.
    opds_importers = {
        FeedbooksOPDSImporter : DataSource.FEEDBOOKS,
        UnglueItImporter : DataSource.UNGLUE_IT,
    }
    for importer_class, data_source_name in opds_importers.items():
        OPDSImportScript(importer_class, data_source_name, _db=_db)

    # Create a StandardEbooks Collection.
    OPDSImportScript(object(), DataSource.STANDARD_EBOOKS, _db=_db,
        collection_data=dict(url=u'https://standardebooks.org/opds/all'))

    # Create a Gutenberg Collection.
    gutenberg, is_new = Collection.by_name_and_protocol(
        _db, DataSource.GUTENBERG, ExternalIntegration.GUTENBERG
    )
    if not gutenberg.data_source:
        gutenberg.external_integration.set_setting(
            Collection.DATA_SOURCE_NAME_SETTING, DataSource.GUTENBERG
        )
    if is_new:
        library = Library.default(_db)
        gutenberg.libraries.append(library)
        logging.info('CREATED Collection for %s: %r' % (
            DataSource.GUTENBERG, gutenberg))

    _db.commit()

    # Alright, all the Collections have been created. Let's update the
    # LicensePools now.
Ejemplo n.º 8
0
 def unaffiliated_collection(cls, _db):
     """Find a special metadata-wrangler-specific Collection whose catalog
     contains identifiers that came in through anonymous lookup.
     """
     return Collection.by_name_and_protocol(_db, "Unaffiliated Identifiers",
                                            DataSource.INTERNAL_PROCESSING)