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...'))
|
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
|
||||||
|
@ -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)
|
||||||
|
@ -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):
|
||||||
|
@ -13,12 +13,13 @@ __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
|
||||||
|
|
||||||
def opf_writer(path, opf_name, manifest, spine, mi):
|
def opf_writer(path, opf_name, manifest, spine, mi):
|
||||||
|
@ -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',
|
||||||
|
@ -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,26 +566,27 @@ 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
|
||||||
for fmt in fmts:
|
if not format:
|
||||||
if fmt in list(set(fmts).intersection(set(available_output_formats()))):
|
for fmt in fmts:
|
||||||
format = fmt
|
if fmt in list(set(fmts).intersection(set(available_output_formats()))):
|
||||||
break
|
format = fmt
|
||||||
|
break
|
||||||
if format is None:
|
if format is None:
|
||||||
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 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:
|
||||||
bad = '\n'.join('%s'%(i,) for i in bad)
|
bad = '\n'.join('%s'%(i,) for i in bad)
|
||||||
@ -680,10 +681,10 @@ 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:
|
||||||
dynamic.set('news_to_be_synced', set([]))
|
dynamic.set('news_to_be_synced', set([]))
|
||||||
@ -776,26 +777,27 @@ 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
|
||||||
for fmt in self.device_manager.device_class.settings().format_map:
|
if not format:
|
||||||
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
|
for fmt in self.device_manager.device_class.settings().format_map:
|
||||||
format = fmt
|
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
|
||||||
break
|
format = fmt
|
||||||
if format is None:
|
break
|
||||||
|
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:
|
||||||
bad = '\n'.join('%s'%(i,) for i in bad)
|
bad = '\n'.join('%s'%(i,) for i in bad)
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user