示例#1
0
 def check_iso639(self, raw, path):
     from calibre.utils.localization import langnames_to_langcodes
     rmap = {}
     msgid = None
     has_errors = False
     if isinstance(raw, bytes):
         raw = raw.decode('utf-8')
     for match in re.finditer(r'^(msgid|msgstr)\s+"(.*?)"', raw, re.M):
         if match.group(1) == 'msgid':
             msgid = match.group(2)
         else:
             msgstr = match.group(2)
             if not msgstr:
                 continue
             omsgid = rmap.get(msgstr, None)
             if omsgid is not None:
                 cm = langnames_to_langcodes([omsgid, msgid])
                 if cm[msgid] and cm[omsgid] and cm[msgid] != cm[omsgid]:
                     has_errors = True
                     self.iso639_errors.append(
                         'In file %s the name %s is used as translation for both %s and %s'
                         % (os.path.basename(path), msgstr, msgid,
                            rmap[msgstr]))
                 # raise SystemExit(1)
             rmap[msgstr] = msgid
     return not has_errors
示例#2
0
def add_item_specific_entries(menu, data, book_info):
    search_internet_added = False
    find_action = book_info.find_in_tag_browser_action
    dt = data['type']
    if dt == 'format':
        add_format_entries(menu, data, book_info)
    elif dt == 'author':
        author = data['name']
        if data['url'] != 'calibre':
            ac = book_info.copy_link_action
            ac.current_url = data['url']
            ac.setText(_('&Copy author link'))
            menu.addAction(ac)
        menu.addAction(init_manage_action(book_info.manage_action, 'authors', author))
        init_find_in_tag_browser(menu, find_action, 'authors', author)
        if hasattr(book_info, 'search_internet'):
            menu.sia = sia = create_search_internet_menu(book_info.search_internet, author)
            menu.addMenu(sia)
            search_internet_added = True
        if hasattr(book_info, 'search_requested'):
            menu.addAction(_('Search calibre for %s') % author,
                            lambda : book_info.search_requested('authors:"={}"'.format(author.replace('"', r'\"'))))
    elif dt in ('path', 'devpath'):
        from calibre.gui2.ui import get_gui
        path = data['loc']
        ac = book_info.copy_link_action
        if isinstance(path, int):
            path = get_gui().library_view.model().db.abspath(path, index_is_id=True)
        ac.current_url = path
        ac.setText(_('Copy path'))
        menu.addAction(ac)
    else:
        field = data.get('field')
        if field is not None:
            book_id = int(data['book_id'])
            value = remove_value = data['value']
            if field == 'identifiers':
                ac = book_info.copy_link_action
                ac.current_url = value
                ac.setText(_('&Copy identifier'))
                menu.addAction(ac)
                remove_value = data['id_type']
                init_find_in_tag_browser(menu, find_action, field, remove_value)
                menu.addAction(book_info.edit_identifiers_action)
            elif field in ('tags', 'series', 'publisher') or is_category(field):
                init_find_in_tag_browser(menu, find_action, field, value)
                menu.addAction(init_manage_action(book_info.manage_action, field, value))
            elif field == 'languages':
                remove_value = langnames_to_langcodes((value,)).get(value, 'Unknown')
                init_find_in_tag_browser(menu, find_action, field, value)
            ac = book_info.remove_item_action
            ac.data = (field, remove_value, book_id)
            ac.setText(_('Remove %s from this book') % escape_for_menu(value))
            menu.addAction(ac)
    return search_internet_added
示例#3
0
 def check_iso639(self, path):
     from calibre.utils.localization import langnames_to_langcodes
     with open(path, 'rb') as f:
         raw = f.read()
     rmap = {}
     msgid = None
     for match in re.finditer(r'^(msgid|msgstr)\s+"(.*?)"', raw, re.M):
         if match.group(1) == 'msgid':
             msgid = match.group(2)
         else:
             msgstr = match.group(2)
             if not msgstr:
                 continue
             omsgid = rmap.get(msgstr, None)
             if omsgid is not None:
                 cm = langnames_to_langcodes([omsgid, msgid])
                 if cm[msgid] and cm[omsgid] and cm[msgid] != cm[omsgid]:
                     self.iso639_errors.append('In file %s the name %s is used as translation for both %s and %s' % (
                         os.path.basename(path), msgstr, msgid, rmap[msgstr]))
                 # raise SystemExit(1)
             rmap[msgstr] = msgid
示例#4
0
 def check_iso639(self, path):
     from calibre.utils.localization import langnames_to_langcodes
     with open(path, 'rb') as f:
         raw = f.read()
     rmap = {}
     msgid = None
     for match in re.finditer(r'^(msgid|msgstr)\s+"(.*?)"', raw, re.M):
         if match.group(1) == 'msgid':
             msgid = match.group(2)
         else:
             msgstr = match.group(2)
             if not msgstr:
                 continue
             omsgid = rmap.get(msgstr, None)
             if omsgid is not None:
                 cm = langnames_to_langcodes([omsgid, msgid])
                 if cm[msgid] and cm[omsgid] and cm[msgid] != cm[omsgid]:
                     self.iso639_errors.append(
                         'In file %s the name %s is used as translation for both %s and %s'
                         % (os.path.basename(path), msgstr, msgid,
                            rmap[msgstr]))
                 # raise SystemExit(1)
             rmap[msgstr] = msgid
示例#5
0
 def check_iso639(self, raw, path):
     from calibre.utils.localization import langnames_to_langcodes
     rmap = {}
     msgid = None
     has_errors = False
     if isinstance(raw, bytes):
         raw = raw.decode('utf-8')
     for match in re.finditer(r'^(msgid|msgstr)\s+"(.*?)"', raw, re.M):
         if match.group(1) == 'msgid':
             msgid = match.group(2)
         else:
             msgstr = match.group(2)
             if not msgstr:
                 continue
             omsgid = rmap.get(msgstr, None)
             if omsgid is not None:
                 cm = langnames_to_langcodes([omsgid, msgid])
                 if cm[msgid] and cm[omsgid] and cm[msgid] != cm[omsgid]:
                     has_errors = True
                     self.iso639_errors.append('In file %s the name %s is used as translation for both %s and %s' % (
                         os.path.basename(path), msgstr, msgid, rmap[msgstr]))
                 # raise SystemExit(1)
             rmap[msgstr] = msgid
     return not has_errors
示例#6
0
def add_item_specific_entries(menu, data, book_info, copy_menu, search_menu):
    from calibre.gui2.ui import get_gui
    search_internet_added = False
    find_action = book_info.find_in_tag_browser_action
    dt = data['type']

    def add_copy_action(name):
        copy_menu.addAction(QIcon(I('edit-copy.png')), _('The text: {}').format(name), lambda: QApplication.instance().clipboard().setText(name))

    if dt == 'format':
        add_format_entries(menu, data, book_info, copy_menu, search_menu)
    elif dt == 'author':
        author = data['name']
        if data['url'] != 'calibre':
            ac = book_info.copy_link_action
            ac.current_url = data['url']
            ac.setText(_('&Author link'))
            copy_menu.addAction(ac)
        add_copy_action(author)
        init_find_in_tag_browser(search_menu, find_action, 'authors', author)
        init_find_in_grouped_search(search_menu, 'authors', author, book_info)
        menu.addAction(init_manage_action(book_info.manage_action, 'authors', author))
        if hasattr(book_info, 'search_internet'):
            search_menu.addSeparator()
            search_menu.sim = create_search_internet_menu(book_info.search_internet, author)
            for ac in search_menu.sim.actions():
                search_menu.addAction(ac)
                ac.setText(_('Search {0} for {1}').format(ac.text(), author))
            search_internet_added = True
        if hasattr(book_info, 'remove_item_action'):
            ac = book_info.remove_item_action
            book_id = get_gui().library_view.current_id
            ac.data = ('authors', author, book_id)
            ac.setText(_('Remove %s from this book') % escape_for_menu(author))
            menu.addAction(ac)
    elif dt in ('path', 'devpath'):
        path = data['loc']
        ac = book_info.copy_link_action
        if isinstance(path, int):
            path = get_gui().library_view.model().db.abspath(path, index_is_id=True)
        ac.current_url = path
        ac.setText(_('The location of the book'))
        copy_menu.addAction(ac)
    else:
        field = data.get('field')
        if field is not None:
            book_id = int(data['book_id'])
            value = remove_value = data['value']
            if field == 'identifiers':
                ac = book_info.copy_link_action
                ac.current_url = value
                ac.setText(_('&Identifier'))
                copy_menu.addAction(ac)
                if data.get('url'):
                    book_info.copy_identifiers_url_action.current_url = data['url']
                    copy_menu.addAction(book_info.copy_identifiers_url_action)
                remove_value = data['id_type']
                init_find_in_tag_browser(search_menu, find_action, field, remove_value)
                init_find_in_grouped_search(search_menu, field, remove_value, book_info)
                menu.addAction(book_info.edit_identifiers_action)
            elif field in ('tags', 'series', 'publisher') or is_category(field):
                add_copy_action(value)
                init_find_in_tag_browser(search_menu, find_action, field, value)
                init_find_in_grouped_search(search_menu, field, value, book_info)
                menu.addAction(init_manage_action(book_info.manage_action, field, value))
            elif field == 'languages':
                remove_value = langnames_to_langcodes((value,)).get(value, 'Unknown')
                init_find_in_tag_browser(search_menu, find_action, field, value)
                init_find_in_grouped_search(search_menu, field, value, book_info)
            ac = book_info.remove_item_action
            ac.data = (field, remove_value, book_id)
            ac.setText(_('Remove %s from this book') % escape_for_menu(value))
            menu.addAction(ac)
    return search_internet_added