mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When downloading recipes from the GUI download the actual recipe in the worker process rather than doing it in the GUI
Makes for better logging in case of errors
This commit is contained in:
parent
f91b9c8e51
commit
57f3db82e0
@ -69,7 +69,23 @@ class RecipeInput(InputFormatPlugin):
|
||||
recipe.needs_subscription = False
|
||||
self.recipe_object = recipe(opts, log, self.report_progress)
|
||||
else:
|
||||
if os.access(recipe_or_file, os.R_OK):
|
||||
if os.environ.get('CALIBRE_RECIPE_URN'):
|
||||
from calibre.web.feeds.recipes.collection import get_custom_recipe, get_builtin_recipe_by_id
|
||||
urn = os.environ['CALIBRE_RECIPE_URN']
|
||||
log('Downloading recipe urn: ' + urn)
|
||||
rtype, recipe_id = urn.partition(':')[::2]
|
||||
if not recipe_id:
|
||||
raise ValueError('Invalid recipe urn: ' + urn)
|
||||
if rtype == 'custom':
|
||||
self.recipe_source = get_custom_recipe(recipe_id)
|
||||
else:
|
||||
self.recipe_source = get_builtin_recipe_by_id(urn)
|
||||
if not self.recipe_source:
|
||||
raise ValueError('Could not find recipe with urn: ' + urn)
|
||||
if not isinstance(self.recipe_source, bytes):
|
||||
self.recipe_source = self.recipe_source.encode('utf-8')
|
||||
recipe = compile_recipe(self.recipe_source)
|
||||
elif os.access(recipe_or_file, os.R_OK):
|
||||
self.recipe_source = open(recipe_or_file, 'rb').read()
|
||||
recipe = compile_recipe(self.recipe_source)
|
||||
log('Using custom recipe')
|
||||
|
@ -4,6 +4,7 @@ __license__ = 'GPL 3'
|
||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os
|
||||
from optparse import OptionParser
|
||||
|
||||
from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
||||
@ -26,6 +27,14 @@ def gui_convert(input, output, recommendations, notification=DummyReporter(),
|
||||
plumber.run()
|
||||
|
||||
|
||||
def gui_convert_recipe(input, output, recommendations, notification=DummyReporter(),
|
||||
abort_after_input_dump=False, log=None, override_input_metadata=False):
|
||||
os.environ['CALIBRE_RECIPE_URN'] = input
|
||||
gui_convert('from-gui.recipe', output, recommendations, notification=notification,
|
||||
abort_after_input_dump=abort_after_input_dump, log=log,
|
||||
override_input_metadata=override_input_metadata)
|
||||
|
||||
|
||||
def gui_convert_override(input, output, recommendations, notification=DummyReporter(),
|
||||
abort_after_input_dump=False, log=None):
|
||||
gui_convert(input, output, recommendations, notification=notification,
|
||||
@ -69,5 +78,3 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, sync, fmt_options, conne
|
||||
# Returns 0 if successful, 1 if no catalog built
|
||||
plugin = plugin_for_catalog_format(fmt)
|
||||
return plugin.run(out_file_name, opts, db, notification=notification)
|
||||
|
||||
|
||||
|
@ -22,7 +22,6 @@ from PyQt5.Qt import (
|
||||
from calibre.gui2 import config as gconf, error_dialog, gprefs
|
||||
from calibre.gui2.search_box import SearchBox2
|
||||
from calibre.web.feeds.recipes.model import RecipeModel
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils.date import utcnow
|
||||
from calibre.utils.network import internet_connected
|
||||
from calibre import force_unicode
|
||||
@ -654,16 +653,11 @@ class Scheduler(QObject):
|
||||
if account_info is not None:
|
||||
un, pw = account_info
|
||||
add_title_tag, custom_tags, keep_issues = customize_info
|
||||
script = self.recipe_model.get_recipe(urn)
|
||||
pt = PersistentTemporaryFile('_builtin.recipe')
|
||||
pt.write(script)
|
||||
pt.close()
|
||||
arg = {
|
||||
'username': un,
|
||||
'password': pw,
|
||||
'add_title_tag':add_title_tag,
|
||||
'custom_tags':custom_tags,
|
||||
'recipe':pt.name,
|
||||
'title':recipe.get('title',''),
|
||||
'urn':urn,
|
||||
'keep_issues':keep_issues
|
||||
|
@ -306,13 +306,13 @@ def fetch_scheduled_recipe(arg): # {{{
|
||||
for opt in p.options:
|
||||
recs.append((opt.option.name, pdf.get(opt.option.name, opt.recommended_value), OptionRecommendation.HIGH))
|
||||
|
||||
args = [arg['recipe'], pt.name, recs]
|
||||
args = [arg['urn'], pt.name, recs]
|
||||
if arg['username'] is not None:
|
||||
recs.append(('username', arg['username'], OptionRecommendation.HIGH))
|
||||
if arg['password'] is not None:
|
||||
recs.append(('password', arg['password'], OptionRecommendation.HIGH))
|
||||
|
||||
return 'gui_convert', args, _('Fetch news from %s')%arg['title'], fmt.upper(), [pt]
|
||||
return 'gui_convert_recipe', args, _('Fetch news from %s')%arg['title'], fmt.upper(), [pt]
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -35,6 +35,9 @@ PARALLEL_FUNCS = {
|
||||
'gui_convert' :
|
||||
('calibre.gui2.convert.gui_conversion', 'gui_convert', 'notification'),
|
||||
|
||||
'gui_convert_recipe' :
|
||||
('calibre.gui2.convert.gui_conversion', 'gui_convert_recipe', 'notification'),
|
||||
|
||||
'gui_polish' :
|
||||
('calibre.ebooks.oeb.polish.main', 'gui_polish', None),
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user