mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Download latest version of recipes from the calibre server automatically. This allows recipe fixes to propagate to users without the need to update calibre
This commit is contained in:
parent
6678af3a25
commit
78ccdd75b2
@ -109,6 +109,8 @@ Pre/post processing of downloaded HTML
|
|||||||
|
|
||||||
.. automember:: BasicNewsRecipe.template_css
|
.. automember:: BasicNewsRecipe.template_css
|
||||||
|
|
||||||
|
.. automember:: BasicNewsRecipe.remove_javascript
|
||||||
|
|
||||||
.. automethod:: BasicNewsRecipe.preprocess_html
|
.. automethod:: BasicNewsRecipe.preprocess_html
|
||||||
|
|
||||||
.. automethod:: BasicNewsRecipe.postprocess_html
|
.. automethod:: BasicNewsRecipe.postprocess_html
|
||||||
@ -128,6 +130,12 @@ Convenience methods
|
|||||||
.. automethod:: BasicNewsRecipe.tag_to_string
|
.. automethod:: BasicNewsRecipe.tag_to_string
|
||||||
|
|
||||||
|
|
||||||
|
Miscellaneous
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. automember:: BasicNewsRecipe.requires_version
|
||||||
|
|
||||||
|
|
||||||
CustomIndexRecipe
|
CustomIndexRecipe
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
|
from calibre.constants import numeric_version
|
||||||
|
|
||||||
class RecipeInput(InputFormatPlugin):
|
class RecipeInput(InputFormatPlugin):
|
||||||
|
|
||||||
@ -51,7 +52,25 @@ class RecipeInput(InputFormatPlugin):
|
|||||||
else:
|
else:
|
||||||
title = getattr(opts, 'original_recipe_input_arg', recipe_or_file)
|
title = getattr(opts, 'original_recipe_input_arg', recipe_or_file)
|
||||||
title = os.path.basename(title).rpartition('.')[0]
|
title = os.path.basename(title).rpartition('.')[0]
|
||||||
recipe = compile_recipe(get_builtin_recipe_by_title(title, log))
|
raw = get_builtin_recipe_by_title(title, log=log, download_recipe=True)
|
||||||
|
builtin = False
|
||||||
|
try:
|
||||||
|
recipe = compile_recipe(raw)
|
||||||
|
if recipe.requires_version > numeric_version:
|
||||||
|
log.warn(
|
||||||
|
'Downloaded recipe needs calibre version at least: %s' % \
|
||||||
|
recipe.requires_version)
|
||||||
|
builtin = True
|
||||||
|
except:
|
||||||
|
log.exception('Failed to compile downloaded recipe. Falling '
|
||||||
|
'back to builtin one')
|
||||||
|
builtin = True
|
||||||
|
if builtin:
|
||||||
|
raw = get_builtin_recipe_by_title(title, log=log,
|
||||||
|
download_recipe=False)
|
||||||
|
recipe = compile_recipe(raw)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if recipe is None:
|
if recipe is None:
|
||||||
raise ValueError('%r is not a valid recipe file or builtin recipe' %
|
raise ValueError('%r is not a valid recipe file or builtin recipe' %
|
||||||
|
@ -46,6 +46,9 @@ class BasicNewsRecipe(Recipe):
|
|||||||
#: The author of this recipe
|
#: The author of this recipe
|
||||||
__author__ = __appname__
|
__author__ = __appname__
|
||||||
|
|
||||||
|
#: Minimum calibre version needed to use this recipe
|
||||||
|
requires_version = (0, 6, 0)
|
||||||
|
|
||||||
#: The language that the news is in. Must be an ISO-639 code either
|
#: The language that the news is in. Must be an ISO-639 code either
|
||||||
#: two or three characters long
|
#: two or three characters long
|
||||||
language = 'und'
|
language = 'und'
|
||||||
|
@ -14,6 +14,8 @@ from lxml import etree
|
|||||||
from lxml.builder import ElementMaker
|
from lxml.builder import ElementMaker
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
|
|
||||||
|
from calibre import browser
|
||||||
|
|
||||||
NS = 'http://calibre-ebook.com/recipe_collection'
|
NS = 'http://calibre-ebook.com/recipe_collection'
|
||||||
E = ElementMaker(namespace=NS, nsmap={None:NS})
|
E = ElementMaker(namespace=NS, nsmap={None:NS})
|
||||||
|
|
||||||
@ -88,10 +90,27 @@ def get_custom_recipe_collection(db):
|
|||||||
def get_builtin_recipe_titles():
|
def get_builtin_recipe_titles():
|
||||||
return [r.get('title') for r in get_builtin_recipe_collection()]
|
return [r.get('title') for r in get_builtin_recipe_collection()]
|
||||||
|
|
||||||
def get_builtin_recipe_by_title(title, log=None):
|
def download_builtin_recipe(urn):
|
||||||
|
br = browser()
|
||||||
|
return br.open('http://status.calibre-ebook.com/recipe/'+urn).read()
|
||||||
|
|
||||||
|
|
||||||
|
def get_builtin_recipe_by_title(title, log=None, download_recipe=False):
|
||||||
for x in get_builtin_recipe_collection():
|
for x in get_builtin_recipe_collection():
|
||||||
if x.get('title') == title:
|
if x.get('title') == title:
|
||||||
urn = x.get('id')[8:]
|
urn = x.get('id')[8:]
|
||||||
|
if download_recipe:
|
||||||
|
try:
|
||||||
|
if log is not None:
|
||||||
|
log('Trying to get latest version of recipe:', urn)
|
||||||
|
return download_builtin_recipe(urn)
|
||||||
|
except:
|
||||||
|
if log is None:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
else:
|
||||||
|
log.exception(
|
||||||
|
'Failed to download recipe, using builtin version')
|
||||||
return P('recipes/%s.recipe'%urn, data=True)
|
return P('recipes/%s.recipe'%urn, data=True)
|
||||||
|
|
||||||
class SchedulerConfig(object):
|
class SchedulerConfig(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user