MCPcopy
hub / github.com/PokemonGoF/PokemonGo-Bot / PluginLoader

Class PluginLoader

pokemongo_bot/plugin_loader.py:10–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import shutil
9
10class PluginLoader(object):
11 folder_cache = []
12
13 def _get_correct_path(self, path):
14 extension = os.path.splitext(path)[1]
15
16 if extension == '.zip':
17 correct_path = path
18 else:
19 correct_path = os.path.dirname(path)
20
21 return correct_path
22
23 def load_plugin(self, plugin):
24 github_plugin = GithubPlugin(plugin)
25 if github_plugin.is_valid_plugin():
26 if not github_plugin.is_already_installed():
27 github_plugin.install()
28
29 correct_path = github_plugin.get_plugin_folder()
30
31 else:
32 correct_path = self._get_correct_path(plugin)
33
34 if correct_path not in self.folder_cache:
35 self.folder_cache.append(correct_path)
36 sys.path.append(correct_path)
37
38 def remove_path(self, path):
39 correct_path = self._get_correct_path(path)
40 sys.path.remove(correct_path)
41 self.folder_cache.remove(correct_path)
42
43 def get_class(self, namespace_class):
44 [namespace, class_name] = namespace_class.split('.')
45 my_module = importlib.import_module(namespace)
46 return getattr(my_module, class_name)
47
48class GithubPlugin(object):
49 PLUGINS_FOLDER = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'plugins')

Callers 5

init_configFunction · 0.90
__init__Method · 0.90
setUpMethod · 0.90
test_load_plugin_taskMethod · 0.90

Calls

no outgoing calls

Tested by 3

setUpMethod · 0.72
test_load_plugin_taskMethod · 0.72