-"""
- NEPI, a framework to manage network experiments
- Copyright (C) 2013 INRIA
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-"""
+#
+# NEPI, a framework to manage network experiments
+# Copyright (C) 2013 INRIA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+# Julien Tribino <julien.tribino@inria.fr>
from nepi.util.logger import Logger
-import sleekxmpp
-from sleekxmpp.exceptions import IqError, IqTimeout
+try:
+ import sleekxmpp
+ from sleekxmpp.exceptions import IqError, IqTimeout
+ class BaseOMFClient(sleekxmpp.ClientXMPP):
+ pass
+except ImportError:
+ msg = ("SleekXMPP is not installed. Without this library "
+ "you will be not able to use OMF Resources "
+ "if you want to install SleekXmpp: \n"
+ " git clone -b develop git://github.com/fritzy/SleekXMPP.git \n"
+ " cd SleekXMPP \n"
+ " sudo python setup.py install\n")
+
+ logger = Logger("BaseOMFClient")
+ logger.debug(msg)
+
+ class BaseOMFClient(object):
+ pass
+
import traceback
import xml.etree.ElementTree as ET
-# inherit from BaseXmpp and XMLStream classes
-class OMFClient(sleekxmpp.ClientXMPP, Logger):
+# inherit from BaseXmpp and XMLstream classes
+class OMFClient(BaseOMFClient, Logger):
"""
.. class:: Class Args :
:param jid: Jabber Id (= Xmpp Slice + Date)
- :type jid: Str
+ :type jid: str
:param password: Jabber Password (= Xmpp Password)
- :type password: Str
+ :type password: str
.. note::
"""
:param jid: Jabber Id (= Xmpp Slice + Date)
- :type jid: Str
+ :type jid: str
:param password: Jabber Password (= Xmpp Password)
- :type password: Str
+ :type password: str
"""
self._registered = True
except IqError as e:
msg = " Could not register account: %s" % e.iq['error']['text']
- selferror(msg)
+ self.error(msg)
except IqTimeout:
msg = " No response from server."
self.error(msg)
result = self['xep_0060'].get_nodes(self._server)
for item in result['disco_items']['items']:
msg = ' - %s' % str(item)
- self.info(msg)
+ self.debug(msg)
return result
except:
error = traceback.format_exc()
#self.boundjid.full)
for node in result['node']:
msg = ' - %s' % str(node)
- self.info(msg)
+ self.debug(msg)
return result
except:
error = traceback.format_exc()
:type node: str
"""
- self.debug(" Create Topic : " + node)
+ msg = " Create Topic : " + node
+ self.info(msg)
config = self['xep_0004'].makeForm('submit')
config.add_field(var='pubsub#node_type', value='leaf')
"""
msg = " Publish to Topic : " + node
- self.debug(msg)
+ self.info(msg)
try:
result = self['xep_0060'].publish(self._server,node,payload=data)
# id = result['pubsub']['publish']['item']['id']
data)
for item in result['pubsub']['items']['substanzas']:
msg = 'Retrieved item %s: %s' % (item['id'], tostring(item['payload']))
- self.info(msg)
+ self.debug(msg)
except:
error = traceback.format_exc()
msg = ' Could not retrieve item %s from topic %s\ntraceback:\n%s' \
try:
result = self['xep_0060'].retract(self._server, self.boundjid, data)
msg = ' Retracted item %s from topic %s' % (data, self.boundjid)
- self.info(msg)
+ self.debug(msg)
except:
error = traceback.format_exc()
msg = 'Could not retract item %s from topic %s\ntraceback:\n%s' \
try:
result = self['xep_0060'].purge(self._server, self.boundjid)
msg = ' Purged all items from topic %s' % self.boundjid
- self.info(msg)
+ self.debug(msg)
except:
error = traceback.format_exc()
msg = ' Could not purge items from topic %s\ntraceback:\n%s' \
result = self['xep_0060'].subscribe(self._server, node)
msg = ' Subscribed %s to topic %s' \
% (self.boundjid.user, node)
- self.info(msg)
- #self.debug(msg)
+ #self.info(msg)
+ self.debug(msg)
except:
error = traceback.format_exc()
msg = ' Could not subscribe %s to topic %s\ntraceback:\n%s' \
try:
result = self['xep_0060'].unsubscribe(self._server, node)
msg = ' Unsubscribed %s from topic %s' % (self.boundjid.bare, node)
- self.info(msg)
+ self.debug(msg)
except:
error = traceback.format_exc()
msg = ' Could not unsubscribe %s from topic %s\ntraceback:\n%s' \