From f58e7ef95ef8de7748bf95b367fa1b5d6623c8d0 Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Sat, 3 Jan 2015 17:46:14 +0100 Subject: [PATCH] PyStache is not mandatory --- glances/core/glances_actions.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/glances/core/glances_actions.py b/glances/core/glances_actions.py index 6069e0e8..ee29fd61 100644 --- a/glances/core/glances_actions.py +++ b/glances/core/glances_actions.py @@ -19,13 +19,19 @@ """Manage on alert actions.""" -# Import system lib -from subprocess import Popen -import pystache - # Import Glances lib from glances.core.glances_logging import logger +# Import system lib +from subprocess import Popen +try: + import pystache +except ImportError: + logger.warning("PyStache lib not installed (action script with mustache will not work)") + pystache_tag = False +else: + pystache_tag = True + class GlancesActions(object): @@ -67,7 +73,10 @@ class GlancesActions(object): # Ran all actions in background for cmd in commands: # Replace {{arg}} by the dict one (Thk to {Mustache}) - cmd_full = pystache.render(cmd, mustache_dict) + if pystache_tag: + cmd_full = pystache.render(cmd, mustache_dict) + else: + cmd_full = cmd # Execute the action logger.info("Action triggered for {0} ({1}): {2}".format(stat_name, criticity, cmd_full)) logger.debug("Stats value for the trigger: {0}".format(mustache_dict))