diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py
index 5504136e0c..13085c5c70 100644
--- a/src/calibre/devices/usbms/device.py
+++ b/src/calibre/devices/usbms/device.py
@@ -42,6 +42,7 @@ class Device(DeviceConfig, DevicePlugin):
WINDOWS_MAIN_MEM = None
WINDOWS_CARD_A_MEM = None
WINDOWS_CARD_B_MEM = None
+ ALLOW_NO_MAIN_MEMORY = False
# The following are used by the check_ioreg_line method and can be either:
# None, a string, a list of strings or a compiled regular expression
@@ -266,6 +267,9 @@ class Device(DeviceConfig, DevicePlugin):
drives['cardb'] = self.windows_get_drive_prefix(drive)
elif self.windows_match_device(drive, 'WINDOWS_MAIN_MEM') and not drives.get('main', None):
drives['main'] = self.windows_get_drive_prefix(drive)
+ if not self.ALLOW_NO_MAIN_MEMORY:
+ raise DeviceError('Failed to find the drive corresponding'
+ ' to the main memory')
if 'main' in drives.keys() and 'carda' in drives.keys() and \
'cardb' in drives.keys():
diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py
index c0ea8ea197..3bc3424c39 100644
--- a/src/calibre/ebooks/fb2/fb2ml.py
+++ b/src/calibre/ebooks/fb2/fb2ml.py
@@ -68,21 +68,13 @@ class FB2MLizer(object):
self.image_hrefs = {}
self.link_hrefs = {}
output = self.fb2_header()
- if 'titlepage' in self.oeb_book.guide:
- self.log.debug('Generating cover page...')
- href = self.oeb_book.guide['titlepage'].href
- item = self.oeb_book.manifest.hrefs[href]
- if item.spine_position is None:
- stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
- output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
- for item in self.oeb_book.spine:
- self.log.debug('Converting %s to FictionBook2 XML' % item.href)
- stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
- output += self.add_page_anchor(item)
- output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
+ output += self.get_cover_page()
+ output += u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk'
+ output += self.get_text()
output += self.fb2_body_footer()
output += self.fb2mlize_images()
output += self.fb2_footer()
+ output = output.replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc())
return u'\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True)
def fb2_header(self):
@@ -112,7 +104,39 @@ class FB2MLizer(object):
'\n
\n' % (author_first, author_middle,
author_last, self.oeb_book.metadata.title[0].value,
__appname__, __version__)
-
+
+ def get_cover_page(self):
+ output = u''
+ if 'titlepage' in self.oeb_book.guide:
+ self.log.debug('Generating cover page...')
+ href = self.oeb_book.guide['titlepage'].href
+ item = self.oeb_book.manifest.hrefs[href]
+ if item.spine_position is None:
+ stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
+ output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
+ return output
+
+ def get_toc(self):
+ toc = u''
+ if self.opts.inline_toc:
+ self.log.debug('Generating table of contents...')
+ toc += u'%s
' % _('Table of Contents:')
+ for item in self.oeb_book.toc:
+ if item.href in self.link_hrefs.keys():
+ toc += '%s
\n' % (self.link_hrefs[item.href], item.title)
+ else:
+ self.oeb.warn('Ignoring toc item: %s not found in document.' % item)
+ return toc
+
+ def get_text(self):
+ text = u''
+ for item in self.oeb_book.spine:
+ self.log.debug('Converting %s to FictionBook2 XML' % item.href)
+ stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
+ text += self.add_page_anchor(item)
+ text += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
+ return text
+
def fb2_body_footer(self):
return u'\n\n'
@@ -135,7 +159,7 @@ class FB2MLizer(object):
for item in self.oeb_book.manifest:
if item.media_type in OEB_RASTER_IMAGES:
try:
- im = Image.open(cStringIO.StringIO(item.data))
+ im = Image.open(cStringIO.StringIO(item.data)).convert('RGB')
data = cStringIO.StringIO()
im.save(data, 'JPEG')
data = data.getvalue()
diff --git a/src/calibre/ebooks/fb2/output.py b/src/calibre/ebooks/fb2/output.py
index af04179e9a..67ea135c1b 100644
--- a/src/calibre/ebooks/fb2/output.py
+++ b/src/calibre/ebooks/fb2/output.py
@@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
import os
-from calibre.customize.conversion import OutputFormatPlugin
+from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
from calibre.ebooks.fb2.fb2ml import FB2MLizer
class FB2Output(OutputFormatPlugin):
@@ -15,6 +15,12 @@ class FB2Output(OutputFormatPlugin):
author = 'John Schember'
file_type = 'fb2'
+ options = set([
+ OptionRecommendation(name='inline_toc',
+ recommended_value=False, level=OptionRecommendation.LOW,
+ help=_('Add Table of Contents to begenning of the book.')),
+ ])
+
def convert(self, oeb_book, output_path, input_plugin, opts, log):
fb2mlizer = FB2MLizer(log)
fb2_content = fb2mlizer.extract_content(oeb_book, opts)
diff --git a/src/calibre/ebooks/pdb/ereader/output.py b/src/calibre/ebooks/pdb/ereader/output.py
deleted file mode 100644
index 7d3a75eeee..0000000000
--- a/src/calibre/ebooks/pdb/ereader/output.py
+++ /dev/null
@@ -1,37 +0,0 @@
-# -*- coding: utf-8 -*-
-
-__license__ = 'GPL 3'
-__copyright__ = '2009, John Schember '
-__docformat__ = 'restructuredtext en'
-
-import os
-
-from calibre.customize.conversion import OutputFormatPlugin
-from calibre.ebooks.pdb.ereader.writer import Writer
-
-class EREADEROutput(OutputFormatPlugin):
-
- name = 'eReader PDB Output'
- author = 'John Schember'
- file_type = 'erpdb'
-
- def convert(self, oeb_book, output_path, input_plugin, opts, log):
- writer = Writer(log)
-
- close = False
- if not hasattr(output_path, 'write'):
- close = True
- if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
- os.makedirs(os.path.dirname(output_path))
- out_stream = open(output_path, 'wb')
- else:
- out_stream = output_path
-
- out_stream.seek(0)
- out_stream.truncate()
-
- writer.dump(oeb_book, out_stream)
-
- if close:
- out_stream.close()
-
diff --git a/src/calibre/ebooks/pdb/output.py b/src/calibre/ebooks/pdb/output.py
index b591769ec8..9a844d2136 100644
--- a/src/calibre/ebooks/pdb/output.py
+++ b/src/calibre/ebooks/pdb/output.py
@@ -27,6 +27,9 @@ class PDBOutput(OutputFormatPlugin):
help=_('Specify the character encoding of the output document. ' \
'The default is cp1252. Note: This option is not honored by all ' \
'formats.')),
+ OptionRecommendation(name='inline_toc',
+ recommended_value=False, level=OptionRecommendation.LOW,
+ help=_('Add Table of Contents to begenning of the book.')),
])
def convert(self, oeb_book, output_path, input_plugin, opts, log):
diff --git a/src/calibre/ebooks/pml/output.py b/src/calibre/ebooks/pml/output.py
index ac66c9a9f5..970bcd3594 100644
--- a/src/calibre/ebooks/pml/output.py
+++ b/src/calibre/ebooks/pml/output.py
@@ -31,8 +31,10 @@ class PMLOutput(OutputFormatPlugin):
OptionRecommendation(name='output_encoding', recommended_value='cp1252',
level=OptionRecommendation.LOW,
help=_('Specify the character encoding of the output document. ' \
- 'The default is cp1252. Note: This option is not honored by all ' \
- 'formats.')),
+ 'The default is cp1252.')),
+ OptionRecommendation(name='inline_toc',
+ recommended_value=False, level=OptionRecommendation.LOW,
+ help=_('Add Table of Contents to begenning of the book.')),
])
def convert(self, oeb_book, output_path, input_plugin, opts, log):
diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py
index 59b27f1763..1777d1290b 100644
--- a/src/calibre/ebooks/pml/pmlml.py
+++ b/src/calibre/ebooks/pml/pmlml.py
@@ -27,7 +27,7 @@ TAG_MAP = {
'del' : 'o',
'h1' : 'x',
'h2' : 'X0',
- 'h3' : 'x1',
+ 'h3' : 'X1',
'h4' : 'X2',
'h5' : 'X3',
'h6' : 'X4',
@@ -85,6 +85,15 @@ class PMLMLizer(object):
def pmlmlize_spine(self):
self.image_hrefs = {}
self.link_hrefs = {}
+ output = u''
+ output += self.get_cover_page()
+ output += u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk'
+ output += self.get_text()
+ output = output.replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc())
+ output = self.clean_text(output)
+ return output
+
+ def get_cover_page(self):
output = u''
if 'titlepage' in self.oeb_book.guide:
self.log.debug('Generating title page...')
@@ -93,14 +102,28 @@ class PMLMLizer(object):
if item.spine_position is None:
stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
+ return output
+
+ def get_toc(self):
+ toc = u''
+ if self.opts.inline_toc:
+ self.log.debug('Generating table of contents...')
+ toc += u'\\X0%s\\X0\n\n' % _('Table of Contents:')
+ for item in self.oeb_book.toc:
+ if item.href in self.link_hrefs.keys():
+ toc += '* \\q="#%s"%s\\q\n' % (self.link_hrefs[item.href], item.title)
+ else:
+ self.oeb.warn('Ignoring toc item: %s not found in document.' % item)
+ return toc
+
+ def get_text(self):
+ text = u''
for item in self.oeb_book.spine:
self.log.debug('Converting %s to PML markup...' % item.href)
stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
- output += self.add_page_anchor(item)
- output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
- output = self.clean_text(output)
-
- return output
+ text += self.add_page_anchor(item)
+ text += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
+ return text
def add_page_anchor(self, page):
return self.get_anchor(page, '')
diff --git a/src/calibre/ebooks/rb/output.py b/src/calibre/ebooks/rb/output.py
index 04c7d41790..0e0bd27326 100644
--- a/src/calibre/ebooks/rb/output.py
+++ b/src/calibre/ebooks/rb/output.py
@@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
import os
-from calibre.customize.conversion import OutputFormatPlugin
+from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
from calibre.ebooks.rb.writer import RBWriter
class RBOutput(OutputFormatPlugin):
@@ -15,6 +15,12 @@ class RBOutput(OutputFormatPlugin):
author = 'John Schember'
file_type = 'rb'
+ options = set([
+ OptionRecommendation(name='inline_toc',
+ recommended_value=False, level=OptionRecommendation.LOW,
+ help=_('Add Table of Contents to begenning of the book.')),
+ ])
+
def convert(self, oeb_book, output_path, input_plugin, opts, log):
close = False
if not hasattr(output_path, 'write'):
diff --git a/src/calibre/ebooks/rb/rbml.py b/src/calibre/ebooks/rb/rbml.py
index 2c4bb6916c..679ccaa39b 100644
--- a/src/calibre/ebooks/rb/rbml.py
+++ b/src/calibre/ebooks/rb/rbml.py
@@ -72,6 +72,16 @@ class RBMLizer(object):
def mlize_spine(self):
self.link_hrefs = {}
output = u''
+ output += self.get_cover_page()
+ output += u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk'
+ output += self.get_text()
+ output += u''
+ output = output.replace(u'ghji87yhjko0Caliblre-toc-placeholder-for-insertion-later8ujko0987yjk', self.get_toc())
+ output = self.clean_text(output)
+ return output
+
+ def get_cover_page(self):
+ output = u''
if 'titlepage' in self.oeb_book.guide:
self.log.debug('Generating cover page...')
href = self.oeb_book.guide['titlepage'].href
@@ -79,13 +89,28 @@ class RBMLizer(object):
if item.spine_position is None:
stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
+ return output
+
+ def get_toc(self):
+ toc = u''
+ if self.opts.inline_toc:
+ self.log.debug('Generating table of contents...')
+ toc += u'%s
\n' % _('Table of Contents:')
+ for item in self.oeb_book.toc:
+ if item.href in self.link_hrefs.keys():
+ toc += '- %s
\n' % (self.link_hrefs[item.href], item.title)
+ else:
+ self.oeb.warn('Ignoring toc item: %s not found in document.' % item)
+ toc += '
'
+ return toc
+
+ def get_text(self):
+ output = u''
for item in self.oeb_book.spine:
self.log.debug('Converting %s to RocketBook HTML...' % item.href)
stylizer = Stylizer(item.data, item.href, self.oeb_book, self.opts.output_profile)
output += self.add_page_anchor(item)
output += self.dump_text(item.data.find(XHTML('body')), stylizer, item)
- output += u'