1 import Ganga.Utility.logging
2 logger = Ganga.Utility.logging.getLogger()
3
6
7
8
9
10
11
12
13
14
15
18 self.all_dict = {}
19 self.first = {}
20
21 - def find(self,category,name):
22 """
23 Return a plugin added with 'name' in the given 'category'.
24 If 'name' is None then the default plugin in the category is returned.
25 Typically the default plugin is the first added.
26 If plugin not found raise PluginManagerError.
27 """
28 try:
29 if name is None:
30 return self.first[category]
31 else:
32 return self.all_dict[category][name]
33 except KeyError:
34 if name is None:
35 s = "cannot find default plugin for category "+category
36 else:
37 s = "cannot find '%s' in a category '%s'" %(name,category)
38
39 logger.debug(s)
40 raise PluginManagerError(s)
41
42 - def add(self,pluginobj,category,name):
43 """ Add a pluginobj to the plugin manager with the name and the category labels.
44 The first plugin is default unless changed explicitly.
45 """
46 cat = self.all_dict.setdefault(category,{})
47 self.first.setdefault(category,pluginobj)
48 cat[name] = pluginobj
49 logger.debug('adding plugin %s (category "%s") ' % (name,category))
50
52 """ Make the plugin 'name' be default in a given 'category'.
53 You must first add() the plugin object before calling this method. Otherwise
54 PluginManagerError is raised.
55 """
56 assert(not name is None)
57 pluginobj = self.find(category,name)
58 self.first[category] = pluginobj
59
60
63
65 cat = self.all_dict.get(category)
66 if cat:
67 return cat
68 else:
69 return {}
70
71 allPlugins = PluginManager()
72