Allowing controlling if trying to get missing resources from a plugin prints a traceback

This commit is contained in:
Kovid Goyal 2022-07-20 07:39:06 +05:30
parent a35ff73ced
commit ef6c2b439f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -28,7 +28,7 @@ from polyglot.builtins import itervalues, reload, string_or_bytes
# have non ASCII characters # have non ASCII characters
def get_resources(zfp, name_or_list_of_names): def get_resources(zfp, name_or_list_of_names, print_tracebacks_for_missing_resources=True):
''' '''
Load resources from the plugin zip file Load resources from the plugin zip file
@ -49,15 +49,16 @@ def get_resources(zfp, name_or_list_of_names):
try: try:
ans[name] = zf.read(name) ans[name] = zf.read(name)
except: except:
import traceback if print_tracebacks_for_missing_resources:
traceback.print_exc() import traceback
traceback.print_exc()
if len(names) == 1: if len(names) == 1:
ans = ans.pop(names[0], None) ans = ans.pop(names[0], None)
return ans return ans
def get_icons(zfp, name_or_list_of_names, plugin_name=''): def get_icons(zfp, name_or_list_of_names, plugin_name='', print_tracebacks_for_missing_resources=True):
''' '''
Load icons from the plugin zip file Load icons from the plugin zip file
@ -86,7 +87,7 @@ def get_icons(zfp, name_or_list_of_names, plugin_name=''):
else: else:
failed = set(namelist) failed = set(namelist)
if failed: if failed:
from_zfp = get_resources(zfp, list(failed)) from_zfp = get_resources(zfp, list(failed), print_tracebacks_for_missing_resources=print_tracebacks_for_missing_resources)
if from_zfp is None: if from_zfp is None:
from_zfp = {} from_zfp = {}
elif isinstance(from_zfp, string_or_bytes): elif isinstance(from_zfp, string_or_bytes):