mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Sync to trunk.
This commit is contained in:
commit
76b10fcac3
@ -163,6 +163,7 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
|
||||
self.workaround_ade_quirks()
|
||||
self.workaround_webkit_quirks()
|
||||
self.workaround_sony_quirks()
|
||||
from calibre.ebooks.oeb.transforms.rescale import RescaleImages
|
||||
RescaleImages()(oeb, opts)
|
||||
self.insert_cover()
|
||||
@ -346,5 +347,50 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
else:
|
||||
self.oeb.log.warn('No stylesheet found')
|
||||
|
||||
def workaround_sony_quirks(self):
|
||||
'''
|
||||
Perform toc link transforms to alleviate slow loading.
|
||||
'''
|
||||
from calibre.ebooks.oeb.base import urldefrag, XPath
|
||||
|
||||
def frag_is_at_top(root, frag):
|
||||
body = XPath('//h:body')(root)
|
||||
if body:
|
||||
body = body[0]
|
||||
else:
|
||||
return False
|
||||
tree = body.getroottree()
|
||||
elem = XPath('//*[@id="%s" or @name="%s"]'%(frag, frag))(root)
|
||||
if elem:
|
||||
elem = elem[0]
|
||||
else:
|
||||
return False
|
||||
path = tree.getpath(elem)
|
||||
for el in body.iterdescendants():
|
||||
epath = tree.getpath(el)
|
||||
if epath == path:
|
||||
break
|
||||
if el.text and el.text.strip():
|
||||
return False
|
||||
if not path.startswith(epath):
|
||||
# Only check tail of non-parent elements
|
||||
if el.tail and el.tail.strip():
|
||||
return False
|
||||
return True
|
||||
|
||||
def simplify_toc_entry(toc):
|
||||
if toc.href:
|
||||
href, frag = urldefrag(toc.href)
|
||||
if frag:
|
||||
for x in self.oeb.spine:
|
||||
if x.href == href:
|
||||
if frag_is_at_top(x.data, frag):
|
||||
self.log.debug('Removing anchor from TOC href:',
|
||||
href+'#'+frag)
|
||||
toc.href = href
|
||||
break
|
||||
for x in toc:
|
||||
simplify_toc_entry(x)
|
||||
|
||||
if self.oeb.toc:
|
||||
simplify_toc_entry(self.oeb.toc)
|
||||
|
@ -71,7 +71,7 @@ def meta_info_to_oeb_metadata(mi, m, log):
|
||||
m.clear('publication_type')
|
||||
m.add('publication_type', mi.publication_type)
|
||||
if not m.timestamp:
|
||||
m.add('timestamp', datetime.utcnow().isoformat())
|
||||
m.add('timestamp', datetime.now().isoformat())
|
||||
|
||||
|
||||
class MergeMetadata(object):
|
||||
|
@ -457,10 +457,9 @@ class FlowSplitter(object):
|
||||
root = tree.getroot()
|
||||
self.files.append(self.base%i)
|
||||
for elem in root.xpath('//*[@id or @name]'):
|
||||
anchor = elem.get('id', '')
|
||||
if not anchor:
|
||||
anchor = elem.get('name')
|
||||
self.anchor_map[anchor] = self.files[-1]
|
||||
for anchor in elem.get('id', ''), elem.get('name', ''):
|
||||
if anchor != '' and anchor not in self.anchor_map:
|
||||
self.anchor_map[anchor] = self.files[-1]
|
||||
for elem in root.xpath('//*[@%s]'%SPLIT_POINT_ATTR):
|
||||
elem.attrib.pop(SPLIT_POINT_ATTR, '0')
|
||||
|
||||
|
@ -144,7 +144,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
||||
ext = os.path.splitext(_file)[1].lower().replace('.', '')
|
||||
for row in range(self.formats.count()):
|
||||
fmt = self.formats.item(row)
|
||||
if fmt.ext == ext:
|
||||
if fmt.ext.lower() == ext:
|
||||
self.formats.takeItem(row)
|
||||
break
|
||||
Format(self.formats, ext, size, path=_file)
|
||||
|
@ -8,7 +8,7 @@ from math import ceil
|
||||
|
||||
from calibre.ebooks.unidecode.unidecoder import Unidecoder
|
||||
from calibre import sanitize_file_name
|
||||
from calibre.constants import preferred_encoding
|
||||
from calibre.constants import preferred_encoding, iswindows
|
||||
udc = Unidecoder()
|
||||
|
||||
def ascii_text(orig):
|
||||
@ -65,3 +65,14 @@ def shorten_components_to(length, components):
|
||||
ans.append(r)
|
||||
return ans
|
||||
|
||||
def find_executable_in_path(name, path=None):
|
||||
if path is None:
|
||||
path = os.environ.get('PATH', '')
|
||||
sep = ';' if iswindows else ':'
|
||||
if iswindows and not name.endswith('.exe'):
|
||||
name += '.exe'
|
||||
path = path.split(sep)
|
||||
for x in path:
|
||||
q = os.path.abspath(os.path.join(x, name))
|
||||
if os.access(q, os.X_OK):
|
||||
return q
|
||||
|
17
src/calibre/utils/sigil.py
Normal file
17
src/calibre/utils/sigil.py
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import with_statement
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from calibre.utils.filenames import find_executable_in_path
|
||||
from calibre.constants import iswindows
|
||||
|
||||
def find_executable():
|
||||
name = 'sigil' + ('.exe' if iswindows else '')
|
||||
path = find_executable_in_path(name)
|
||||
#if path is None and iswindows:
|
||||
# path = search_program_files()
|
||||
|
@ -11,6 +11,7 @@ import os, time, traceback, re, urlparse, sys
|
||||
from collections import defaultdict
|
||||
from functools import partial
|
||||
from contextlib import nested, closing
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt4.Qt import QApplication, QFile, QIODevice
|
||||
|
||||
@ -872,6 +873,8 @@ class BasicNewsRecipe(Recipe):
|
||||
mi.publisher = __appname__
|
||||
mi.author_sort = __appname__
|
||||
mi.publication_type = 'periodical:'+self.publication_type
|
||||
mi.timestamp = datetime.now()
|
||||
mi.pubdate = datetime.now()
|
||||
opf_path = os.path.join(dir, 'index.opf')
|
||||
ncx_path = os.path.join(dir, 'index.ncx')
|
||||
opf = OPFCreator(dir, mi)
|
||||
|
Loading…
x
Reference in New Issue
Block a user