Pull from driver-dev

This commit is contained in:
Kovid Goyal 2009-06-27 19:29:28 -07:00
commit aa54195d62
7 changed files with 72 additions and 55 deletions

View File

@ -207,6 +207,10 @@ class PRS505(CLI, Device):
self.report_progress((i+1) / float(len(paths)), _('Removing books from device...')) self.report_progress((i+1) / float(len(paths)), _('Removing books from device...'))
if os.path.exists(path): if os.path.exists(path):
os.unlink(path) os.unlink(path)
try:
os.removedirs(os.path.dirname(path))
except:
pass
self.report_progress(1.0, _('Removing books from device...')) self.report_progress(1.0, _('Removing books from device...'))
@classmethod @classmethod

View File

@ -308,6 +308,31 @@ class LitWriter(object):
else: else:
self._logger.warn('No suitable cover image found.') self._logger.warn('No suitable cover image found.')
# Remove comments because they are not supported by LIT HTML
for item in oeb.spine:
for elem in item.data.getiterator():
if isinstance(elem, etree._Comment):
tail = elem.tail
parent = elem.getparent()
index = parent.index(elem)
text = u''
if index == 0:
if parent.text:
text += parent.text
if tail:
text += tail
parent.text = text
else:
prev = parent[index-1]
text = u''
if prev.tail:
text += prev.tail
if tail:
text += tail
prev.tail = text
parent.remove(elem)
def __call__(self, oeb, path): def __call__(self, oeb, path):
if hasattr(path, 'write'): if hasattr(path, 'write'):
return self._dump_stream(oeb, path) return self._dump_stream(oeb, path)

View File

@ -868,33 +868,18 @@ class Manifest(object):
def _parse_txt(self, data): def _parse_txt(self, data):
if '<html>' in data: if '<html>' in data:
return self._parse_xhtml(data) return self._parse_xhtml(data)
from xml.sax.saxutils import escape
self.oeb.log.debug('Converting', self.href, '...')
paras = []
lines = []
for l in data.splitlines():
if not l:
if lines:
paras.append('<p>'+'\n'.join(lines)+'</p>')
lines = []
lines.append(escape(l))
if lines: self.oeb.log.debug('Converting', self.href, '...')
paras.append('<p>'+'\n'.join(lines)+'</p>')
from calibre.ebooks.txt.processor import txt_to_markdown
title = self.oeb.metadata.title title = self.oeb.metadata.title
if title: if title:
title = unicode(title[0]) title = unicode(title[0])
else: else:
title = 'No title' title = _('Unknown')
data = '''\
<html> return self._parse_xhtml(txt_to_markdown(data, title))
<head><title>%s</title></head>
<body>%s</body>
</html>
'''%(title, '\n'.join(paras))
data = self._parse_xhtml(data)
print etree.tostring(data)
return data
def _parse_css(self, data): def _parse_css(self, data):

View File

@ -13,11 +13,12 @@ __license__ = 'GPL v3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>' __copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
def txt_to_markdown(txt): def txt_to_markdown(txt, title=''):
md = markdown.Markdown( md = markdown.Markdown(
extensions=['footnotes', 'tables', 'toc'], extensions=['footnotes', 'tables', 'toc'],
safe_mode=False,) safe_mode=False,)
html = '<html><head><title /></head><body>'+md.convert(txt)+'</body></html>' html = u'<html><head><title>%s</title></head><body>%s</body></html>' % (title,
md.convert(txt))
return html return html

View File

@ -18,7 +18,7 @@ class TOCWidget(Widget, Ui_Form):
HELP = _('Control the creation/conversion of the Table of Contents.') HELP = _('Control the creation/conversion of the Table of Contents.')
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'structure_detection', Widget.__init__(self, parent, 'toc',
['level1_toc', 'level2_toc', 'level3_toc', ['level1_toc', 'level2_toc', 'level3_toc',
'toc_threshold', 'max_toc_links', 'no_chapters_in_toc', 'toc_threshold', 'max_toc_links', 'no_chapters_in_toc',
'use_auto_toc', 'toc_filter', 'use_auto_toc', 'toc_filter',

View File

@ -19,7 +19,7 @@ from calibre.utils.ipc.job import BaseJob
from calibre.devices.scanner import DeviceScanner from calibre.devices.scanner import DeviceScanner
from calibre.gui2 import config, error_dialog, Dispatcher, dynamic, \ from calibre.gui2 import config, error_dialog, Dispatcher, dynamic, \
pixmap_to_data, warning_dialog, \ pixmap_to_data, warning_dialog, \
info_dialog question_dialog
from calibre.ebooks.metadata import authors_to_string from calibre.ebooks.metadata import authors_to_string
from calibre import sanitize_file_name, preferred_encoding from calibre import sanitize_file_name, preferred_encoding
from calibre.utils.filenames import ascii_filename from calibre.utils.filenames import ascii_filename
@ -566,13 +566,14 @@ class DeviceGUI(object):
else: else:
bad.append(self.library_view.model().db.title(id, index_is_id=True)) bad.append(self.library_view.model().db.title(id, index_is_id=True))
else: else:
if specific_format in available_output_formats(): if specific_format in list(set(fmts).intersection(set(available_output_formats()))):
auto.append(id) auto.append(id)
else: else:
bad.append(self.library_view.model().db.title(id, index_is_id=True)) bad.append(self.library_view.model().db.title(id, index_is_id=True))
if auto != []: if auto != []:
format = None format = specific_format if specific_format in list(set(fmts).intersection(set(available_output_formats()))) else None
if not format:
for fmt in fmts: for fmt in fmts:
if fmt in list(set(fmts).intersection(set(available_output_formats()))): if fmt in list(set(fmts).intersection(set(available_output_formats()))):
format = fmt format = fmt
@ -582,9 +583,9 @@ class DeviceGUI(object):
else: else:
autos = [self.library_view.model().db.title(id, index_is_id=True) for id in auto] autos = [self.library_view.model().db.title(id, index_is_id=True) for id in auto]
autos = '\n'.join('%s'%i for i in autos) autos = '\n'.join('%s'%i for i in autos)
info_dialog(self, _('No suitable formats'), if question_dialog(self, _('No suitable formats'),
_('Auto converting the following books before sending via ' _('Auto convert the following books before sending via '
'email:'), det_msg=autos, show=True) 'email?'), det_msg=autos):
self.auto_convert_mail(to, fmts, delete_from_library, auto, format) self.auto_convert_mail(to, fmts, delete_from_library, auto, format)
if bad: if bad:
@ -680,9 +681,9 @@ class DeviceGUI(object):
if format is not None: if format is not None:
autos = [self.library_view.model().db.title(id, index_is_id=True) for id in auto] autos = [self.library_view.model().db.title(id, index_is_id=True) for id in auto]
autos = '\n'.join('%s'%i for i in autos) autos = '\n'.join('%s'%i for i in autos)
info_dialog(self, _('No suitable formats'), if question_dialog(self, _('No suitable formats'),
_('Auto converting the following books before uploading to ' _('Auto convert the following books before uploading to '
'the device:'), det_msg=autos, show=True) 'the device?'), det_msg=autos):
self.auto_convert_news(auto, format) self.auto_convert_news(auto, format)
files = [f for f in files if f is not None] files = [f for f in files if f is not None]
if not files: if not files:
@ -776,25 +777,26 @@ class DeviceGUI(object):
else: else:
bad.append(self.library_view.model().db.title(id, index_is_id=True)) bad.append(self.library_view.model().db.title(id, index_is_id=True))
else: else:
if specific_format in available_output_formats(): if specific_format in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
auto.append(id) auto.append(id)
else: else:
bad.append(self.library_view.model().db.title(id, index_is_id=True)) bad.append(self.library_view.model().db.title(id, index_is_id=True))
if auto != []: if auto != []:
format = None format = specific_format if specific_format in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))) else None
if not format:
for fmt in self.device_manager.device_class.settings().format_map: for fmt in self.device_manager.device_class.settings().format_map:
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))): if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
format = fmt format = fmt
break break
if format is None: if not format:
bad += auto bad += auto
else: else:
autos = [self.library_view.model().db.title(id, index_is_id=True) for id in auto] autos = [self.library_view.model().db.title(id, index_is_id=True) for id in auto]
autos = '\n'.join('%s'%i for i in autos) autos = '\n'.join('%s'%i for i in autos)
info_dialog(self, _('No suitable formats'), if question_dialog(self, _('No suitable formats'),
_('Auto converting the following books before uploading to ' _('Auto convert the following books before uploading to '
'the device:'), det_msg=autos, show=True) 'the device?'), det_msg=autos):
self.auto_convert(auto, on_card, format) self.auto_convert(auto, on_card, format)
if bad: if bad:

View File

@ -1186,7 +1186,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
try: try:
if job.failed: if job.failed:
return self.job_exception(job) return self.job_exception(job)
data = open(temp_files[0].name, 'rb') data = open(temp_files[-1].name, 'rb')
self.library_view.model().db.add_format(book_id, fmt, data, index_is_id=True) self.library_view.model().db.add_format(book_id, fmt, data, index_is_id=True)
data.close() data.close()
self.status_bar.showMessage(job.description + (' completed'), 2000) self.status_bar.showMessage(job.description + (' completed'), 2000)
@ -1210,7 +1210,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
if job.failed: if job.failed:
self.job_exception(job) self.job_exception(job)
return return
data = open(temp_files[0].name, 'rb') data = open(temp_files[-1].name, 'rb')
self.library_view.model().db.add_format(book_id, fmt, data, index_is_id=True) self.library_view.model().db.add_format(book_id, fmt, data, index_is_id=True)
data.close() data.close()
self.status_bar.showMessage(job.description + (' completed'), 2000) self.status_bar.showMessage(job.description + (' completed'), 2000)
@ -1233,7 +1233,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
try: try:
if job.failed: if job.failed:
return self.job_exception(job) return self.job_exception(job)
data = open(temp_files[0].name, 'rb') data = open(temp_files[-1].name, 'rb')
self.library_view.model().db.add_format(book_id, fmt, data, index_is_id=True) self.library_view.model().db.add_format(book_id, fmt, data, index_is_id=True)
data.close() data.close()
self.status_bar.showMessage(job.description + (' completed'), 2000) self.status_bar.showMessage(job.description + (' completed'), 2000)