Created
April 1, 2019 01:47
-
-
Save edsion1107/d26cf27c644ec38565e1eec01421257e to your computer and use it in GitHub Desktop.
一个插件化的简单示例。缺点:动态加载导致没有代码提示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Device(Serial, Transport): | |
INSTALL_RESULT_PATTERN = r"(Success|Failure|Error)\s?(.*)" | |
UNINSTALL_RESULT_PATTERN = r"(Success|Failure.*|.*Unknown package:.*)" | |
def __new__(cls, *args, **kwargs): | |
# s = importlib.import_module('.__init__', ['plugins']) | |
p = Path(__file__).parent.joinpath('plugins/dumpsys.py') | |
# s = importlib.util.spec_from_file_location('plugins', submodule_search_locations=[p]) | |
s = importlib.util.find_spec('.dumpsys', 'src.tmd.common.adb.plugins') | |
m = s.loader.load_module(s.name) | |
# m = importlib.util.module_from_spec(s) | |
print(repr(m)) | |
print(type(m)) | |
print(dir(m)) | |
print(m.__all__) | |
c = getattr(m, m.__all__[0]) | |
print(c) | |
cls.__bases__ += (c,) | |
print(cls.__bases__) | |
return object.__new__(cls) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment