diff --git a/src/calibre/ebooks/epub/__init__.py b/src/calibre/ebooks/epub/__init__.py index d33582ac8b..93d5813fba 100644 --- a/src/calibre/ebooks/epub/__init__.py +++ b/src/calibre/ebooks/epub/__init__.py @@ -62,10 +62,10 @@ def config(defaults=None): c.add_opt('override_css', ['--override-css'], default=None, help=_('Either the path to a CSS stylesheet or raw CSS. This CSS will override any existing CSS declarations in the source files.')) structure = c.add_group('structure detection', _('Control auto-detection of document structure.')) - structure('chapter', ['--chapter'], default="//*[re:match(name(), 'h[1-2]') and re:test(., 'chapter|book|section', 'i')]", + structure('chapter', ['--chapter'], default="//*[re:match(name(), 'h[1-2]') and re:test(., 'chapter|book|section|part', 'i')]", help=_('''\ An XPath expression to detect chapter titles. The default is to consider
EPUB support is still in beta. If you find bugs, please report them by opening a ticket.').exec_()
+ prefs['output_format'] = of
if not path or not os.path.exists(path) or not os.path.isdir(path):
d = error_dialog(self, _('Invalid database location'),
diff --git a/src/calibre/gui2/dialogs/config.ui b/src/calibre/gui2/dialogs/config.ui
index 35b990efde..bc5f634af4 100644
--- a/src/calibre/gui2/dialogs/config.ui
+++ b/src/calibre/gui2/dialogs/config.ui
@@ -7,7 +7,7 @@
There was an error reading from file: Could not convert %d of %d books, because no suitable source format was found. Could not convert %d of %d books, because no suitable source format was found. Could not convert %d of %d books, because no suitable source format was found.
") + _file + "
"+str(e))
+ d.exec_()
+ if cover:
+ pix = QPixmap()
+ pix.loadFromData(cover)
+ if pix.isNull():
+ d = error_dialog(self.window, _file + _(" is not a valid picture"))
+ d.exec_()
+ else:
+ self.cover_path.setText(_file)
+ self.cover.setPixmap(pix)
+ self.cover_changed = True
+ self.cpixmap = pix
+
+ def initialize_metadata_options(self):
+ all_series = self.db.all_series()
+ all_series.sort(cmp=lambda x, y : cmp(x[1], y[1]))
+ for series in all_series:
+ self.series.addItem(series[1])
+ self.series.setCurrentIndex(-1)
+
+ if self.row is not None:
+ mi = self.db.get_metadata(self.id, index_is_id=True)
+ self.title.setText(mi.title)
+ self.author.setText(', '.join(mi.authors))
+ self.publisher.setText(mi.publisher if mi.publisher else '')
+ self.author_sort.setText(mi.author_sort if mi.author_sort else '')
+ self.tags.setText(', '.join(mi.tags if mi.tags else []))
+ self.comment.setText(mi.comments if mi.comments else '')
+ if mi.series:
+ self.series.setCurrentIndex(self.series.findText(mi.series))
+ if mi.series_index is not None:
+ self.series_index.setValue(mi.series_index)
+
+ cover = self.db.cover(self.id, index_is_id=True)
+ if cover:
+ pm = QPixmap()
+ pm.loadFromData(cover)
+ if not pm.isNull():
+ self.cover.setPixmap(pm)
+
+ def get_title_and_authors(self):
+ title = unicode(self.title.text()).strip()
+ if not title:
+ title = _('Unknown')
+ authors = [i.strip() for i in unicode(self.author.text()).strip().split(',')]
+ if not authors:
+ authors = [_('Unknown')]
+ return title, authors
+
+ def get_metadata(self):
+ title, authors = self.get_title_and_authors()
+ mi = MetaInformation(title, authors)
+ publisher = unicode(self.publisher.text())
+ if publisher:
+ mi.publisher = publisher
+ author_sort = unicode(self.publisher.text())
+ if author_sort:
+ mi.author_sort = author_sort
+ comments = unicode(self.comment.toPlainText())
+ if comments:
+ mi.comments = comments
+ mi.series_index = int(self.series_index.value())
+ if self.series.currentIndex() > -1:
+ mi.series = unicode(self.series.currentText())
+ tags = [t.strip() for t in unicode(self.tags.text()).split(',')]
+ if tags:
+ mi.tags = tags
+
+ return mi
+
+ def read_settings(self):
+ for pref in self.config.option_set.preferences:
+ g = getattr(self, 'opt_'+pref.name, False)
+ if g:
+ if isinstance(g, (QSpinBox, QDoubleSpinBox)):
+ self.config.set(pref.name, g.value())
+ elif isinstance(g, (QLineEdit, QTextEdit)):
+ func = getattr(g, 'toPlainText', getattr(g, 'text', None))()
+ val = unicode(func)
+ self.config.set(pref.name, val if val else None)
+ elif isinstance(g, QComboBox):
+ self.config.set(pref.name, unicode(g.currentText()))
+ elif isinstance(g, QCheckBox):
+ self.config.set(pref.name, bool(g.isChecked()))
+ if self.row is not None:
+ self.db.set_conversion_options(self.id, 'epub', self.config.src)
+
+
+ def initialize_options(self):
+ self.initialize_metadata_options()
+ values = self.config.parse()
+ for pref in self.config.option_set.preferences:
+ g = getattr(self, 'opt_'+pref.name, False)
+ if g:
+ val = getattr(values, pref.name)
+ if val is None:
+ continue
+ if isinstance(g, (QSpinBox, QDoubleSpinBox)):
+ g.setValue(val)
+ elif isinstance(g, (QLineEdit, QTextEdit)):
+ getattr(g, 'setPlainText', g.setText)(val)
+ elif isinstance(g, QComboBox):
+ for value in pref.choices:
+ g.addItem(value)
+ g.setCurrentIndex(g.findText(val))
+ elif isinstance(g, QCheckBox):
+ g.setCheckState(Qt.Checked if bool(val) else Qt.Unchecked)
+
+
+ def get_source_format(self):
+ self.source_format = None
+ if self.row is not None:
+ temp = self.db.formats(self.id, index_is_id=True)
+ if not temp:
+ error_dialog(self.parent(), _('Cannot convert'),
+ _('This book has no available formats')).exec_()
+
+ available_formats = [f.upper().strip() for f in temp.split(',')]
+ choices = [fmt.upper() for fmt in SOURCE_FORMATS if fmt.upper() in available_formats]
+ if not choices:
+ error_dialog(self.parent(), _('No available formats'),
+ _('Cannot convert %s as this book has no supported formats')%(self.title.text())).exec_()
+ elif len(choices) == 1:
+ self.source_format = choices[0]
+ else:
+ d = ChooseFormatDialog(self.parent(), _('Choose the format to convert to EPUB'), choices)
+ if d.exec_() == QDialog.Accepted:
+ self.source_format = d.format()
+
+ def accept(self):
+ mi = self.get_metadata()
+ self.read_settings()
+ self.cover_file = None
+ if self.row is not None:
+ self.db.set_metadata(self.id, mi)
+ self.mi = self.db.get_metadata(self.id, index_is_id=True)
+ opf = OPFCreator(os.getcwdu(), self.mi)
+ self.opf_file = PersistentTemporaryFile('.opf')
+ opf.render(self.opf_file)
+ self.opf_file.close()
+ if self.cover_changed:
+ self.db.set_cover(self.id, pixmap_to_data(self.cover.pixmap()))
+ cover = self.db.cover(self.id, index_is_id=True)
+ if cover:
+ cf = PersistentTemporaryFile('.jpeg')
+ cf.write(cover)
+ cf.close()
+ self.cover_file = cf
+ self.opts = self.config.parse()
+ QDialog.accept(self)
+
+
\ No newline at end of file
diff --git a/src/calibre/gui2/dialogs/epub.ui b/src/calibre/gui2/dialogs/epub.ui
new file mode 100644
index 0000000000..32d0d40252
--- /dev/null
+++ b/src/calibre/gui2/dialogs/epub.ui
@@ -0,0 +1,735 @@
+%s
')%(len(res), len(rows), '\n'.join(res))
- warning_dialog(self, _('Could not convert some books'), msg).exec_()
-
def convert_bulk(self, checked):
- comics, others = self.get_books_for_conversion()
- if others:
- self.convert_bulk_others(others)
- if comics:
- opts = ComicConf.get_bulk_conversion_options(self)
- if opts:
- for i, row in enumerate(comics):
- options = opts.copy()
- mi = self.library_view.model().db.get_metadata(row)
- if mi.title:
- options.title = mi.title
- if mi.authors:
- options.author = ','.join(mi.authors)
- data = None
- for fmt in ['cbz', 'cbr']:
- try:
- data = self.library_view.model().db.format(row, fmt.upper())
- if data:
- break
- except:
- continue
-
- pt = PersistentTemporaryFile('.'+fmt.lower())
- pt.write(data)
- pt.close()
- of = PersistentTemporaryFile('.lrf')
- of.close()
- setattr(options, 'output', of.name)
- options.verbose = 1
- args = [pt.name, options]
- job = self.job_manager.run_job(Dispatcher(self.book_converted),
- 'comic2lrf', args=args,
- description=_('Convert comic %d of %d (%s)')%(i+1, len(comics), repr(options.title)))
- self.conversion_jobs[job] = (None, pt, of, 'lrf',
- self.library_view.model().db.id(row))
-
-
- def set_conversion_defaults(self, checked):
- d = LRFSingleDialog(self, None, None)
- d.exec_()
+ r = self.get_books_for_conversion()
+ if r is None:
+ return
+ comics, others = r
- def set_comic_conversion_defaults(self, checked):
- ComicConf.set_conversion_defaults(self)
-
- def convert_single_others(self, rows):
- changed = False
- for row in rows:
- d = LRFSingleDialog(self, self.library_view.model().db, row)
- if d.selected_format:
- d.exec_()
- if d.result() == QDialog.Accepted:
- cmdline = d.cmdline
- data = self.library_view.model().db.format(row, d.selected_format)
- pt = PersistentTemporaryFile('.'+d.selected_format.lower())
- pt.write(data)
- pt.close()
- of = PersistentTemporaryFile('.lrf')
- of.close()
- cmdline.extend(['-o', of.name])
- cmdline.append(pt.name)
- job = self.job_manager.run_job(Dispatcher(self.book_converted),
- 'any2lrf', args=[cmdline],
- description=_('Convert book: ')+d.title())
-
- self.conversion_jobs[job] = (d.cover_file, pt, of, d.output_format, d.id)
- changed = True
+ jobs, changed = convert_bulk_ebooks(self, self.library_view.model().db, comics, others)
+ for func, args, desc, fmt, id, temp_files in jobs:
+ job = self.job_manager.run_job(Dispatcher(self.book_converted),
+ func, args=args, description=desc)
+ self.conversion_jobs[job] = (temp_files, fmt, id)
+
if changed:
self.library_view.model().resort(reset=False)
self.library_view.model().research()
+
+ def set_conversion_defaults(self, checked):
+ set_conversion_defaults(False, self, self.library_view.model().db)
+ def set_comic_conversion_defaults(self, checked):
+ set_conversion_defaults(True, self, self.library_view.model().db)
def convert_single(self, checked):
- comics, others = self.get_books_for_conversion()
- if others:
- self.convert_single_others(others)
- changed = False
- db = self.library_view.model().db
- for row in comics:
- mi = db.get_metadata(row)
- title = author = _('Unknown')
- if mi.title:
- title = mi.title
- if mi.authors:
- author = ','.join(mi.authors)
- defaults = db.conversion_options(db.id(row), 'comic')
- opts, defaults = ComicConf.get_conversion_options(self, defaults, title, author)
- if defaults is not None:
- db.set_conversion_options(db.id(row), 'comic', defaults)
- if opts is None: continue
- for fmt in ['cbz', 'cbr']:
- try:
- data = db.format(row, fmt.upper())
- break
- except:
- continue
- pt = PersistentTemporaryFile('.'+fmt)
- pt.write(data)
- pt.close()
- of = PersistentTemporaryFile('.lrf')
- of.close()
- opts.output = of.name
- opts.verbose = 1
- args = [pt.name, opts]
- changed = True
+ r = self.get_books_for_conversion()
+ if r is None: return
+ comics, others = r
+ jobs, changed = convert_single_ebook(self, self.library_view.model().db, comics, others)
+ for func, args, desc, fmt, id, temp_files in jobs:
job = self.job_manager.run_job(Dispatcher(self.book_converted),
- 'comic2lrf', args=args,
- description=_('Convert comic: ')+opts.title)
- self.conversion_jobs[job] = (None, pt, of, 'lrf',
- self.library_view.model().db.id(row))
+ func, args=args, description=desc)
+ self.conversion_jobs[job] = (temp_files, fmt, id)
+
if changed:
self.library_view.model().resort(reset=False)
self.library_view.model().research()
def book_converted(self, job):
- cf, pt, of, fmt, book_id = self.conversion_jobs.pop(job)
+ temp_files, fmt, book_id = self.conversion_jobs.pop(job)
try:
if job.exception is not None:
self.job_exception(job)
return
- data = open(of.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)
finally:
- for f in (cf, of, pt):
+ for f in temp_files:
try:
if os.path.exists(f.name):
os.remove(f.name)
diff --git a/src/calibre/gui2/tools.py b/src/calibre/gui2/tools.py
new file mode 100644
index 0000000000..68d90f5228
--- /dev/null
+++ b/src/calibre/gui2/tools.py
@@ -0,0 +1,380 @@
+#!/usr/bin/env python
+__license__ = 'GPL v3'
+__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
+__docformat__ = 'restructuredtext en'
+
+'''
+Logic for setting up conversion jobs
+'''
+import os
+from PyQt4.Qt import QDialog
+
+from calibre.utils.config import prefs
+from calibre.gui2.dialogs.lrf_single import LRFSingleDialog, LRFBulkDialog
+from calibre.gui2.dialogs.epub import Config as EPUBConvert
+import calibre.gui2.dialogs.comicconf as ComicConf
+from calibre.gui2 import warning_dialog
+from calibre.ptempfile import PersistentTemporaryFile
+from calibre.ebooks.lrf import preferred_source_formats as LRF_PREFERRED_SOURCE_FORMATS
+from calibre.ebooks.metadata.opf import OPFCreator
+from calibre.ebooks.epub.from_any import SOURCE_FORMATS as EPUB_PREFERRED_SOURCE_FORMATS
+
+def convert_single_epub(parent, db, comics, others):
+ changed = False
+ jobs = []
+ for row in others:
+ temp_files = []
+ d = EPUBConvert(parent, db, row)
+ if d.source_format is not None:
+ d.exec_()
+ if d.result() == QDialog.Accepted:
+ opts = d.opts
+ data = db.format(row, d.source_format)
+ pt = PersistentTemporaryFile('.'+d.source_format.lower())
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.epub')
+ of.close()
+ opts.output = of.name
+ opts.from_opf = d.opf_file.name
+ opts.verbose = 2
+ args = [opts, pt.name]
+ if d.cover_file:
+ temp_files.append(d.cover_file)
+ opts.cover = d.cover_file.name
+ temp_files.extend([d.opf_file, pt, of])
+ jobs.append(('any2epub', args, _('Convert book: ')+d.mi.title,
+ 'EPUB', db.id(row), temp_files))
+ changed = True
+
+ for row in comics:
+ mi = db.get_metadata(row)
+ title = author = _('Unknown')
+ if mi.title:
+ title = mi.title
+ if mi.authors:
+ author = ','.join(mi.authors)
+ defaults = db.conversion_options(db.id(row), 'comic')
+ opts, defaults = ComicConf.get_conversion_options(parent, defaults, title, author)
+ if defaults is not None:
+ db.set_conversion_options(db.id(row), 'comic', defaults)
+ if opts is None: continue
+ for fmt in ['cbz', 'cbr']:
+ try:
+ data = db.format(row, fmt.upper())
+ break
+ except:
+ continue
+ pt = PersistentTemporaryFile('.'+fmt)
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.epub')
+ of.close()
+ opts.output = of.name
+ opts.verbose = 2
+ args = [pt.name, opts]
+ changed = True
+ jobs.append(('comic2epub', args, _('Convert comic: ')+opts.title,
+ 'EPUB', db.id(row), [pt, of]))
+
+ return jobs, changed
+
+
+
+def convert_single_lrf(parent, db, comics, others):
+ changed = False
+ jobs = []
+ for row in others:
+ temp_files = []
+ d = LRFSingleDialog(parent, db, row)
+ if d.selected_format:
+ d.exec_()
+ if d.result() == QDialog.Accepted:
+ cmdline = d.cmdline
+ data = db.format(row, d.selected_format)
+ pt = PersistentTemporaryFile('.'+d.selected_format.lower())
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.lrf')
+ of.close()
+ cmdline.extend(['-o', of.name])
+ cmdline.append(pt.name)
+ if d.cover_file:
+ temp_files.append(d.cover_file)
+ temp_files.extend([pt, of])
+ jobs.append(('any2lrf', [cmdline], _('Convert book: ')+d.title(),
+ 'LRF', db.id(row), temp_files))
+ changed = True
+
+ for row in comics:
+ mi = db.get_metadata(row)
+ title = author = _('Unknown')
+ if mi.title:
+ title = mi.title
+ if mi.authors:
+ author = ','.join(mi.authors)
+ defaults = db.conversion_options(db.id(row), 'comic')
+ opts, defaults = ComicConf.get_conversion_options(parent, defaults, title, author)
+ if defaults is not None:
+ db.set_conversion_options(db.id(row), 'comic', defaults)
+ if opts is None: continue
+ for fmt in ['cbz', 'cbr']:
+ try:
+ data = db.format(row, fmt.upper())
+ break
+ except:
+ continue
+ pt = PersistentTemporaryFile('.'+fmt)
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.lrf')
+ of.close()
+ opts.output = of.name
+ opts.verbose = 1
+ args = [pt.name, opts]
+ changed = True
+ jobs.append(('comic2lrf', args, _('Convert comic: ')+opts.title,
+ 'LRF', db.id(row), [pt, of]))
+
+ return jobs, changed
+
+def convert_bulk_epub(parent, db, comics, others):
+ if others:
+ d = EPUBConvert(parent, db)
+ if d.exec_() != QDialog.Accepted:
+ others = []
+ else:
+ opts = d.opts
+ opts.verbose = 2
+ if comics:
+ comic_opts = ComicConf.get_bulk_conversion_options(parent)
+ if not comic_opts:
+ comics = []
+ bad_rows = []
+ jobs = []
+ total = sum(map(len, (others, comics)))
+ if total == 0:
+ return
+ parent.status_bar.showMessage(_('Starting Bulk conversion of %d books')%total, 2000)
+
+ for i, row in enumerate(others+comics):
+ if row in others:
+ data = None
+ for fmt in EPUB_PREFERRED_SOURCE_FORMATS:
+ try:
+ data = db.format(row, fmt.upper())
+ break
+ except:
+ continue
+ if data is None:
+ bad_rows.append(row)
+ continue
+ options = opts.copy()
+ mi = db.get_metadata(row)
+ opf = OPFCreator(os.getcwdu(), mi)
+ opf_file = PersistentTemporaryFile('.opf')
+ opf.render(opf_file)
+ opf_file.close()
+ pt = PersistentTemporaryFile('.'+fmt.lower())
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.epub')
+ of.close()
+ cover = db.cover(row)
+ cf = None
+ if cover:
+ cf = PersistentTemporaryFile('.jpeg')
+ cf.write(cover)
+ cf.close()
+ options.cover = cf.name
+ options.output = of.name
+ options.from_opf = opf_file.name
+ args = [options, pt.name]
+ desc = _('Convert book %d of %d (%s)')%(i+1, total, repr(mi.title))
+ temp_files = [cf] if cf is not None else []
+ temp_files.extend([opf_file, pt, of])
+ jobs.append(('any2epub', args, desc, 'EPUB', db.id(row), temp_files))
+ else:
+ options = comic_opts.copy()
+ mi = db.get_metadata(row)
+ if mi.title:
+ options.title = mi.title
+ if mi.authors:
+ options.author = ','.join(mi.authors)
+ data = None
+ for fmt in ['cbz', 'cbr']:
+ try:
+ data = db.format(row, fmt.upper())
+ if data:
+ break
+ except:
+ continue
+
+ pt = PersistentTemporaryFile('.'+fmt.lower())
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.epub')
+ of.close()
+ setattr(options, 'output', of.name)
+ options.verbose = 1
+ args = [pt.name, options]
+ desc = _('Convert book %d of %d (%s)')%(i+1, total, repr(mi.title))
+ jobs.append(('comic2epub', args, desc, 'EPUB', db.id(row), [pt, of]))
+
+ if bad_rows:
+ res = []
+ for row in bad_rows:
+ title = db.title(row)
+ res.append('%s
')%(len(res), total, '\n'.join(res))
+ warning_dialog(parent, _('Could not convert some books'), msg).exec_()
+
+ return jobs, False
+
+
+def convert_bulk_lrf(parent, db, comics, others):
+ if others:
+ d = LRFBulkDialog(parent)
+ if d.exec_() != QDialog.Accepted:
+ others = []
+ if comics:
+ comic_opts = ComicConf.get_bulk_conversion_options(parent)
+ if not comic_opts:
+ comics = []
+ bad_rows = []
+ jobs = []
+ total = sum(map(len, (others, comics)))
+ if total == 0:
+ return
+ parent.status_bar.showMessage(_('Starting Bulk conversion of %d books')%total, 2000)
+
+ for i, row in enumerate(others+comics):
+ if row in others:
+ cmdline = list(d.cmdline)
+ mi = db.get_metadata(row)
+ if mi.title:
+ cmdline.extend(['--title', mi.title])
+ if mi.authors:
+ cmdline.extend(['--author', ','.join(mi.authors)])
+ if mi.publisher:
+ cmdline.extend(['--publisher', mi.publisher])
+ if mi.comments:
+ cmdline.extend(['--comment', mi.comments])
+ data = None
+ for fmt in LRF_PREFERRED_SOURCE_FORMATS:
+ try:
+ data = db.format(row, fmt.upper())
+ break
+ except:
+ continue
+ if data is None:
+ bad_rows.append(row)
+ continue
+ pt = PersistentTemporaryFile('.'+fmt.lower())
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.lrf')
+ of.close()
+ cover = db.cover(row)
+ cf = None
+ if cover:
+ cf = PersistentTemporaryFile('.jpeg')
+ cf.write(cover)
+ cf.close()
+ cmdline.extend(['--cover', cf.name])
+ cmdline.extend(['-o', of.name])
+ cmdline.append(pt.name)
+ desc = _('Convert book %d of %d (%s)')%(i+1, total, repr(mi.title))
+ temp_files = [cf] if cf is not None else []
+ temp_files.extend([pt, of])
+ jobs.append(('any2lrf', [cmdline], desc, 'LRF', db.id(row), temp_files))
+ else:
+ options = comic_opts.copy()
+ mi = db.get_metadata(row)
+ if mi.title:
+ options.title = mi.title
+ if mi.authors:
+ options.author = ','.join(mi.authors)
+ data = None
+ for fmt in ['cbz', 'cbr']:
+ try:
+ data = db.format(row, fmt.upper())
+ if data:
+ break
+ except:
+ continue
+
+ pt = PersistentTemporaryFile('.'+fmt.lower())
+ pt.write(data)
+ pt.close()
+ of = PersistentTemporaryFile('.lrf')
+ of.close()
+ setattr(options, 'output', of.name)
+ options.verbose = 1
+ args = [pt.name, options]
+ desc = _('Convert book %d of %d (%s)')%(i+1, total, repr(mi.title))
+ jobs.append(('comic2lrf', args, desc, 'LRF', db.id(row), [pt, of]))
+
+ if bad_rows:
+ res = []
+ for row in bad_rows:
+ title = db.title(row)
+ res.append('%s
')%(len(res), total, '\n'.join(res))
+ warning_dialog(parent, _('Could not convert some books'), msg).exec_()
+
+ return jobs, False
+
+def set_conversion_defaults_lrf(comic, parent, db):
+ if comic:
+ ComicConf.set_conversion_defaults(parent)
+ else:
+ LRFSingleDialog(parent, None, None).exec_()
+
+def set_conversion_defaults_epub(comic, parent, db):
+ if comic:
+ ComicConf.set_conversion_defaults(parent)
+ else:
+ d = EPUBConvert(parent, db)
+ d.setWindowTitle(_('Set conversion defaults'))
+ d.exec_()
+
+
+def _fetch_news(data, fmt):
+ pt = PersistentTemporaryFile(suffix='_feeds2%s.%s'%(fmt.lower(), fmt.lower()))
+ pt.close()
+ args = ['feeds2%s'%fmt.lower(), '--output', pt.name, '--debug']
+ if data['username']:
+ args.extend(['--username', data['username']])
+ if data['password']:
+ args.extend(['--password', data['password']])
+ args.append(data['script'] if data['script'] else data['title'])
+ return 'feeds2'+fmt.lower(), [args], _('Fetch news from ')+data['title'], fmt.upper(), [pt]
+
+
+def convert_single_ebook(*args):
+ fmt = prefs['output_format'].lower()
+ if fmt == 'lrf':
+ return convert_single_lrf(*args)
+ elif fmt == 'epub':
+ return convert_single_epub(*args)
+
+def convert_bulk_ebooks(*args):
+ fmt = prefs['output_format'].lower()
+ if fmt == 'lrf':
+ return convert_bulk_lrf(*args)
+ elif fmt == 'epub':
+ return convert_bulk_epub(*args)
+
+def set_conversion_defaults(comic, parent, db):
+ fmt = prefs['output_format'].lower()
+ if fmt == 'lrf':
+ return set_conversion_defaults_lrf(comic, parent, db)
+ elif fmt == 'epub':
+ return set_conversion_defaults_epub(comic, parent, db)
+
+def fetch_news(data):
+ fmt = prefs['output_format'].lower()
+ return _fetch_news(data, fmt)
\ No newline at end of file
diff --git a/src/calibre/linux.py b/src/calibre/linux.py
index 6c7e390306..7a820d3cfa 100644
--- a/src/calibre/linux.py
+++ b/src/calibre/linux.py
@@ -443,7 +443,10 @@ def post_install():
from calibre.utils.config import config_dir
if os.path.exists(config_dir):
- shutil.rmtree(config_dir)
+ os.chdir(config_dir)
+ for f in os.listdir('.'):
+ if os.stat(f).st_uid == 0:
+ os.unlink(f)
VIEWER = '''\
diff --git a/src/calibre/parallel.py b/src/calibre/parallel.py
index 2cf1f50630..c8b8cd029f 100644
--- a/src/calibre/parallel.py
+++ b/src/calibre/parallel.py
@@ -54,6 +54,16 @@ PARALLEL_FUNCS = {
'comic2lrf' :
('calibre.ebooks.lrf.comic.convert_from', 'do_convert', {}, 'notification'),
+
+ 'any2epub' :
+ ('calibre.ebooks.epub.from_any', 'any2epub', {}, None),
+
+ 'feeds2epub' :
+ ('calibre.ebooks.epub.from_feeds', 'main', {}, 'notification'),
+
+ 'comic2epub' :
+ ('calibre.ebooks.epub.from_comic', 'convert', {}, 'notification'),
+
}
diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py
index 9aef6b1f66..8aa5ac7991 100644
--- a/src/calibre/utils/config.py
+++ b/src/calibre/utils/config.py
@@ -322,7 +322,7 @@ class OptionSet(object):
prefs = [pref for pref in self.preferences if pref.group == name]
lines = ['### Begin group: %s'%(name if name else 'DEFAULT')]
if desc:
- lines += map(lambda x: '# '+x for x in desc.split('\n'))
+ lines += map(lambda x: '# '+x, desc.split('\n'))
lines.append(' ')
for pref in prefs:
lines.append('# '+pref.name.replace('_', ' '))
@@ -522,6 +522,8 @@ def _prefs():
help=_('Path to directory in which your library of books is stored'))
c.add_opt('language', default=None,
help=_('The language in which to display the user interface'))
+ c.add_opt('output_format', default='LRF',
+ help=_('The default output format for ebook conversions.'))
c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
return c