summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-10-11 17:38:38 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-10-11 17:38:38 +0200
commitaead85270dbeb3db62c07b762ebfcd9381e41e51 (patch)
tree27d89316212ef08badf84ea9c73f921f68b1395c
parentchanged iso timeformat Z vs T (diff)
added a check for simplejson existance
-rw-r--r--src/daq/flumotion-plug/sfive.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/daq/flumotion-plug/sfive.py b/src/daq/flumotion-plug/sfive.py
index 5e48164..0f6abd5 100644
--- a/src/daq/flumotion-plug/sfive.py
+++ b/src/daq/flumotion-plug/sfive.py
@@ -32,13 +32,17 @@
import os
+try:
+ import simplejson as json
+except ImportError:
+ json = None
+
from flumotion.component.plugs import base
from flumotion.common import messages, i18n, log
from flumotion.common.poller import Poller
from twisted.internet import protocol, reactor
from socket import error as socket_error
-import simplejson as json
import datetime
from flumotion.common.i18n import N_
@@ -89,6 +93,9 @@ class ComponentSFivePlug(base.ComponentPlug):
self._sfivepoller = None
self._component = component
+ if not self._hasImport():
+ return
+
properties = self.args['properties']
self._socket = properties['socket']
self._hostname = properties['hostname']
@@ -106,6 +113,19 @@ class ComponentSFivePlug(base.ComponentPlug):
self._initSocket()
+ def _hasImport(self):
+ """Check simplejson availability"""
+ if not json:
+ m = messages.Warning(T_(N_(
+ "Cannot import module '%s'.\n"), 'simplejson'),
+ mid='simplejson-import-error')
+ m.add(T_(N_(
+ "The SFive plug for this component is disabled.")))
+ self._component.addMessage(m)
+ return False
+
+ return True
+
def stop(self, component):
if self._sfivepoller:
self._sfivepoller.stop()