|
21 | 21 | """
|
22 | 22 | Form action chooser
|
23 | 23 | """
|
| 24 | +#------------------------------------------------------------------------- |
| 25 | +# |
| 26 | +# Standard Python modules |
| 27 | +# |
| 28 | +#------------------------------------------------------------------------- |
| 29 | +import logging |
24 | 30 | import importlib.util
|
25 | 31 | import inspect
|
26 | 32 | import os
|
27 |
| -import gobject |
| 33 | +import sys |
| 34 | + |
| 35 | +LOG = logging.getLogger('.form') |
28 | 36 |
|
29 | 37 | #------------------------------------------------------------------------
|
30 | 38 | #
|
@@ -93,9 +101,19 @@ def __init__(self, dbstate, uistate, track, citation):
|
93 | 101 | # for security reasons provide the full path to the actions_module .py file
|
94 | 102 | full_path = os.path.join(os.path.dirname(__file__), '%s.py' % self.form_id)
|
95 | 103 | if os.path.exists(full_path):
|
96 |
| - spec = importlib.util.spec_from_file_location('form.action.', full_path) |
97 |
| - self.actions_module = importlib.util.module_from_spec(spec) |
98 |
| - spec.loader.exec_module(self.actions_module) |
| 104 | + # temporarily modify sys.path so that any import statements in the module get processed correctly |
| 105 | + sys.path.insert(0, os.path.dirname(__file__)) |
| 106 | + try: |
| 107 | + spec = importlib.util.spec_from_file_location('form.actions.%s' % self.form_id, full_path) |
| 108 | + self.actions_module = importlib.util.module_from_spec(spec) |
| 109 | + spec.loader.exec_module(self.actions_module) |
| 110 | + except (ValueError, ImportError, SyntaxError) as err: |
| 111 | + self.actions_module = None |
| 112 | + LOG.warning("Form plugin error (from '%s'): %s" |
| 113 | + % (self.form_id, err)) |
| 114 | + finally: |
| 115 | + # must make sure we restore sys.path |
| 116 | + sys.path.pop(0) |
99 | 117 |
|
100 | 118 | self.event = find_form_event(self.db, self.citation)
|
101 | 119 |
|
|
0 commit comments