From aead85270dbeb3db62c07b762ebfcd9381e41e51 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 11 Oct 2014 17:38:38 +0200 Subject: added a check for simplejson existance --- src/daq/flumotion-plug/sfive.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/daq') 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() -- cgit v1.2.3