From 89b4ccad2d6bc689ee7bc530f0d45f3a559ca71c Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Mon, 11 Sep 2023 14:53:12 +0200 Subject: [PATCH] WIP: enhance find_func of table_export --- src/caosadvancedtools/table_export.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/caosadvancedtools/table_export.py b/src/caosadvancedtools/table_export.py index 056207a7..e6b83be8 100644 --- a/src/caosadvancedtools/table_export.py +++ b/src/caosadvancedtools/table_export.py @@ -83,7 +83,7 @@ class BaseTableExporter(object): ``` {"entry_to_be_exported: { "optional": True/False - "find_func": name of member function + "find_func": callable or name of member function "query": query string "selector": selector for the query "error": error explanation @@ -97,8 +97,8 @@ class BaseTableExporter(object): - optional: True or False, if not present, the entry is assumed to be mandatory. - find_func: name of the member function that returns the - value for this entry. Must not exist together with - `query` + value for this entry or callable object. Must not exist + together with `query` - query: Query string for finding the value for this entry. If this is given, a record must be given to the constructor of this class. The query is then executed as @@ -163,7 +163,10 @@ class BaseTableExporter(object): else: self._append_missing(e, d) elif FIND_FUNCTION in d: - find_fun = getattr(self, d[FIND_FUNCTION]) + if callable(d[FIND_FUNCTION]): + find_fun = d[FIND_FUNCTION] + else + find_fun = getattr(self, d[FIND_FUNCTION]) try: self.info[e] = find_fun() except Exception as exc: @@ -287,7 +290,9 @@ class BaseTableExporter(object): # check find function if present if FIND_FUNCTION in d: - if not hasattr(self, d[FIND_FUNCTION]): + if callable(d[FIND_FUNCTION]): + pass + elif not hasattr(self, d[FIND_FUNCTION]): raise TableExportError( "Find function " + d[FIND_FUNCTION] + " was specified for entry " + e + -- GitLab