def books(self, oncard=None, end_session=True):
        """
        Return a list of ebooks on the device.

        :param oncard:  If 'carda' or 'cardb' return a list of ebooks on the
                        specific storage card, otherwise return list of ebooks
                        in main memory of device. If a card is specified and no
                        books are on the card return empty list.

        :return: A BookList.

        """
        logger.debug(sys._getframe().f_code.co_name)
        card_id = self._convert_oncard_to_cardid(oncard)
        storage_type = self.qt_settings.get(card_id,{}).get('storage_type',None)
        if (storage_type is not None) and (storage_type != 'quietthyme'):
            qt_booklist = ApiClient().books(storage_type)['data']
        else:
            qt_booklist = []

        booklist = BookList(None, None, None)
        for qt_metadata in qt_booklist:
            if qt_metadata['storage_identifier']:
                logger.debug(qt_metadata)
                booklist.add_book(Book.from_quietthyme_metadata(qt_metadata), False)
        return booklist
예제 #2
0
    def add_books_to_metadata(self, dest_info, metadata, booklists):
        '''
        Add locations to the booklists. This function must not communicate with
        the device.

        :param dest_info: Result of a call to L{upload_books}
        :param metadata: List of :class:`Metadata` objects, same as for
                         :meth:`upload_books`.
        :param booklists: A tuple containing the result of calls to
                          (:meth:`books(oncard=None)`,
                          :meth:`books(oncard='carda')`,
                          :meth`books(oncard='cardb')`).

        '''
        logger.debug(sys._getframe().f_code.co_name)
        logger.debug('USBMS: adding metadata for %d books' % (len(metadata)))

        metadata = iter(metadata)
        for i, location in enumerate(dest_info):
            self.report_progress(
                (i + 1) / float(len(dest_info)),
                _('Adding books to device metadata listing...'))
            local_metadata = metadata.next()
            blist = 2 if location[0] == 'B' else 1 if location[0] == 'A' else 0

            try:
                book = Book.from_quietthyme_metadata(location[1])
            except StandardError, e:

                logger.debug(
                    'An error occured while adding book via QT data, using calibre data'
                )
                logger.debug(str(e))
                import traceback
                logger.debug(traceback.format_exc())
                book = Book.from_calibre_metadata(local_metadata)

            b = booklists[blist].add_book(book, replace_metadata=True)
            if b:
                b._new_book = True
    def add_books_to_metadata(self, dest_info, metadata, booklists):
        '''
        Add locations to the booklists. This function must not communicate with
        the device.

        :param dest_info: Result of a call to L{upload_books}
        :param metadata: List of :class:`Metadata` objects, same as for
                         :meth:`upload_books`.
        :param booklists: A tuple containing the result of calls to
                          (:meth:`books(oncard=None)`,
                          :meth:`books(oncard='carda')`,
                          :meth`books(oncard='cardb')`).

        '''
        logger.debug(sys._getframe().f_code.co_name)
        logger.debug('USBMS: adding metadata for %d books'%(len(metadata)))

        metadata = iter(metadata)
        for i, location in enumerate(dest_info):
            self.report_progress((i+1) / float(len(dest_info)), _('Adding books to device metadata listing...'))
            local_metadata = metadata.next()
            blist = 2 if location[0] == 'B' else 1 if location[0] == 'A' else 0

            try:
                book = Book.from_quietthyme_metadata(location[1]['data'])
            except StandardError, e:

                logger.debug('An error occured while adding book via QT data, using calibre data')
                logger.debug(str(e))
                import traceback
                logger.debug(traceback.format_exc())
                book = Book.from_calibre_metadata(local_metadata)

            b = booklists[blist].add_book(book, replace_metadata=True)
            if b:
                b._new_book = True
예제 #4
0
    def books(self, oncard=None, end_session=True):
        """
        Return a list of ebooks on the device.

        :param oncard:  If 'carda' or 'cardb' return a list of ebooks on the
                        specific storage card, otherwise return list of ebooks
                        in main memory of device. If a card is specified and no
                        books are on the card return empty list.

        :return: A BookList.

        """
        logger.debug(sys._getframe().f_code.co_name)
        card_id = self._convert_oncard_to_cardid(oncard)
        storage_type = self.qt_settings.get(card_id,
                                            {}).get('storage_type', "")
        storage_id = self.qt_settings.get(card_id, {}).get('storage_id', None)
        if storage_id is not None:
            qt_response = ApiClient().books_all(storage_id)['data']
            qt_booklist = qt_response['Items']
        else:
            qt_booklist = []

        booklist = BookList(None, None, None)

        placeholderBook = Book()
        placeholderBook.title = "## {0} books ##".format(
            storage_type.capitalize())
        placeholderBook.authors = ['QuietThyme']
        placeholderBook.comments = "All Books in this list are actually stored on {0} cloud storage".format(
            storage_type.capitalize())

        placeholderBook.size = 0
        placeholderBook.thumbnail = get_resources(
            "images/{0}.png".format(storage_type))
        placeholderBook.tags = [storage_type]
        placeholderBook.identifiers = {}
        placeholderBook.path = "placeholder.ignore"

        booklist.add_book(placeholderBook, False)

        for i, qt_metadata in enumerate(qt_booklist):
            self.report_progress((i + 1) / float(len(qt_booklist)),
                                 _('Loading books from device...'))
            if qt_metadata['storage_identifier']:
                #logger.debug(qt_metadata)
                booklist.add_book(Book.from_quietthyme_metadata(qt_metadata),
                                  False)
        self.report_progress(1.0, _('Loaded book from device'))
        return booklist