Exemple #1
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