Replace eval with getattr when loading plugin classes

This commit is contained in:
Nick Hall 2018-10-17 20:34:40 +01:00
parent 290815cba8
commit 77cc12a42e
6 changed files with 14 additions and 14 deletions

View File

@ -619,8 +619,8 @@ class ArgHandler:
#import of plugin failed
return
category = pdata.category
report_class = eval('mod.' + pdata.reportclass)
options_class = eval('mod.' + pdata.optionclass)
report_class = getattr(mod, pdata.reportclass)
options_class = getattr(mod, pdata.optionclass)
if category in (CATEGORY_BOOK, CATEGORY_CODE):
options_class(self.dbstate.db, name, category,
options_str_dict)
@ -668,8 +668,8 @@ class ArgHandler:
#import of plugin failed
return
category = pdata.category
tool_class = eval('mod.' + pdata.toolclass)
options_class = eval('mod.' + pdata.optionclass)
tool_class = getattr(mod, pdata.toolclass)
options_class = getattr(mod, pdata.optionclass)
tool.cli_tool(dbstate=self.dbstate,
name=name,
category=category,

View File

@ -100,9 +100,9 @@ class BookItem:
else:
self.category = book_categories[pdata.category]
mod = pmgr.load_plugin(pdata)
self.write_item = eval('mod.' + pdata.reportclass)
self.write_item = getattr(mod, pdata.reportclass)
self.name = pdata.id
oclass = eval('mod.' + pdata.optionclass)
oclass = getattr(mod, pdata.optionclass)
self.option_class = oclass(self.name, self.dbase)
self.option_class.load_previous_values()

View File

@ -2310,7 +2310,7 @@ def get_relationship_calculator(reinit=False, clocale=glocale):
# the loaded module is put in variable mod
mod = pmgr.load_plugin(plugin)
if mod:
__RELCALC_CLASS = eval('mod.' + plugin.relcalcclass)
__RELCALC_CLASS = getattr(mod, plugin.relcalcclass)
relation_translation_found = True
break
if not relation_translation_found and \

View File

@ -250,8 +250,8 @@ class PluginDialog(ManagedWindow):
active_handle = self.uistate.get_active('Person')
report(self.state, self.uistate,
self.state.db.get_person_from_handle(active_handle),
eval('mod.' + pdata.reportclass),
eval('mod.' + pdata.optionclass),
getattr(mod, pdata.reportclass),
getattr(mod, pdata.optionclass),
pdata.name, pdata.id,
pdata.category, pdata.require_active)
else:
@ -259,8 +259,8 @@ class PluginDialog(ManagedWindow):
tool.gui_tool(
dbstate = self.state,
user = User(uistate=self.uistate),
tool_class = eval('mod.' + pdata.toolclass),
options_class = eval('mod.' + pdata.optionclass),
tool_class = getattr(mod, pdata.toolclass),
options_class = getattr(mod, pdata.optionclass),
translated_name = pdata.name,
name = pdata.id,
category = pdata.category,

View File

@ -222,7 +222,7 @@ def run_quick_report_by_name_direct(report_name, database, document, handle):
d.open("")
mod = pmgr.load_plugin(report)
if mod:
reportfunc = eval('mod.' + report.runfunc)
reportfunc = getattr(mod, report.runfunc)
retval = reportfunc(database, d, handle)
d.close()
return retval
@ -246,7 +246,7 @@ def run_report(dbstate, uistate, category, handle, pdata, container=None,
if not mod:
print("QuickView Error: plugin does not load")
return
func = eval('mod.' + pdata.runfunc)
func = getattr(mod, pdata.runfunc)
if handle:
d = TextBufDoc(make_basic_stylesheet(), None, track=track)
d.dbstate = dbstate

View File

@ -251,7 +251,7 @@ class PlaceBaseView(ListView):
serv = self.mapservicedata[self.mapservice]
mod = pmgr.load_plugin(serv)
if mod:
servfunc = eval('mod.' + serv.mapservice)
servfunc = getattr(mod, serv.mapservice)
servfunc()(self.dbstate.db, places, self.uistate)
else:
print('Failed to load map plugin, see Plugin Manager')