'Add locations to the booklists. This function must not communicate with
the device.
@param locations: Result of a call to L{upload_books}
@param metadata: List of MetaInformation objects, same as for
:method:`upload_books`.
@param booklists: A tuple containing the result of calls to
(L{books}(oncard=None), L{books}(oncard=\'carda\'),
L{books}(oncard=\'cardb\')).'

def add_books_to_metadata(self, locations, metadata, booklists):

    if self.verbose:
        logger().info(('%s.add_books_to_metadata()' % self.__class__.__name__))
    task_count = float(len(self.update_list))
    if self.update_list:
        if (False and self.verbose):
            self._dump_booklist(booklists[0], header='before', indent=2)
            self._dump_update_list(header='before', indent=2)
            self._dump_cached_books(header='before', indent=2)
        for (j, p_book) in enumerate(self.update_list):
            if (False and self.verbose):
                if isosx:
                    logger().info(("        looking    for    '%s'    by    %s    uuid:%s" % (p_book['title'], p_book['author'], p_book['uuid'])))
                elif iswindows:
                    logger().info(("    looking    for    '%s'    by    %s    (%s)" % (p_book['title'], p_book['author'], p_book['uuid'])))
            for (i, bl_book) in enumerate(booklists[0]):
                if (bl_book.uuid == p_book['uuid']):
                    booklists[0].pop(i)
                    if False:
                        if isosx:
                            logger().info(('        removing    old    %s    %s    from    booklists[0]' % (p_book['title'], str(p_book['lib_book'])[(-9):])))
                        elif iswindows:
                            logger().info(("    removing    old    '%s'    from    booklists[0]" % p_book['title']))
                    matching_uuids = 0
                    for cb in self.cached_books:
                        if (self.cached_books[cb]['uuid'] == p_book['uuid']):
                            matching_uuids += 1
                    if (matching_uuids > 1):
                        for cb in self.cached_books:
                            if (self.cached_books[cb]['uuid'] == p_book['uuid']):
                                if ((self.cached_books[cb]['title'] == p_book['title']) and (self.cached_books[cb]['author'] == p_book['author'])):
                                    if self.verbose:
                                        self._dump_cached_book(self.cached_books[cb], header='removing    from    self.cached_books:', indent=2)
                                    self.cached_books.pop(cb)
                                    break
                        break
            if (self.report_progress is not None):
                self.report_progress(((j + 1) / task_count), _('Updating    device    metadata    listing...'))
        if (self.report_progress is not None):
            self.report_progress(1.0, _('Updating    device    metadata    listing...'))
    for new_book in locations[0]:
        if self.verbose:
            logger().info(("        adding    '%s'    by    '%s'    to    booklists[0]" % (new_book.title, new_book.author)))
        booklists[0].append(new_book)
    if False:
        self._dump_booklist(booklists[0], header='after', indent=2)
        self._dump_cached_books(header='after', indent=2)
