More miscellaneous bug fixes

This commit is contained in:
Kovid Goyal 2009-04-25 10:03:00 -07:00
parent 0504bbd929
commit 19e7ed0cb7
8 changed files with 35 additions and 1196 deletions

View File

@ -110,7 +110,7 @@ class EPUBInput(InputFormatPlugin):
parts = os.path.split(opf)
opf = OPF(opf, os.path.dirname(os.path.abspath(opf)))
if len(parts) > 1:
if len(parts) > 1 and parts[0]:
delta = '/'.join(parts[:-1])+'/'
for elem in opf.itermanifest():
elem.set('href', delta+elem.get('href'))

View File

@ -6,13 +6,15 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os
import os, shutil
from urllib import unquote
from calibre.customize.conversion import OutputFormatPlugin
from calibre.ptempfile import TemporaryDirectory
from calibre.constants import __appname__, __version__
from calibre import strftime, guess_type
from calibre.customize.conversion import OptionRecommendation
from lxml import etree
@ -22,6 +24,14 @@ class EPUBOutput(OutputFormatPlugin):
author = 'Kovid Goyal'
file_type = 'epub'
options = set([
OptionRecommendation(name='extract_to',
help=_('Extract the contents of the generated EPUB file to the '
'specified directory. The contents of the directory are first '
'deleted, so be careful.'))
])
TITLEPAGE_COVER = '''\
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
@ -43,6 +53,7 @@ class EPUBOutput(OutputFormatPlugin):
TITLEPAGE = '''\
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>%(title)s</title>
<style type="text/css">
body {
background: white no-repeat fixed center center;
@ -66,7 +77,7 @@ class EPUBOutput(OutputFormatPlugin):
<h2>%(date)s</h2>
<br/><br/><br/><br/><br/>
<h3>%(author)s</h3>
<br/><br/></br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/>
<h4>Produced by %(app)s</h4>
</div>
</div>
@ -94,6 +105,12 @@ class EPUBOutput(OutputFormatPlugin):
from calibre.ebooks.epub import initialize_container
epub = initialize_container(output_path, os.path.basename(opf))
epub.add_dir(tdir)
if opts.extract_to is not None:
if os.path.exists(opts.extract_to):
shutil.rmtree(opts.extract_to)
os.mkdir(opts.extract_to)
epub.extractall(path=opts.extract_to)
self.log.info('EPUB extracted to', opts.extract_to)
epub.close()
def default_cover(self):
@ -145,6 +162,8 @@ class EPUBOutput(OutputFormatPlugin):
urldefrag(self.oeb.guide['titlepage'].href)[0]]
if item is not None:
self.oeb.spine.insert(0, item, True)
if 'cover' not in self.oeb.guide.refs:
self.oeb.guide.add('cover', 'Title Page', 'a')
self.oeb.guide.refs['cover'].href = item.href
if 'titlepage' in self.oeb.guide.refs:
self.oeb.guide.refs['titlepage'].href = item.href

File diff suppressed because it is too large Load Diff

View File

@ -620,7 +620,8 @@ class MobiReader(object):
if r > -1 and (r < l or l == end or l == -1):
p = self.mobi_html.rfind('<', 0, end + 1)
if pos < end and p > -1 and \
not end_tag_re.match(self.mobi_html[p:r]):
not end_tag_re.match(self.mobi_html[p:r]) and \
not self.mobi_html[p:r+1].endswith('/>'):
anchor = ' filepos-id="filepos%d"'
end = r
else:

View File

@ -1324,6 +1324,12 @@ class TOC(object):
return True
return False
def has_text(self, text):
for x in self.iter():
if x.title and x.title.lower() == text.lower():
return True
return False
def iterdescendants(self):
"""Iterate over all descendant nodes in depth-first order."""
for child in self.nodes:

View File

@ -85,7 +85,7 @@ class DetectStructure(object):
def create_toc_from_links(self):
for item in self.oeb.spine:
for a in item.data.xpath('//h:a[@href]'):
for a in XPath('//h:a[@href]')(item.data):
href = a.get('href')
purl = urlparse(href)
if not purl[0] or purl[0] == 'file':

View File

@ -554,7 +554,8 @@ class PdfFileReader(object):
if not self._override_encryption and self.isEncrypted:
# if we don't have the encryption key:
if not hasattr(self, '_decryption_key'):
raise Exception, "file has not been decrypted"
from calibre.ebooks import DRMError
raise DRMError('File contents are encrypted')
# otherwise, decrypt here...
import struct, md5
pack1 = struct.pack("<i", indirectReference.idnum)[:3]

2
todo
View File

@ -12,3 +12,5 @@
* Refactor add books to use a separate process named calibre-worker-add
- Dont use the process for adding a single book
- Use a process pool for speed
* Change mobi metadata setter to use author_sort setting from MOBI output plugin instead of mobi.py