diff options
author | Nathan Lovato <nathan@gdquest.com> | 2019-09-05 18:22:37 +0300 |
---|---|---|
committer | Nathan Lovato <nathan@gdquest.com> | 2019-09-05 18:22:52 +0300 |
commit | 61d48c0a4be0ab8f71e6e1d35f0aa99c77fcfd33 (patch) | |
tree | f64d0ea88789184f45112b489598990d549788f2 /power_sequencer/utils/addon_auto_imports.py | |
parent | da5a1175e30c347fbce05e49e2f5f895be30bd5b (diff) |
Add the VSE addon Power Sequencer
Diffstat (limited to 'power_sequencer/utils/addon_auto_imports.py')
-rw-r--r-- | power_sequencer/utils/addon_auto_imports.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/power_sequencer/utils/addon_auto_imports.py b/power_sequencer/utils/addon_auto_imports.py new file mode 100644 index 00000000..e570f53c --- /dev/null +++ b/power_sequencer/utils/addon_auto_imports.py @@ -0,0 +1,72 @@ +# +# Copyright (C) 2016-2019 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors +# +# This file is part of Power Sequencer. +# +# Power Sequencer is free software: you can redistribute it and/or modify it under the terms of the +# GNU General Public License as published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Power Sequencer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with Power Sequencer. If +# not, see <https://www.gnu.org/licenses/>. +# +import pkgutil +import importlib + +reload_event = False + + +def setup_addon_modules(path, package_name, ignore_packages=[], ignore_modules=[]): + """ + Imports and reloads all modules in this addon. + + path -- __path__ from __init__.py + package_name -- __name__ from __init__.py + ignore_packages -- list of packages to ignore, + skips the package if the string is in the name + ignore_modules -- list of module_names to ignore, strings + skips the module if the string is in the name + """ + + def get_submodule_names(path=path[0], root=""): + module_names = [] + for ignore in ignore_packages: + if ignore in root: + return [] + for importer, module_name, is_package in pkgutil.iter_modules([path]): + skip_module = False + for ignore in ignore_modules: + if ignore in module_name: + skip_module = True + if skip_module: + continue + if is_package: + sub_path = path + "\\" + module_name + sub_root = root + module_name + "." + module_names.extend(get_submodule_names(sub_path, sub_root)) + else: + module_names.append(root + module_name) + return module_names + + def import_submodules(names): + modules = [] + for name in names: + modules.append(importlib.import_module("." + name, package_name)) + return modules + + def reload_modules(modules): + for module in modules: + importlib.reload(module) + + names = get_submodule_names() + modules = import_submodules(names) + if reload_event: + reload_modules(modules) + return modules + + +reload_event = True |