summaryrefslogtreecommitdiff
path: root/src/daq/flumotion-plug/sfive.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/daq/flumotion-plug/sfive.py')
-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()