From b0a2a305028bf284fc5dcf7e1a696d85787f128f Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Mon, 8 Nov 2010 00:59:14 +0100 Subject: Add the sleekxmpp library (will be added as a submodule later) --- sleekxmpp/plugins/jobs.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sleekxmpp/plugins/jobs.py (limited to 'sleekxmpp/plugins/jobs.py') diff --git a/sleekxmpp/plugins/jobs.py b/sleekxmpp/plugins/jobs.py new file mode 100644 index 0000000..c52e524 --- /dev/null +++ b/sleekxmpp/plugins/jobs.py @@ -0,0 +1,46 @@ +from . import base +import logging +from xml.etree import cElementTree as ET +import types + +class jobs(base.base_plugin): + def plugin_init(self): + self.xep = 'pubsubjob' + self.description = "Job distribution over Pubsub" + + def post_init(self): + pass + #TODO add event + + def createJobNode(self, host, jid, node, config=None): + pass + + def createJob(self, host, node, jobid=None, payload=None): + return self.xmpp.plugin['xep_0060'].setItem(host, node, ((jobid, payload),)) + + def claimJob(self, host, node, jobid, ifrom=None): + return self._setState(host, node, jobid, ET.Element('{http://andyet.net/protocol/pubsubjob}claimed')) + + def unclaimJob(self, host, node, jobid): + return self._setState(host, node, jobid, ET.Element('{http://andyet.net/protocol/pubsubjob}unclaimed')) + + def finishJob(self, host, node, jobid, payload=None): + finished = ET.Element('{http://andyet.net/protocol/pubsubjob}finished') + if payload is not None: + finished.append(payload) + return self._setState(host, node, jobid, finished) + + def _setState(self, host, node, jobid, state, ifrom=None): + iq = self.xmpp.Iq() + iq['to'] = host + if ifrom: iq['from'] = ifrom + iq['type'] = 'set' + iq['psstate']['node'] = node + iq['psstate']['item'] = jobid + iq['psstate']['payload'] = state + result = iq.send() + if result is None or type(result) == types.BooleanType or result['type'] != 'result': + logging.error("Unable to change %s:%s to %s" % (node, jobid, state)) + return False + return True + -- cgit v1.2.3-70-g09d2