1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 '''This module manages plugins and macro code. The difference is that
22 macros are loaded dynamically and plugins are loaded from files. Macros tend
23 to be shorter snippets executed once while plugins are loaded into memory and
24 interact with the core.'''
25
26 import sys, traceback
27
31
33 '''Load a Python plugin. It needs to be on the path (ie: in the plugins dir)
34 A plugin is simply a module with a setup function. Variables are set in the module
35 for the view, config, eventBus, actions list and pluginManager before setup
36 is called'''
37 try:
38 plugin = self.__MyImport(pluginName)
39 except:
40 traceback.print_exc()
41 print "-" * 40 + "\n\nError Loading %s" % pluginName
42 return
43 plugin.pallavi = self.pallavi
44 plugin.pluginManager = self
45 plugin.config = self.pallavi.config
46 plugin.eventBus = self.pallavi.eventBus
47 plugin.actions = self.pallavi.actions
48 plugin.setup()
49
51 '''Load a list of plugins. The list should be of names of python modules in
52 the path (normally the plugins dir).'''
53 for plugin in pluginList:
54 self.LoadPlugin(plugin)
55
57 '''Load a list of plugins. The list should be names of python modules in the
58 pallavi.plugins directory. For example, to load the plugin
59 pallavi.plugins.Default_Keybinding, the list should contain 'Default_Keybinding';
60 the prefix will be prepended automatically.'''
61 newlist = []
62 for plugin in pluginList:
63 newlist.append("pallavi.plugins." + plugin)
64 self.LoadPlugins(newlist)
65
67 '''Execute an arbitrary string. These variables will be defined:
68
69 pallavi
70 config
71 pluginManager
72 eventBus
73 actions
74
75 Note: This method is extremely unsafe. It allows arbitrary Python code
76 to be executed, including possibly malicious code. However, Python has
77 no sandbox or safeguards, the restricted environment is broken, and
78 there is no way around this. IMHO, its better to provide the macro
79 functionality and accept the risks. I suppose we could add a config
80 option to disable macros if necessary. Or this simple functionality
81 could actually be moved into a plugin itself.'''
82 pallavi = self.pallavi
83 config = self.pallavi.config
84 pluginManager = self
85 eventBus = self.pallavi.eventBus
86 actions = self.pallavi.actions
87
88 try:
89 exec(string)
90 except Exception, ex:
91 print ex
92
94 '''Borrowed from python tutorial, does basic importing, I believe'''
95 mod = __import__(name)
96 components = name.split('.')
97 for comp in components[1:]:
98 mod = getattr(mod, comp)
99 return mod
100