| 34 | |
| 35 | |
| 36 | class PluginManager(object): |
| 37 | EMPTY_SENTINEL = object() |
| 38 | |
| 39 | def __init__(self, main_debugger): |
| 40 | self.plugins = load_plugins() |
| 41 | |
| 42 | # When some breakpoint is added for a given plugin it becomes active. |
| 43 | self.active_plugins = [] |
| 44 | |
| 45 | self.main_debugger = main_debugger |
| 46 | |
| 47 | def add_breakpoint(self, func_name, *args, **kwargs): |
| 48 | # add breakpoint for plugin |
| 49 | for plugin in self.plugins: |
| 50 | if hasattr(plugin, func_name): |
| 51 | func = getattr(plugin, func_name) |
| 52 | result = func(*args, **kwargs) |
| 53 | if result: |
| 54 | self.activate(plugin) |
| 55 | return result |
| 56 | return None |
| 57 | |
| 58 | def activate(self, plugin): |
| 59 | if plugin not in self.active_plugins: |
| 60 | self.active_plugins.append(plugin) |
| 61 | |
| 62 | # These are not a part of the API, rather, `add_breakpoint` should be used with `add_line_breakpoint` or `add_exception_breakpoint` |
| 63 | # which will call it for all plugins and then if it's valid it'll be activated. |
| 64 | # |
| 65 | # def add_line_breakpoint(self, py_db, type, canonical_normalized_filename, breakpoint_id, line, condition, expression, func_name, hit_condition=None, is_logpoint=False, add_breakpoint_result=None, on_changed_breakpoint_state=None): |
| 66 | # def add_exception_breakpoint(plugin, py_db, type, exception): |
| 67 | |
| 68 | def after_breakpoints_consolidated(self, py_db, canonical_normalized_filename, id_to_pybreakpoint, file_to_line_to_breakpoints): |
| 69 | for plugin in self.active_plugins: |
| 70 | plugin.after_breakpoints_consolidated(py_db, canonical_normalized_filename, id_to_pybreakpoint, file_to_line_to_breakpoints) |
| 71 | |
| 72 | def remove_exception_breakpoint(self, py_db, exception_type, exception): |
| 73 | """ |
| 74 | :param exception_type: 'django', 'jinja2' (can be extended) |
| 75 | """ |
| 76 | for plugin in self.active_plugins: |
| 77 | ret = plugin.remove_exception_breakpoint(py_db, exception_type, exception) |
| 78 | if ret: |
| 79 | return ret |
| 80 | |
| 81 | return None |
| 82 | |
| 83 | def remove_all_exception_breakpoints(self, py_db): |
| 84 | for plugin in self.active_plugins: |
| 85 | plugin.remove_all_exception_breakpoints(py_db) |
| 86 | |
| 87 | def get_breakpoints(self, py_db, breakpoint_type): |
| 88 | """ |
| 89 | :param breakpoint_type: 'django-line', 'jinja2-line' |
| 90 | """ |
| 91 | for plugin in self.active_plugins: |
| 92 | ret = plugin.get_breakpoints(py_db, breakpoint_type) |
| 93 | if ret: |
no outgoing calls
no test coverage detected