mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
News download now works
This commit is contained in:
parent
e58c5eb50f
commit
5f0c27e6d6
@ -100,18 +100,23 @@ def available_width():
|
||||
def extension(path):
|
||||
return os.path.splitext(path)[1][1:].lower()
|
||||
|
||||
def warning_dialog(parent, title, msg, det_msg=''):
|
||||
def warning_dialog(parent, title, msg, det_msg='', show=False):
|
||||
d = QMessageBox(QMessageBox.Warning, 'WARNING: '+title, msg, QMessageBox.Ok,
|
||||
parent)
|
||||
d.setDetailedText(det_msg)
|
||||
d.setIconPixmap(QPixmap(':/images/dialog_warning.svg'))
|
||||
|
||||
if show:
|
||||
return d.exec_()
|
||||
return d
|
||||
|
||||
def error_dialog(parent, title, msg, det_msg=''):
|
||||
def error_dialog(parent, title, msg, det_msg='', show=False):
|
||||
d = QMessageBox(QMessageBox.Critical, 'ERROR: '+title, msg, QMessageBox.Ok,
|
||||
parent)
|
||||
d.setDetailedText(det_msg)
|
||||
d.setIconPixmap(QPixmap(':/images/dialog_error.svg'))
|
||||
if show:
|
||||
return d.exec_()
|
||||
return d
|
||||
|
||||
def question_dialog(parent, title, msg, det_msg=''):
|
||||
@ -121,13 +126,16 @@ def question_dialog(parent, title, msg, det_msg=''):
|
||||
d.setIconPixmap(QPixmap(':/images/dialog_information.svg'))
|
||||
return d
|
||||
|
||||
def info_dialog(parent, title, msg, det_msg=''):
|
||||
def info_dialog(parent, title, msg, det_msg='', show=False):
|
||||
d = QMessageBox(QMessageBox.Information, title, msg, QMessageBox.NoButton,
|
||||
parent)
|
||||
d.setDetailedText(det_msg)
|
||||
d.setIconPixmap(QPixmap(':/images/dialog_information.svg'))
|
||||
if show:
|
||||
return d.exec_()
|
||||
return d
|
||||
|
||||
|
||||
def qstring_to_unicode(q):
|
||||
return unicode(q)
|
||||
|
||||
|
@ -530,8 +530,8 @@ class DeviceGUI(object):
|
||||
])
|
||||
error_dialog(self, _('Failed to email books'),
|
||||
_('Failed to email the following books:'),
|
||||
'%s'%errors,
|
||||
show=True)
|
||||
'%s'%errors
|
||||
)
|
||||
else:
|
||||
self.status_bar.showMessage(_('Sent by email:') + ', '.join(good),
|
||||
5000)
|
||||
|
@ -20,6 +20,7 @@ from calibre.utils.search_query_parser import SearchQueryParser
|
||||
from calibre.utils.pyparsing import ParseException
|
||||
from calibre.gui2 import NONE, error_dialog, config as gconf
|
||||
from calibre.utils.config import DynamicConfig
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.gui2.dialogs.user_profiles import UserProfiles
|
||||
|
||||
config = DynamicConfig('scheduler')
|
||||
@ -522,8 +523,12 @@ class Scheduler(QObject):
|
||||
self.recipes.remove(recipe)
|
||||
save_recipes(self.recipes)
|
||||
return
|
||||
pt = PersistentTemporaryFile('_builtin.recipe')
|
||||
pt.write(script)
|
||||
pt.close()
|
||||
script = pt.name
|
||||
except ValueError:
|
||||
script = recipe.title
|
||||
script = recipe.title + '.recipe'
|
||||
self.debug('\tQueueing:', recipe)
|
||||
self.main.download_scheduled_recipe(recipe, script, self.recipe_downloaded)
|
||||
self.queue.add(recipe)
|
||||
|
@ -856,10 +856,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
_('Failed to download metadata for the following:'),
|
||||
details, self).exec_()
|
||||
else:
|
||||
err = _('<b>Failed to download metadata:')+\
|
||||
'</b><br><pre>'+x.tb+'</pre>'
|
||||
error_dialog(self, _('Error'), err,
|
||||
show=True)
|
||||
err = _('Failed to download metadata:')
|
||||
error_dialog(self, _('Error'), err, det_msg=x.tb).exec_()
|
||||
|
||||
|
||||
|
||||
@ -1414,8 +1412,9 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
return
|
||||
if isinstance(job.exception, JobKilled):
|
||||
return
|
||||
error_dialog(self, _('Conversion Error'), job.gui_text(),
|
||||
show=True)
|
||||
error_dialog(self, _('Conversion Error'),
|
||||
_('Failed to process')+': '+unicode(job.description),
|
||||
det_msg=job.console_text()).exec_()
|
||||
|
||||
|
||||
def initialize_database(self):
|
||||
|
@ -7,6 +7,7 @@ from PyQt4.Qt import QMainWindow, QString, Qt, QFont, QCoreApplication, SIGNAL,\
|
||||
QAction, QMenu, QMenuBar, QIcon
|
||||
from calibre.gui2.dialogs.conversion_error import ConversionErrorDialog
|
||||
from calibre.utils.config import OptionParser
|
||||
from calibre.gui2 import error_dialog
|
||||
|
||||
def option_parser(usage='''\
|
||||
Usage: %prog [options]
|
||||
@ -79,9 +80,8 @@ class MainWindow(QMainWindow):
|
||||
traceback.print_exception(type, value, tb, file=sio)
|
||||
fe = sio.getvalue()
|
||||
print >>sys.stderr, fe
|
||||
msg = '<p><b>' + unicode(str(value), 'utf8', 'replace') + '</b></p>'
|
||||
msg += '<p>Detailed <b>traceback</b>:<pre>'+fe+'</pre>'
|
||||
d = ConversionErrorDialog(self, _('ERROR: Unhandled exception'), msg)
|
||||
d.exec_()
|
||||
msg = unicode(str(value), 'utf8', 'replace')
|
||||
error_dialog(self, _('ERROR: Unhandled exception'), msg, det_msg=fe,
|
||||
show=True)
|
||||
except:
|
||||
pass
|
||||
|
@ -7,16 +7,16 @@ __docformat__ = 'restructuredtext en'
|
||||
Logic for setting up conversion jobs
|
||||
'''
|
||||
|
||||
import cPickle, os
|
||||
import cPickle
|
||||
|
||||
from PyQt4.Qt import QDialog
|
||||
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.gui2 import warning_dialog
|
||||
from calibre.gui2.convert import load_specifics
|
||||
from calibre.gui2.convert.single import NoSupportedInputFormats
|
||||
from calibre.gui2.convert.single import Config as SingleConfig
|
||||
from calibre.gui2.convert.bulk import BulkConfig
|
||||
from calibre.utils.config import prefs
|
||||
|
||||
def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format=None):
|
||||
changed = False
|
||||
@ -126,33 +126,18 @@ def convert_bulk_ebook(parent, db, book_ids, out_format=None):
|
||||
|
||||
return jobs, changed, bad
|
||||
|
||||
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 'fconvert_bulk_ebookseeds2'+fmt.lower(), [args], _('Fetch news from ')+data['title'], fmt.upper(), [pt]
|
||||
|
||||
|
||||
def fetch_scheduled_recipe(recipe, script):
|
||||
from calibre.gui2.dialogs.scheduler import config
|
||||
fmt = prefs['output_format'].lower()
|
||||
pt = PersistentTemporaryFile(suffix='_feeds2%s.%s'%(fmt.lower(), fmt.lower()))
|
||||
pt = PersistentTemporaryFile(suffix='_recipe_out.%s'%fmt.lower())
|
||||
pt.close()
|
||||
args = ['feeds2%s'%fmt.lower(), '--output', pt.name, '--debug']
|
||||
args = ['ebook-convert', script, pt.name, '-vv']
|
||||
if recipe.needs_subscription:
|
||||
x = config.get('recipe_account_info_%s'%recipe.id, False)
|
||||
if not x:
|
||||
raise ValueError(_('You must set a username and password for %s')%recipe.title)
|
||||
args.extend(['--username', x[0], '--password', x[1]])
|
||||
args.append(script)
|
||||
return 'feeds2'+fmt, [args], _('Fetch news from ')+recipe.title, fmt.upper(), [pt]
|
||||
|
||||
def fetch_news(data):
|
||||
fmt = prefs['output_format'].lower()
|
||||
return _fetch_news(data, fmt)
|
||||
return 'ebook-convert', [args], _('Fetch news from ')+recipe.title, fmt.upper(), [pt]
|
||||
|
||||
|
||||
|
@ -19,7 +19,6 @@ from calibre.gui2 import Application, ORG_NAME, APP_UID, choose_files, \
|
||||
info_dialog, error_dialog
|
||||
from calibre.ebooks.oeb.iterator import EbookIterator
|
||||
from calibre.ebooks import DRMError
|
||||
from calibre.gui2.dialogs.conversion_error import ConversionErrorDialog
|
||||
from calibre.constants import islinux
|
||||
from calibre.utils.config import Config, StringConfig
|
||||
from calibre.gui2.library import SearchBox
|
||||
@ -543,8 +542,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
if isinstance(worker.exception, DRMError):
|
||||
error_dialog(self, _('DRM Error'), _('<p>This book is protected by <a href="%s">DRM</a>')%'http://wiki.mobileread.com/wiki/DRM').exec_()
|
||||
else:
|
||||
ConversionErrorDialog(self, _('Could not open ebook'),
|
||||
_('<b>%s</b><br/><p>%s</p>')%(worker.exception, worker.traceback.replace('\n', '<br>')), show=True)
|
||||
error_dialog(self, _('Could not open ebook'),
|
||||
unicode(worker.exception), det_msg=worker.traceback, show=True)
|
||||
self.close_progress_indicator()
|
||||
else:
|
||||
self.metadata.show_opf(self.iterator.opf)
|
||||
|
Loading…
x
Reference in New Issue
Block a user