This commit is contained in:
Kovid Goyal 2017-06-12 22:37:09 +05:30
parent a3ac32b48a
commit f328f4d8eb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 10 additions and 6 deletions

View File

@ -20,6 +20,7 @@ from calibre.utils.localization import canonicalize_lang
readonly = False readonly = False
version = 0 # change this if you change signature of implementation() version = 0 # change this if you change signature of implementation()
def to_stream(data): def to_stream(data):
ans = BytesIO(data[1]) ans = BytesIO(data[1])
ans.name = data[0] ans.name = data[0]

View File

@ -25,6 +25,7 @@ from calibre.utils.localization import calibre_langcode_to_name
def bool_sort_key(bools_are_tristate): def bool_sort_key(bools_are_tristate):
return (lambda x:{True: 1, False: 2, None: 3}.get(x, 3)) if bools_are_tristate else lambda x:{True: 1, False: 2, None: 2}.get(x, 2) return (lambda x:{True: 1, False: 2, None: 3}.get(x, 3)) if bools_are_tristate else lambda x:{True: 1, False: 2, None: 2}.get(x, 2)
IDENTITY = lambda x: x IDENTITY = lambda x: x
@ -756,4 +757,3 @@ def create_field(name, table, bools_are_tristate, get_template_functions):
elif table.metadata['datatype'] == 'series': elif table.metadata['datatype'] == 'series':
cls = SeriesField cls = SeriesField
return cls(name, table, bools_are_tristate, get_template_functions) return cls(name, table, bools_are_tristate, get_template_functions)

View File

@ -1451,15 +1451,15 @@ class KOBOTOUCH(KOBO):
def open_linux(self): def open_linux(self):
super(KOBOTOUCH, self).open_linux() super(KOBOTOUCH, self).open_linux()
self.swap_drives_if_needed() self.swap_drives_if_needed()
def open_osx(self): def open_osx(self):
# Just dump some info to the logs. # Just dump some info to the logs.
super(KOBOTOUCH, self).open_osx() super(KOBOTOUCH, self).open_osx()
# Wrap some debugging output in a try/except so that it unlikely to break things completely. # Wrap some debugging output in a try/except so that it unlikely to break things completely.
try: try:
if DEBUG: if DEBUG:
from calibre.constants import plugins from calibre.constants import plugins
usbobserver, usbobserver_err = plugins['usbobserver'] usbobserver, usbobserver_err = plugins['usbobserver']

View File

@ -12,8 +12,7 @@ import re, string, traceback
from calibre import prints from calibre import prints
from calibre.constants import DEBUG from calibre.constants import DEBUG
from calibre.utils.formatter_functions import formatter_functions, compile_user_function from calibre.utils.formatter_functions import formatter_functions
from calibre.utils.config import tweaks
class _Parser(object): class _Parser(object):
@ -174,6 +173,7 @@ class _Parser(object):
else: else:
self.error(_('expression is not function or constant')) self.error(_('expression is not function or constant'))
class TemplateFormatter(string.Formatter): class TemplateFormatter(string.Formatter):
''' '''
Provides a format function that substitutes '' for any missing value Provides a format function that substitutes '' for any missing value

View File

@ -1635,6 +1635,7 @@ class UserFunction(FormatterUserFunction):
cls = locals_['UserFunction'](name, doc, arg_count, eval_func) cls = locals_['UserFunction'](name, doc, arg_count, eval_func)
return cls return cls
def compile_user_template_functions(funcs): def compile_user_template_functions(funcs):
compiled_funcs = {} compiled_funcs = {}
for func in funcs: for func in funcs:
@ -1653,6 +1654,7 @@ def compile_user_template_functions(funcs):
traceback.print_exc() traceback.print_exc()
return compiled_funcs return compiled_funcs
def load_user_template_functions(library_uuid, funcs, precompiled_user_functions=None): def load_user_template_functions(library_uuid, funcs, precompiled_user_functions=None):
unload_user_template_functions(library_uuid) unload_user_template_functions(library_uuid)
if precompiled_user_functions: if precompiled_user_functions:
@ -1661,5 +1663,6 @@ def load_user_template_functions(library_uuid, funcs, precompiled_user_functions
compiled_funcs = compile_user_template_functions(funcs) compiled_funcs = compile_user_template_functions(funcs)
formatter_functions().register_functions(library_uuid, compiled_funcs.values()) formatter_functions().register_functions(library_uuid, compiled_funcs.values())
def unload_user_template_functions(library_uuid): def unload_user_template_functions(library_uuid):
formatter_functions().unregister_functions(library_uuid) formatter_functions().unregister_functions(library_uuid)