mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Pull from driver-dev
This commit is contained in:
commit
aa54195d62
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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,13 +566,14 @@ 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
|
||||
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
|
||||
@ -582,9 +583,9 @@ class DeviceGUI(object):
|
||||
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)
|
||||
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:
|
||||
@ -680,9 +681,9 @@ 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)
|
||||
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:
|
||||
@ -776,25 +777,26 @@ 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
|
||||
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 format is None:
|
||||
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)
|
||||
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:
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user