当前位置: 首页>>代码示例>>Python>>正文


Python OPFCreator.create_spine方法代码示例

本文整理汇总了Python中calibre.ebooks.metadata.opf2.OPFCreator.create_spine方法的典型用法代码示例。如果您正苦于以下问题:Python OPFCreator.create_spine方法的具体用法?Python OPFCreator.create_spine怎么用?Python OPFCreator.create_spine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在calibre.ebooks.metadata.opf2.OPFCreator的用法示例。


在下文中一共展示了OPFCreator.create_spine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write(self, doc):
        toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map, self.log)
        raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
        with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
            f.write(raw)
        css = self.styles.generate_css(self.dest_dir, self.docx)
        if css:
            with open(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
                f.write(css.encode('utf-8'))

        opf = OPFCreator(self.dest_dir, self.mi)
        opf.toc = toc
        opf.create_manifest_from_files_in([self.dest_dir])
        for item in opf.manifest:
            if item.media_type == 'text/html':
                item.media_type = guess_type('a.xhtml')[0]
        opf.create_spine(['index.html'])
        if self.cover_image is not None:
            opf.guide.set_cover(self.cover_image)
        toc_file = os.path.join(self.dest_dir, 'toc.ncx')
        with open(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(toc_file, 'wb') as ncx:
            opf.render(of, ncx, 'toc.ncx')
        if os.path.getsize(toc_file) == 0:
            os.remove(toc_file)
        return os.path.join(self.dest_dir, 'metadata.opf')
开发者ID:AtulKumar2,项目名称:calibre,代码行数:27,代码来源:to_html.py

示例2: write

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write(self, doc):
        toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map, self.log, self.namespace)
        raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
        with lopen(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
            f.write(raw)
        css = self.styles.generate_css(self.dest_dir, self.docx, self.notes_nopb, self.nosupsub)
        if css:
            with lopen(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
                f.write(css.encode('utf-8'))

        opf = OPFCreator(self.dest_dir, self.mi)
        opf.toc = toc
        opf.create_manifest_from_files_in([self.dest_dir])
        for item in opf.manifest:
            if item.media_type == 'text/html':
                item.media_type = guess_type('a.xhtml')[0]
        opf.create_spine(['index.html'])
        if self.cover_image is not None:
            opf.guide.set_cover(self.cover_image)

        def process_guide(E, guide):
            if self.toc_anchor is not None:
                guide.append(E.reference(
                    href='index.html#' + self.toc_anchor, title=_('Table of Contents'), type='toc'))
        toc_file = os.path.join(self.dest_dir, 'toc.ncx')
        with lopen(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(toc_file, 'wb') as ncx:
            opf.render(of, ncx, 'toc.ncx', process_guide=process_guide)
        if os.path.getsize(toc_file) == 0:
            os.remove(toc_file)
        return os.path.join(self.dest_dir, 'metadata.opf')
开发者ID:miurahr,项目名称:calibre,代码行数:32,代码来源:to_html.py

示例3: convert

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def convert(self, stream, options, file_ext, log,
                accelerators):
        from calibre.ebooks.metadata.opf2 import OPFCreator
        from calibre.ebooks.pdf.pdftohtml import pdftohtml

        log.debug('Converting file to html...')
        # The main html file will be named index.html
        self.opts, self.log = options, log
        if options.new_pdf_engine:
            return self.convert_new(stream, accelerators)
        pdftohtml(os.getcwdu(), stream.name, options.no_images)

        from calibre.ebooks.metadata.meta import get_metadata
        log.debug('Retrieving document metadata...')
        mi = get_metadata(stream, 'pdf')
        opf = OPFCreator(os.getcwdu(), mi)

        manifest = [(u'index.html', None)]

        images = os.listdir(os.getcwdu())
        images.remove('index.html')
        for i in images:
            manifest.append((i, None))
        log.debug('Generating manifest...')
        opf.create_manifest(manifest)

        opf.create_spine([u'index.html'])
        log.debug('Rendering manifest...')
        with open(u'metadata.opf', 'wb') as opffile:
            opf.render(opffile)

        return os.path.join(os.getcwdu(), u'metadata.opf')
开发者ID:089git,项目名称:calibre,代码行数:34,代码来源:pdf_input.py

示例4: write_opf

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write_opf(self, guide, toc, spine, resource_map):
        mi = self.header.exth.mi
        if (self.cover_offset is not None and self.cover_offset <
                len(resource_map)):
            mi.cover = resource_map[self.cover_offset]

        if len(list(toc)) < 2:
            self.log.warn('KF8 has no metadata Table of Contents')

            for ref in guide:
                if ref.type == 'toc':
                    href = ref.href()
                    href, frag = urldefrag(href)
                    if os.path.exists(href.replace('/', os.sep)):
                        try:
                            toc = self.read_inline_toc(href, frag)
                        except:
                            self.log.exception('Failed to read inline ToC')

        opf = OPFCreator(os.getcwdu(), mi)
        opf.guide = guide

        def exclude(path):
            return os.path.basename(path) == 'debug-raw.html'

        opf.create_manifest_from_files_in([os.getcwdu()], exclude=exclude)
        opf.create_spine(spine)
        opf.set_toc(toc)

        with open('metadata.opf', 'wb') as of, open('toc.ncx', 'wb') as ncx:
            opf.render(of, ncx, 'toc.ncx')
        return 'metadata.opf'
开发者ID:Eksmo,项目名称:calibre,代码行数:34,代码来源:mobi8.py

示例5: convert

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def convert(self, stream, options, file_ext, log,
                accelerators):
        from calibre.ebooks.metadata.toc import TOC
        from calibre.ebooks.metadata.opf2 import OPFCreator
        from calibre.utils.zipfile import ZipFile

        self.options = options
        self.log = log
        pages, images = [], []
        toc = TOC()

        if file_ext == 'pmlz':
            log.debug('De-compressing content to temporary directory...')
            with TemporaryDirectory('_unpmlz') as tdir:
                zf = ZipFile(stream)
                zf.extractall(tdir)

                pmls = glob.glob(os.path.join(tdir, '*.pml'))
                for pml in pmls:
                    html_name = os.path.splitext(os.path.basename(pml))[0]+'.html'
                    html_path = os.path.join(getcwd(), html_name)

                    pages.append(html_name)
                    log.debug('Processing PML item %s...' % pml)
                    ttoc = self.process_pml(pml, html_path)
                    toc += ttoc
                images = self.get_images(stream, tdir, True)
        else:
            toc = self.process_pml(stream, 'index.html')
            pages.append('index.html')

            if hasattr(stream, 'name'):
                images = self.get_images(stream, os.path.abspath(os.path.dirname(stream.name)))

        # We want pages to be orded alphabetically.
        pages.sort()

        manifest_items = []
        for item in pages+images:
            manifest_items.append((item, None))

        from calibre.ebooks.metadata.meta import get_metadata
        log.debug('Reading metadata from input file...')
        mi = get_metadata(stream, 'pml')
        if 'images/cover.png' in images:
            mi.cover = 'images/cover.png'
        opf = OPFCreator(getcwd(), mi)
        log.debug('Generating manifest...')
        opf.create_manifest(manifest_items)
        opf.create_spine(pages)
        opf.set_toc(toc)
        with lopen('metadata.opf', 'wb') as opffile:
            with lopen('toc.ncx', 'wb') as tocfile:
                opf.render(opffile, tocfile, 'toc.ncx')

        return os.path.join(getcwd(), 'metadata.opf')
开发者ID:j-howell,项目名称:calibre,代码行数:58,代码来源:pml_input.py

示例6: write_opf

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write_opf(self, guide, toc, spine, resource_map):
        mi = self.header.exth.mi
        if (self.cover_offset is not None and self.cover_offset <
                len(resource_map)):
            mi.cover = resource_map[self.cover_offset]

        if len(list(toc)) < 2:
            self.log.warn('KF8 has no metadata Table of Contents')

            for ref in guide:
                if ref.type == 'toc':
                    href = ref.href()
                    href, frag = urldefrag(href)
                    if os.path.exists(href.replace('/', os.sep)):
                        try:
                            toc = self.read_inline_toc(href, frag)
                        except:
                            self.log.exception('Failed to read inline ToC')

        opf = OPFCreator(os.getcwdu(), mi)
        opf.guide = guide

        def exclude(path):
            return os.path.basename(path) == 'debug-raw.html'

        # If there are no images then the azw3 input plugin dumps all
        # binary records as .unknown images, remove them
        if self.for_tweak and os.path.exists('images') and os.path.isdir('images'):
            files = os.listdir('images')
            unknown = [x for x in files if x.endswith('.unknown')]
            if len(files) == len(unknown):
                [os.remove('images/'+f) for f in files]

        if self.for_tweak:
            try:
                os.remove('debug-raw.html')
            except:
                pass

        opf.create_manifest_from_files_in([os.getcwdu()], exclude=exclude)
        for entry in opf.manifest:
            if entry.mime_type == 'text/html':
                entry.mime_type = 'application/xhtml+xml'
        opf.create_spine(spine)
        opf.set_toc(toc)
        ppd = getattr(self.header.exth, 'page_progression_direction', None)
        if ppd in {'ltr', 'rtl', 'default'}:
            opf.page_progression_direction = ppd
        pwm = getattr(self.header.exth, 'primary_writing_mode', None)
        if pwm is not None:
            opf.primary_writing_mode = pwm

        with open('metadata.opf', 'wb') as of, open('toc.ncx', 'wb') as ncx:
            opf.render(of, ncx, 'toc.ncx')
        return 'metadata.opf'
开发者ID:MarioJC,项目名称:calibre,代码行数:57,代码来源:mobi8.py

示例7: write_opf

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write_opf(self, guide, toc, spine, resource_map):
        mi = self.header.exth.mi
        if self.cover_offset is not None and self.cover_offset < len(resource_map):
            mi.cover = resource_map[self.cover_offset]

        if len(list(toc)) < 2:
            self.log.warn("KF8 has no metadata Table of Contents")

            for ref in guide:
                if ref.type == "toc":
                    href = ref.href()
                    href, frag = urldefrag(href)
                    if os.path.exists(href.replace("/", os.sep)):
                        try:
                            toc = self.read_inline_toc(href, frag)
                        except:
                            self.log.exception("Failed to read inline ToC")

        opf = OPFCreator(os.getcwdu(), mi)
        opf.guide = guide

        def exclude(path):
            return os.path.basename(path) == "debug-raw.html"

        # If there are no images then the azw3 input plugin dumps all
        # binary records as .unknown images, remove them
        if self.for_tweak and os.path.exists("images") and os.path.isdir("images"):
            files = os.listdir("images")
            unknown = [x for x in files if x.endswith(".unknown")]
            if len(files) == len(unknown):
                [os.remove("images/" + f) for f in files]

        if self.for_tweak:
            try:
                os.remove("debug-raw.html")
            except:
                pass

        opf.create_manifest_from_files_in([os.getcwdu()], exclude=exclude)
        for entry in opf.manifest:
            if entry.mime_type == "text/html":
                entry.mime_type = "application/xhtml+xml"
        opf.create_spine(spine)
        opf.set_toc(toc)
        ppd = getattr(self.header.exth, "page_progression_direction", None)
        if ppd in {"ltr", "rtl", "default"}:
            opf.page_progression_direction = ppd

        with open("metadata.opf", "wb") as of, open("toc.ncx", "wb") as ncx:
            opf.render(of, ncx, "toc.ncx")
        return "metadata.opf"
开发者ID:mirror,项目名称:calibre,代码行数:53,代码来源:mobi8.py

示例8: convert

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def convert(self, stream, options, file_ext, log, accelerators):
        log.debug('Enter convert() ...')
        dest_dir = os.getcwdu()  # note: temp dir from calibre process
        log.debug('dest_dir: ' + dest_dir)

        mi = None

        # call latex2mobi with markup output only
        from subprocess import check_output, STDOUT, CalledProcessError

        args = [self.java_exec, '-jar', os.path.join(self.plugin_dir, JAR_FILENAME), '-i', stream.name,
                '-n', '-o', dest_dir]

        from calibre_plugins.latexformulas_input.config import prefs

        if prefs['pandoc_exec'] != None and prefs['pandoc_exec'] != '':
            args.append('-p')
            args.append(prefs['pandoc_exec'])

        try:
            log.debug(check_output(args, stderr=STDOUT))
        except CalledProcessError as e:
            log.debug(e.returncode)
            log.debug(e.cmd)
            log.debug(e.output)

        opf = OPFCreator(dest_dir, mi)
        markup_dir = dest_dir + os.path.sep + os.path.basename(stream.name) + '-markup'
        log.debug('Markup-dir: ' + markup_dir)
        log.debug('CreateManifestFromFilesIn()')

        opf.create_manifest_from_files_in([markup_dir])
        for item in opf.manifest:
            if item.media_type == 'text/html':
                log.debug('Item ' + str(item) + ' is of type text/html')
                item.media_type = guess_type('a.html')[0]
                log.debug('Guess type result: ' + item.media_type)
            if item.media_type == 'text/css':
                log.debug('Item ' + str(item) + ' is of type text/css')
                item.media_type = guess_type('a.css')[0]
                log.debug('Guess type result: ' + item.media_type)

        log.debug('Create_spine()')
        opf.create_spine([os.path.basename(markup_dir) + os.path.sep + 'latex2mobi.html'])

        output_path = os.path.join(dest_dir, 'metadata.opf')
        with open(output_path, 'wb') as of:
            opf.render(of)

        log('Exit convert() ...')
        return output_path
开发者ID:Sevyls,项目名称:latex-formulas-mobi-converter,代码行数:53,代码来源:__init__.py

示例9: create_opf

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def create_opf(self, output_dir, pages, images):
        with CurrentDir(output_dir):
            opf = OPFCreator(output_dir, self.mi)

            manifest = []
            for page in pages+images:
                manifest.append((page, None))

            opf.create_manifest(manifest)
            opf.create_spine(pages)
            with open('metadata.opf', 'wb') as opffile:
                opf.render(opffile)

        return os.path.join(output_dir, 'metadata.opf')
开发者ID:MarioJC,项目名称:calibre,代码行数:16,代码来源:reader.py

示例10: create_opf

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def create_opf(self, output_dir, images):
        with CurrentDir(output_dir):
            opf = OPFCreator(output_dir, self.mi)

            manifest = [('index.html', None)]

            for i in images:
                manifest.append((os.path.join('images/', i), None))

            opf.create_manifest(manifest)
            opf.create_spine(['index.html'])
            with open('metadata.opf', 'wb') as opffile:
                opf.render(opffile)

        return os.path.join(output_dir, 'metadata.opf')
开发者ID:089git,项目名称:calibre,代码行数:17,代码来源:reader202.py

示例11: write

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write(self):
        toc = self.create_toc()
        raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
        with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
            f.write(raw)
        css = self.styles.generate_css(self.dest_dir, self.docx)
        if css:
            with open(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
                f.write(css.encode('utf-8'))

        opf = OPFCreator(self.dest_dir, self.mi)
        opf.toc = toc
        opf.create_manifest_from_files_in([self.dest_dir])
        opf.create_spine(['index.html'])
        with open(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(os.path.join(self.dest_dir, 'toc.ncx'), 'wb') as ncx:
            opf.render(of, ncx, 'toc.ncx')
        return os.path.join(self.dest_dir, 'metadata.opf')
开发者ID:RealEnder,项目名称:calibre,代码行数:19,代码来源:to_html.py

示例12: write

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write(self, doc):
        toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map)
        raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
        with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
            f.write(raw)
        css = self.styles.generate_css(self.dest_dir, self.docx)
        if css:
            with open(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
                f.write(css.encode('utf-8'))

        opf = OPFCreator(self.dest_dir, self.mi)
        opf.toc = toc
        opf.create_manifest_from_files_in([self.dest_dir])
        opf.create_spine(['index.html'])
        if self.cover_image is not None:
            opf.guide.set_cover(self.cover_image)
        with open(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(os.path.join(self.dest_dir, 'toc.ncx'), 'wb') as ncx:
            opf.render(of, ncx, 'toc.ncx')
        return os.path.join(self.dest_dir, 'metadata.opf')
开发者ID:andrewks,项目名称:calibre,代码行数:21,代码来源:to_html.py

示例13: write

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def write(self):
        toc = self.create_toc()
        raw = html.tostring(self.html, encoding="utf-8", doctype="<!DOCTYPE html>")
        with open(os.path.join(self.dest_dir, "index.html"), "wb") as f:
            f.write(raw)
        css = self.styles.generate_css(self.dest_dir, self.docx)
        if css:
            with open(os.path.join(self.dest_dir, "docx.css"), "wb") as f:
                f.write(css.encode("utf-8"))

        opf = OPFCreator(self.dest_dir, self.mi)
        opf.toc = toc
        opf.create_manifest_from_files_in([self.dest_dir])
        opf.create_spine(["index.html"])
        with open(os.path.join(self.dest_dir, "metadata.opf"), "wb") as of, open(
            os.path.join(self.dest_dir, "toc.ncx"), "wb"
        ) as ncx:
            opf.render(of, ncx, "toc.ncx")
        return os.path.join(self.dest_dir, "metadata.opf")
开发者ID:bjhemens,项目名称:calibre,代码行数:21,代码来源:to_html.py

示例14: create_opf

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def create_opf(self, output_dir, images, toc):
        with CurrentDir(output_dir):
            if 'cover.png' in images:
                self.mi.cover = os.path.join('images', 'cover.png')

            opf = OPFCreator(output_dir, self.mi)

            manifest = [('index.html', None)]

            for i in images:
                manifest.append((os.path.join('images', i), None))

            opf.create_manifest(manifest)
            opf.create_spine(['index.html'])
            opf.set_toc(toc)
            with open('metadata.opf', 'wb') as opffile:
                with open('toc.ncx', 'wb') as tocfile:
                    opf.render(opffile, tocfile, 'toc.ncx')

        return os.path.join(output_dir, 'metadata.opf')
开发者ID:JimmXinu,项目名称:calibre,代码行数:22,代码来源:reader132.py

示例15: convert

# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPFCreator [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPFCreator import create_spine [as 别名]
    def convert(self, stream, options, file_ext, log,
                accelerators):
        from calibre.ebooks.metadata.opf2 import OPFCreator
        from calibre.ebooks.pdf.pdftohtml import pdftohtml

        log.debug('Converting file to html...')
        # The main html file will be named index.html
        self.opts, self.log = options, log
        if options.new_pdf_engine:
            return self.convert_new(stream, accelerators)
        pdftohtml(getcwd(), stream.name, options.no_images)

        from calibre.ebooks.metadata.meta import get_metadata
        log.debug('Retrieving document metadata...')
        mi = get_metadata(stream, 'pdf')
        opf = OPFCreator(getcwd(), mi)

        manifest = [('index.html', None)]

        images = os.listdir(getcwd())
        images.remove('index.html')
        for i in images:
            manifest.append((i, None))
        log.debug('Generating manifest...')
        opf.create_manifest(manifest)

        opf.create_spine(['index.html'])
        log.debug('Rendering manifest...')
        with lopen('metadata.opf', 'wb') as opffile:
            opf.render(opffile)
        if os.path.exists('toc.ncx'):
            ncxid = opf.manifest.id_for_path('toc.ncx')
            if ncxid:
                with lopen('metadata.opf', 'r+b') as f:
                    raw = f.read().replace(b'<spine', b'<spine toc="%s"' % as_bytes(ncxid))
                    f.seek(0)
                    f.write(raw)

        return os.path.join(getcwd(), 'metadata.opf')
开发者ID:j-howell,项目名称:calibre,代码行数:41,代码来源:pdf_input.py


注:本文中的calibre.ebooks.metadata.opf2.OPFCreator.create_spine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。