'Detect author_sort mismatches.
Sort by author, look for inconsistencies in author_sort among
similarly-named authors. Fatal for MOBI generation, a mere
annoyance for EPUB.
Inputs:
books_by_author (list): list of books to test, possibly unsorted
Output:
(none)
Exceptions:
AuthorSortMismatchException: author_sort mismatch detected'

def detect_author_sort_mismatches(self, books_to_test):

    books_by_author = sorted(list(books_to_test), key=self._kf_books_by_author_sorter_author)
    authors = [(record['author'], record['author_sort']) for record in books_by_author]
    current_author = authors[0]
    for (i, author) in enumerate(authors):
        if ((author != current_author) and i):
            if (author[0] == current_author[0]):
                if (self.opts.fmt == 'mobi'):
                    error_msg = _((((('<p>Inconsistent    author    sort    values    for    author<br/>' + "'{!s}':</p>".format(author[0])) + '<p><center><b>{!s}</b>    !=    <b>{!s}</b></center></p>'.format(author[1], current_author[1])) + '<p>Unable    to    build    MOBI    catalog.<br/>') + "Select    all    books    by    '{!s}',    apply    correct    Author    Sort    value    in    Edit    Metadata    dialog,    then    rebuild    the    catalog.\n<p>".format(author[0])))
                    self.opts.log.warn('\n***    Metadata    error    ***')
                    self.opts.log.warn(error_msg)
                    self.error.append('Author    sort    mismatch')
                    self.error.append(error_msg)
                    raise AuthorSortMismatchException('author_sort    mismatch    while    building    MOBI')
                else:
                    if (not self.error):
                        self.error.append('Author    sort    mismatch')
                    error_msg = _(("Warning:    Inconsistent    Author    Sort    values    for    Author    '{!s}':\n".format(author[0]) + '    {!s}    !=    {!s}\n'.format(author[1], current_author[1])))
                    self.opts.log.warn('\n***    Metadata    warning    ***')
                    self.opts.log.warn(error_msg)
                    self.error.append(error_msg)
                    continue
            current_author = author
