Sync to trunk.

This commit is contained in:
John Schember 2009-07-09 06:18:49 -04:00
commit 488d04cc08
11 changed files with 790 additions and 658 deletions

View File

@ -2,7 +2,7 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
__appname__ = 'calibre' __appname__ = 'calibre'
__version__ = '0.6.0b10' __version__ = '0.6.0b11'
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
import re import re

View File

@ -24,21 +24,26 @@ def read_metadata_(task, tdir, notification=lambda x,y:x):
from calibre.ebooks.metadata.meta import metadata_from_formats from calibre.ebooks.metadata.meta import metadata_from_formats
from calibre.ebooks.metadata.opf2 import OPFCreator from calibre.ebooks.metadata.opf2 import OPFCreator
for x in task: for x in task:
id, formats = x try:
if isinstance(formats, basestring): formats = [formats] id, formats = x
mi = metadata_from_formats(formats) if isinstance(formats, basestring): formats = [formats]
mi.cover = None mi = metadata_from_formats(formats)
cdata = None mi.cover = None
if mi.cover_data: cdata = None
cdata = mi.cover_data[-1] if mi.cover_data:
mi.cover_data = None cdata = mi.cover_data[-1]
opf = OPFCreator(tdir, mi) mi.cover_data = None
with open(os.path.join(tdir, '%s.opf'%id), 'wb') as f: opf = OPFCreator(tdir, mi)
opf.render(f) with open(os.path.join(tdir, '%s.opf'%id), 'wb') as f:
if cdata: opf.render(f)
with open(os.path.join(tdir, str(id)), 'wb') as f: if cdata:
f.write(cdata) with open(os.path.join(tdir, str(id)), 'wb') as f:
notification(0.5, id) f.write(cdata)
notification(0.5, id)
except:
import traceback
with open(os.path.join(tdir, '%s.error'%id), 'wb') as f:
f.write(traceback.format_exc())
class Progress(object): class Progress(object):
@ -49,7 +54,10 @@ class Progress(object):
def __call__(self, id): def __call__(self, id):
cover = os.path.join(self.tdir, str(id)) cover = os.path.join(self.tdir, str(id))
if not os.path.exists(cover): cover = None if not os.path.exists(cover): cover = None
self.result_queue.put((id, os.path.join(self.tdir, '%s.opf'%id), cover)) res = os.path.join(self.tdir, '%s.error'%id)
if not os.path.exists(res):
res = res.replace('.error', '.opf')
self.result_queue.put((id, res, cover))
class ReadMetadata(Thread): class ReadMetadata(Thread):

View File

@ -35,7 +35,7 @@ class Clean(object):
for x in list(self.oeb.guide): for x in list(self.oeb.guide):
href = urldefrag(self.oeb.guide[x].href)[0] href = urldefrag(self.oeb.guide[x].href)[0]
if x.lower() not in ('cover', 'titlepage', 'masthead', 'toc', if x.lower() not in ('cover', 'titlepage', 'masthead', 'toc',
'title-page', 'copyright-page'): 'title-page', 'copyright-page', 'start'):
self.oeb.guide.remove(x) self.oeb.guide.remove(x)

View File

@ -72,7 +72,7 @@ def _config():
c.add_opt('asked_library_thing_password', default=False, c.add_opt('asked_library_thing_password', default=False,
help='Asked library thing password at least once.') help='Asked library thing password at least once.')
c.add_opt('search_as_you_type', default=True, c.add_opt('search_as_you_type', default=True,
help='Start searching as you type. If this is disabled then seaerch will ' help='Start searching as you type. If this is disabled then search will '
'only take place when the Enter or Return key is pressed.') 'only take place when the Enter or Return key is pressed.')
return ConfigProxy(c) return ConfigProxy(c)

View File

@ -44,6 +44,7 @@ class Adder(QObject):
self.pd = ProgressDialog(_('Adding...'), parent=parent) self.pd = ProgressDialog(_('Adding...'), parent=parent)
self.spare_server = spare_server self.spare_server = spare_server
self.db = db self.db = db
self.critical = {}
self.pd.setModal(True) self.pd.setModal(True)
self.pd.show() self.pd.show()
self._parent = parent self._parent = parent
@ -123,8 +124,12 @@ class Adder(QObject):
return return
self.pd.value += 1 self.pd.value += 1
formats = self.ids.pop(id) formats = self.ids.pop(id)
mi = MetaInformation(OPF(opf))
name = self.nmap.pop(id) name = self.nmap.pop(id)
if opf.endswith('.error'):
mi = MetaInformation('', [_('Unknown')])
self.critical[name] = open(opf, 'rb').read().decode('utf-8', 'replace')
else:
mi = MetaInformation(OPF(opf))
if not mi.title: if not mi.title:
mi.title = os.path.splitext(name)[0] mi.title = os.path.splitext(name)[0]
mi.title = mi.title if isinstance(mi.title, unicode) else \ mi.title = mi.title if isinstance(mi.title, unicode) else \

View File

@ -8,11 +8,9 @@ __docformat__ = 'restructuredtext en'
import re import re
from PyQt4.Qt import SIGNAL
from calibre.gui2.convert.structure_detection_ui import Ui_Form from calibre.gui2.convert.structure_detection_ui import Ui_Form
from calibre.gui2.convert import Widget from calibre.gui2.convert import Widget
from calibre.gui2 import error_dialog, qstring_to_unicode from calibre.gui2 import error_dialog
class StructureDetectionWidget(Widget, Ui_Form): class StructureDetectionWidget(Widget, Ui_Form):
@ -39,7 +37,7 @@ class StructureDetectionWidget(Widget, Ui_Form):
for x in ('header_regex', 'footer_regex'): for x in ('header_regex', 'footer_regex'):
x = getattr(self, 'opt_'+x) x = getattr(self, 'opt_'+x)
try: try:
pat = qstring_to_unicode(x.text()) pat = unicode(x.text())
re.compile(pat) re.compile(pat)
except Exception, err: except Exception, err:
error_dialog(self, _('Invalid regular expression'), error_dialog(self, _('Invalid regular expression'),

View File

@ -13,7 +13,7 @@ import traceback
from datetime import datetime from datetime import datetime
from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt, QTimer, QThread, QDate from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt, QTimer, QThread, QDate
from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog, QCompleter from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog
from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \ from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
choose_files, pixmap_to_data, choose_images, ResizableDialog choose_files, pixmap_to_data, choose_images, ResizableDialog

View File

@ -313,12 +313,14 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
cm.addAction(_('Convert individually')) cm.addAction(_('Convert individually'))
cm.addAction(_('Bulk convert')) cm.addAction(_('Bulk convert'))
self.action_convert.setMenu(cm) self.action_convert.setMenu(cm)
self._convert_single_hook = partial(self.convert_ebook, bulk=False)
QObject.connect(cm.actions()[0], QObject.connect(cm.actions()[0],
SIGNAL('triggered(bool)'), partial(self.convert_ebook, bulk=False)) SIGNAL('triggered(bool)'), self._convert_single_hook)
self._convert_bulk_hook = partial(self.convert_ebook, bulk=True)
QObject.connect(cm.actions()[1], QObject.connect(cm.actions()[1],
SIGNAL('triggered(bool)'), partial(self.convert_ebook, bulk=True)) SIGNAL('triggered(bool)'), self._convert_bulk_hook)
QObject.connect(self.action_convert, QObject.connect(self.action_convert,
SIGNAL('triggered(bool)'), partial(self.convert_ebook)) SIGNAL('triggered(bool)'), self.convert_ebook)
self.convert_menu = cm self.convert_menu = cm
pm = QMenu() pm = QMenu()
@ -859,6 +861,13 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.library_view.model().books_added(self._adder.number_of_books_added) self.library_view.model().books_added(self._adder.number_of_books_added)
if hasattr(self, 'db_images'): if hasattr(self, 'db_images'):
self.db_images.reset() self.db_images.reset()
if self._adder.critical:
det_msg = []
for name, log in self._adder.critical.items():
det_msg.append(name+'\n'+log)
warning_dialog(self, _('Failed to read metadata'),
_('Failed to read metadata from the following')+':',
det_msg='\n\n'.join(det_msg), show=True)
self._adder = None self._adder = None
@ -1363,13 +1372,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
if len(rows) >= 3: if len(rows) >= 3:
if not question_dialog(self, _('Multiple Books Selected'), if not question_dialog(self, _('Multiple Books Selected'),
_('You are attempting to open %i books. Opening to many ' _('You are attempting to open %d books. Opening too many '
'books at once can be slow and have an negative effect on the ' 'books at once can be slow and have a negative effect on the '
'responsiveness of your computer. Once started the process ' )% len(rows)):
'cannot be stopped until complete. Do you wish to continue?'
% len(rows))):
return return
if self.current_view() is self.library_view: if self.current_view() is self.library_view:
for row in rows: for row in rows:
row = row.row() row = row.row()

View File

@ -92,6 +92,12 @@ class CybookG3(Device):
manufacturer = 'Booken' manufacturer = 'Booken'
id = 'cybookg3' id = 'cybookg3'
class CybookOpus(CybookG3):
name = 'Cybook Opus'
output_format = 'EPUB'
id = 'cybook_opus'
class BeBook(Device): class BeBook(Device):
name = 'BeBook or BeBook Mini' name = 'BeBook or BeBook Mini'

File diff suppressed because it is too large Load Diff

View File

@ -548,8 +548,10 @@ def _prefs():
help=_('The language in which to display the user interface')) help=_('The language in which to display the user interface'))
c.add_opt('output_format', default='EPUB', c.add_opt('output_format', default='EPUB',
help=_('The default output format for ebook conversions.')) help=_('The default output format for ebook conversions.'))
c.add_opt('input_format_order', default=['EPUB', 'MOBI', 'PRC', 'LIT'], c.add_opt('input_format_order', default=['EPUB', 'MOBI', 'LIT', 'PRC',
help=_('Order list of formats to prefer for input.')) 'FB2', 'HTML', 'HTM', 'XHTM', 'SHTML', 'XHTML', 'ODT', 'RTF', 'PDF',
'TXT'],
help=_('Ordered list of formats to prefer for input.'))
c.add_opt('read_file_metadata', default=True, c.add_opt('read_file_metadata', default=True,
help=_('Read metadata from files')) help=_('Read metadata from files'))
c.add_opt('worker_process_priority', default='normal', c.add_opt('worker_process_priority', default='normal',