summaryrefslogtreecommitdiffstats
path: root/pyfirstaidkit
diff options
context:
space:
mode:
authorTomas Mlcoch <tmlcoch@redhat.com>2010-08-16 17:19:56 +0200
committerTomas Mlcoch <tmlcoch@redhat.com>2010-08-16 17:19:56 +0200
commite501f8a31b86eb8ec8d336dda80177a3b700028f (patch)
tree8b6fed6a943d1444bf70abeee06a4ee761fbd508 /pyfirstaidkit
parentdbaa7ea7278212a8d5ffa43193ea6038b5108a7e (diff)
downloadfirstaidkit-e501f8a31b86eb8ec8d336dda80177a3b700028f.tar.gz
firstaidkit-e501f8a31b86eb8ec8d336dda80177a3b700028f.tar.xz
firstaidkit-e501f8a31b86eb8ec8d336dda80177a3b700028f.zip
Add support for flow title in plugin.
Diffstat (limited to 'pyfirstaidkit')
-rw-r--r--pyfirstaidkit/plugins.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py
index 0fe3852..bf55df7 100644
--- a/pyfirstaidkit/plugins.py
+++ b/pyfirstaidkit/plugins.py
@@ -34,8 +34,9 @@ from cStringIO import StringIO
Logger = logging.getLogger("firstaidkit")
class Flow(dict):
- def __init__(self, rules, description="", *args, **kwargs):
+ def __init__(self, rules, description="", title="", *args, **kwargs):
self.description = description
+ self.title = title
dict.__init__(self, rules, *args, **kwargs)
@staticmethod
@@ -486,6 +487,7 @@ class PluginSystem(object):
self._deps = dependencies
self._interpret = interpret
self._plugins = {}
+ self._flow_titles = {}
for path in self._paths:
if not os.path.isdir(path):
@@ -544,11 +546,43 @@ class PluginSystem(object):
(m, str(e)), level = PLUGINSYSTEM, origin = self)
finally:
imp.release_lock()
-
+
+ #initialize gettext
+ trans = None
+ try:
+ import gettext
+ trans = gettext.translation('firstaidkit')
+ except Exception as e:
+ pass
+
+ #get flow titles from plugins
+ for m in self._plugins:
+ plugin = self.getplugin(m)
+ for flowname in plugin.getFlows():
+ flow = plugin.getFlow(flowname)
+
+ #we already have title
+ if flowname in self._flow_titles and self._flow_titles[flowname]:
+ continue
+
+ #get best title
+ gt = trans.lgettext(flowname) if trans else flowname
+ title = gt if gt != flowname else flow.title
+
+ self._flow_titles[flowname] = title
+
+ #set title for flow with no title
+ for flow, title in self._flow_titles.iteritems():
+ if not title:
+ self._flow_titles[flow] = flow
def list(self):
"""Return the list of imported plugins"""
return self._plugins.keys()
+
+ def get_title(self, flow):
+ """Return flow title"""
+ return self._flow_titles[flow]
def autorun(self, plugin, flow = None, dependencies = True):
"""Perform automated run of plugin with condition checking