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...'))
if os.path.exists(path):
os.unlink(path)
try:
os.removedirs(os.path.dirname(path))
except:
pass
self.report_progress(1.0, _('Removing books from device...'))
@classmethod

View File

@ -308,6 +308,31 @@ class LitWriter(object):
else:
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):
if hasattr(path, 'write'):
return self._dump_stream(oeb, path)

View File

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

View File

@ -13,11 +13,12 @@ __license__ = 'GPL v3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
def txt_to_markdown(txt):
def txt_to_markdown(txt, title=''):
md = markdown.Markdown(
extensions=['footnotes', 'tables', 'toc'],
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

View File

@ -18,7 +18,7 @@ class TOCWidget(Widget, Ui_Form):
HELP = _('Control the creation/conversion of the Table of Contents.')
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',
'toc_threshold', 'max_toc_links', 'no_chapters_in_toc',
'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.gui2 import config, error_dialog, Dispatcher, dynamic, \
pixmap_to_data, warning_dialog, \
info_dialog
question_dialog
from calibre.ebooks.metadata import authors_to_string
from calibre import sanitize_file_name, preferred_encoding
from calibre.utils.filenames import ascii_filename
@ -566,26 +566,27 @@ class DeviceGUI(object):
else:
bad.append(self.library_view.model().db.title(id, index_is_id=True))
else:
if specific_format in available_output_formats():
if specific_format in list(set(fmts).intersection(set(available_output_formats()))):
auto.append(id)
else:
bad.append(self.library_view.model().db.title(id, index_is_id=True))
if auto != []:
format = None
for fmt in fmts:
if fmt in list(set(fmts).intersection(set(available_output_formats()))):
format = fmt
break
format = specific_format if specific_format in list(set(fmts).intersection(set(available_output_formats()))) else None
if not format:
for fmt in fmts:
if fmt in list(set(fmts).intersection(set(available_output_formats()))):
format = fmt
break
if format is None:
bad += auto
else:
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)
info_dialog(self, _('No suitable formats'),
_('Auto converting the following books before sending via '
'email:'), det_msg=autos, show=True)
self.auto_convert_mail(to, fmts, delete_from_library, auto, format)
if question_dialog(self, _('No suitable formats'),
_('Auto convert the following books before sending via '
'email?'), det_msg=autos):
self.auto_convert_mail(to, fmts, delete_from_library, auto, format)
if bad:
bad = '\n'.join('%s'%(i,) for i in bad)
@ -680,10 +681,10 @@ class DeviceGUI(object):
if format is not None:
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)
info_dialog(self, _('No suitable formats'),
_('Auto converting the following books before uploading to '
'the device:'), det_msg=autos, show=True)
self.auto_convert_news(auto, format)
if question_dialog(self, _('No suitable formats'),
_('Auto convert the following books before uploading to '
'the device?'), det_msg=autos):
self.auto_convert_news(auto, format)
files = [f for f in files if f is not None]
if not files:
dynamic.set('news_to_be_synced', set([]))
@ -776,26 +777,27 @@ class DeviceGUI(object):
else:
bad.append(self.library_view.model().db.title(id, index_is_id=True))
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)
else:
bad.append(self.library_view.model().db.title(id, index_is_id=True))
if auto != []:
format = None
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()))):
format = fmt
break
if format is 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:
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
format = fmt
break
if not format:
bad += auto
else:
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)
info_dialog(self, _('No suitable formats'),
_('Auto converting the following books before uploading to '
'the device:'), det_msg=autos, show=True)
self.auto_convert(auto, on_card, format)
if question_dialog(self, _('No suitable formats'),
_('Auto convert the following books before uploading to '
'the device?'), det_msg=autos):
self.auto_convert(auto, on_card, format)
if bad:
bad = '\n'.join('%s'%(i,) for i in bad)

View File

@ -1186,7 +1186,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
try:
if job.failed:
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)
data.close()
self.status_bar.showMessage(job.description + (' completed'), 2000)
@ -1210,7 +1210,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
if job.failed:
self.job_exception(job)
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)
data.close()
self.status_bar.showMessage(job.description + (' completed'), 2000)
@ -1233,7 +1233,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
try:
if job.failed:
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)
data.close()
self.status_bar.showMessage(job.description + (' completed'), 2000)