View Single Post
Old 12-17-2020, 02:58 PM   #118
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
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?
capink is offline   Reply With Quote