diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py index 986d1bff24..c03d103e3a 100644 --- a/src/calibre/ebooks/epub/output.py +++ b/src/calibre/ebooks/epub/output.py @@ -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) diff --git a/src/calibre/ebooks/oeb/transforms/metadata.py b/src/calibre/ebooks/oeb/transforms/metadata.py index 9733faf487..11509a1edd 100644 --- a/src/calibre/ebooks/oeb/transforms/metadata.py +++ b/src/calibre/ebooks/oeb/transforms/metadata.py @@ -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): diff --git a/src/calibre/ebooks/oeb/transforms/split.py b/src/calibre/ebooks/oeb/transforms/split.py index d8d750eade..d639d895bf 100644 --- a/src/calibre/ebooks/oeb/transforms/split.py +++ b/src/calibre/ebooks/oeb/transforms/split.py @@ -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') diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index 42785e3f3e..ab86cc810d 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -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) diff --git a/src/calibre/utils/filenames.py b/src/calibre/utils/filenames.py index 0aab96522b..bf3cbe2f67 100644 --- a/src/calibre/utils/filenames.py +++ b/src/calibre/utils/filenames.py @@ -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 diff --git a/src/calibre/utils/sigil.py b/src/calibre/utils/sigil.py new file mode 100644 index 0000000000..c87cd5ea93 --- /dev/null +++ b/src/calibre/utils/sigil.py @@ -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 ' +__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() + diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index 80f8563771..a98e355274 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -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)