OK, I am testing this now using calibre-debug -e script.py
Code:
def test():
from calibre.library import db as DB
from calibre.ebooks.metadata.book.formatter import SafeFormat
db = DB().new_api
book_id = list(db.all_book_ids())[0]
mi = db.get_proxy_metadata(book_id)
TEMPLATE_ERROR = 'TEMPLATE_ERROR: '
my_globals = {'path_to_file': '/home/user', 'b': 2}
template = "program: globals(path_to_file)"
template_output = SafeFormat().safe_format(template, mi, TEMPLATE_ERROR, mi, global_vars=my_globals)
print('debug: template_output: ({})'.format(template_output))
test()
the output is empty:
Code:
debug: template_output: ()
I don't know what I am doing wrong?