示例#1
0
    def _fetch_remote_availability(self, identifiers):
        """Retrieve availability information for the specified identifiers.

        :yield: A stream of (Metadata, CirculationData) 2-tuples.
        """
        identifier_strings = self.create_identifier_strings(identifiers)
        response = self.availability(title_ids=identifier_strings)
        parser = BibliographicParser(self.collection)
        return parser.process_all(response.content)
示例#2
0
    def update_licensepools_for_identifiers(self, identifiers):
        """Update availability information for a list of books.

        If the book has never been seen before, a new LicensePool
        will be created for the book.

        The book's LicensePool will be updated with current
        circulation information.
        """
        identifier_strings = self.create_identifier_strings(identifiers)
        response = self.availability(title_ids=identifier_strings)
        collection = self.collection
        parser = BibliographicParser(collection)
        remainder = set(identifiers)
        for bibliographic, availability in parser.process_all(
                response.content):
            identifier, is_new = bibliographic.primary_identifier.load(
                self._db)
            if identifier in remainder:
                remainder.remove(identifier)
            pool, is_new = availability.license_pool(self._db, collection)
            availability.apply(self._db, pool.collection)

        # We asked Axis about n books. It sent us n-k responses. Those
        # k books are the identifiers in `remainder`. These books have
        # been removed from the collection without us being notified.
        for removed_identifier in remainder:
            pool = identifier.licensed_through_collection(self.collection)
            if not pool:
                self.log.warn(
                    "Was about to reap %r but no local license pool in this collection.",
                    removed_identifier)
                continue
            if pool.licenses_owned == 0:
                # Already reaped.
                continue
            self.log.info("Reaping %r", removed_identifier)

            availability = CirculationData(
                data_source=pool.data_source,
                primary_identifier=removed_identifier,
                licenses_owned=0,
                licenses_available=0,
                licenses_reserved=0,
                patrons_in_hold_queue=0,
            )
            availability.apply(pool,
                               ReplacementPolicy.from_license_source(self._db))
示例#3
0
文件: axis.py 项目: dguo/circulation
    def update_licensepools_for_identifiers(self, identifiers):
        """Update availability information for a list of books.

        If the book has never been seen before, a new LicensePool
        will be created for the book.

        The book's LicensePool will be updated with current
        circulation information.
        """
        identifier_strings = self.create_identifier_strings(identifiers)
        response = self.availability(title_ids=identifier_strings)
        parser = BibliographicParser()
        remainder = set(identifiers)
        for bibliographic, availability in parser.process_all(response.content):
            identifier, is_new = bibliographic.primary_identifier.load(self._db)
            if identifier in remainder:
                remainder.remove(identifier)
            pool, is_new = availability.license_pool(self._db)
            availability.apply(pool)

        # We asked Axis about n books. It sent us n-k responses. Those
        # k books are the identifiers in `remainder`. These books have
        # been removed from the collection without us being notified.
        for removed_identifier in remainder:
            pool = removed_identifier.licensed_through
            if not pool:
                self.log.warn(
                    "Was about to reap %r but no local license pool.",
                    removed_identifier
                )
                continue
            if pool.licenses_owned == 0:
                # Already reaped.
                continue
            self.log.info(
                "Reaping %r", removed_identifier
            )

            availability = CirculationData(
                data_source=pool.data_source,
                primary_identifier=removed_identifier,
                licenses_owned=0,
                licenses_available=0,
                licenses_reserved=0,
                patrons_in_hold_queue=0,
            )
            availability.apply(pool, False)