MCPcopy
hub / github.com/apache/caldera / Plugin

Class Plugin

app/objects/c_plugin.py:24–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24class Plugin(FirstClassObjectInterface, BaseObject):
25
26 schema = PluginSchema()
27 display_schema = PluginSchema(only=['name', 'description', 'enabled', 'address'])
28
29 @property
30 def unique(self):
31 return self.hash(self.name)
32
33 def __init__(self, name='virtual', description=None, address=None, enabled=False, data_dir=None, access=None):
34 super().__init__()
35 self.name = name
36 self.description = description
37 self.address = address
38 self.enabled = enabled
39 self.data_dir = data_dir
40 self.access = access if access else self.Access.APP
41
42 def store(self, ram):
43 existing = self.retrieve(ram['plugins'], self.unique)
44 if not existing:
45 ram['plugins'].append(self)
46 return self.retrieve(ram['plugins'], self.unique)
47 else:
48 existing.update('enabled', self.enabled)
49 return existing
50
51 def load_plugin(self):
52 try:
53 plugin = self._load_module()
54 self.description = plugin.description
55 self.address = plugin.address
56 self.access = getattr(self._load_module(), 'access', self.Access.APP)
57 return True
58 except Exception as e:
59 logging.error('Error loading plugin=%s, %s' % (self.name, e))
60 return False
61
62 async def enable(self, services):
63 try:
64 if os.path.exists('plugins/%s/data' % self.name.lower()):
65 self.data_dir = 'plugins/%s/data' % self.name.lower()
66 plugin = self._load_module().enable
67 await plugin(services)
68 self.enabled = True
69 except Exception as e:
70 logging.error('Error enabling plugin=%s, %s' % (self.name, e))
71
72 async def destroy(self, services):
73 if self.enabled:
74 destroyable = getattr(self._load_module(), 'destroy', None)
75 if destroyable:
76 await destroyable(services)
77
78 async def expand(self, services):
79 try:
80 if self.enabled:
81 expansion = getattr(self._load_module(), 'expansion', None)

Callers 7

_loadMethod · 0.90
loadMethod · 0.90
watch_ability_filesMethod · 0.90
_generate_pluginFunction · 0.90
test_load_payloadsMethod · 0.90
test_pluginFunction · 0.90
build_pluginMethod · 0.85

Calls 1

PluginSchemaClass · 0.85

Tested by 3

_generate_pluginFunction · 0.72
test_load_payloadsMethod · 0.72
test_pluginFunction · 0.72