示例#1
0
 def write_toc(self):
     toc = self.toc_view.create_toc()
     toc.toc_title = getattr(self.toc_view, 'toc_title', None)
     commit_toc(current_container(),
                toc,
                lang=self.toc_view.toc_lang,
                uid=self.toc_view.toc_uid)
示例#2
0
文件: toc.py 项目: Xliff/calibre
 def write_toc(self):
     toc = self.toc_view.create_toc()
     toc.toc_title = getattr(self.toc_view, 'toc_title', None)
     commit_toc(
         current_container(),
         toc,
         lang=self.toc_view.toc_lang,
         uid=self.toc_view.toc_uid)
示例#3
0
 def write_toc(self):
     tb = None
     try:
         toc = self.toc_view.create_toc()
         commit_toc(self.ebook, toc, lang=self.toc_view.toc_lang,
                 uid=self.toc_view.toc_uid)
         self.ebook.commit()
     except:
         import traceback
         tb = traceback.format_exc()
     self.writing_done.emit(tb)
示例#4
0
文件: toc.py 项目: siebert/calibre
 def write_toc(self):
     toc = self.toc_view.create_toc()
     commit_toc(current_container(),
                toc,
                lang=self.toc_view.toc_lang,
                uid=self.toc_view.toc_uid)
示例#5
0
文件: toc.py 项目: Gondulf/calibre
 def write_toc(self):
     toc = self.toc_view.create_toc()
     commit_toc(current_container(), toc, lang=self.toc_view.toc_lang,
             uid=self.toc_view.toc_uid)
示例#6
0
def set_metadata_toc(container, language, criteria, changed_files, converter):
    # Returns True if either the metadata or TOC files changed
    # changed_files is updated
    
    opfChanged = False
    tocChanged = False
    # List of dc items in OPF file that get a simple text replacement
    # Add more items to this list if needed
    dc_list = ['//opf:metadata/dc:title',
               '//opf:metadata/dc:description',
               '//opf:metadata/dc:publisher',
               '//opf:metadata/dc:subject'
               '//opf:metadata/dc:contributor',
               '//opf:metadata/dc:coverage',
               '//opf:metadata/dc:rights'];
    # Update the OPF metadata
    # The language and creator fields are special
    # Only update the dc language if the original language was a Chinese type and epub format
    if container.book_type == u'epub':
        items = container.opf_xpath('//opf:metadata/dc:language')
        if len(items) > 0:
            for item in items:
                old_item = item.text
                if re.search('zh-\w+|zh', item.text, flags=re.IGNORECASE) != None:
                    item.text = language
                if item.text != old_item:
                    opfChanged = True
        # Update the creator text and file-as attribute
    items = container.opf_xpath('//opf:metadata/dc:creator')
    if len(items) > 0:
        for item in items:
            old_item = item.text
            if (item.text != None):
                item.text = converter.convert(item.text)
                if item.text != old_item:
                    opfChanged = True
            for attribute in item.attrib: # update file-as attribute
                item.attrib[attribute] = converter.convert(item.attrib[attribute])
    # Update the remaining dc items using a loop
    for dc_item in dc_list:
        items = container.opf_xpath(dc_item)
        if len(items) > 0:
            for item in items:
                old_item = item.text
                if (item.text != None):
                    item.text = converter.convert(item.text)
                    if item.text != old_item:
                        opfChanged = True

    # Update the TOC - Do this after modifying the OPF data
    # Just grab all <text> fields (AKA "title" attribute in a TOC object)
    # and convert to the desired Chinese. Let Calibre set the title and
    # language automatically from the OPF file modified earlier
    book_toc = get_toc(container)
    for item in book_toc.iterdescendants():
        if(item.title != None):
            old_title = item.title
            item.title = converter.convert(item.title)
            if old_title != item.title:
                tocChanged = True

    # Update the files with the changes
    if tocChanged:
        commit_toc(container, book_toc)
        container.dirty(book_toc.toc_file_name)
        changed_files.append(book_toc.toc_file_name)
    if opfChanged:
        container.dirty(container.opf_name)
        changed_files.append(container.opf_name)
    return(tocChanged or opfChanged)