Chmod +x examples, and add shebang lines

This commit is contained in:
Lance Stout 2013-09-20 11:50:51 -07:00
parent b8b2f37e7b
commit cd2d25cf87
15 changed files with 77 additions and 58 deletions

29
examples/IoT_TestDevice.py Normal file → Executable file
View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SleekXMPP: The Sleek XMPP Library
@ -35,7 +36,7 @@ if sys.version_info < (3, 0):
setdefaultencoding('utf8')
else:
raw_input = input
from sleekxmpp.plugins.xep_0323.device import Device
#from sleekxmpp.exceptions import IqError, IqTimeout
@ -68,7 +69,7 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
else:
self.beServer=False
self.clientJID=clientJID
def testForRelease(self):
# todo thread safe
return self.releaseMe
@ -76,14 +77,14 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
def doReleaseMe(self):
# todo thread safe
self.releaseMe=True
def addDevice(self, device):
self.device=device
def session_start(self, event):
self.send_presence()
self.get_roster()
# tell your preffered friend that you are alive
# tell your preffered friend that you are alive
self.send_message(mto='jocke@jabber.sust.se', mbody=self.boundjid.bare +' is now online use xep_323 stanza to talk to me')
if not(self.beServer):
@ -96,7 +97,7 @@ class IoT_TestDevice(sleekxmpp.ClientXMPP):
msg.reply("Hi I am " + self.boundjid.full + " and I am on IP " + ip).send()
else:
logging.debug("got unknown message type %s", str(msg['type']))
class TheDevice(Device):
"""
This is the actual device object that you will use to get information from your real hardware
@ -112,8 +113,8 @@ class TheDevice(Device):
"""
self._set_momentary_timestamp(self._get_timestamp())
self.counter+=self.counter
self._add_field_momentary_data(self, "Temperature", self.counter)
self._add_field_momentary_data(self, "Temperature", self.counter)
if __name__ == '__main__':
# Setup the command line arguments.
@ -123,7 +124,7 @@ if __name__ == '__main__':
# python IoT_TestDevice.py -j "serverjid@yourdomain.com" -p "password" -n "TestIoT" --debug
#
# "client" an IoT device or other party that would like to get data from another device
optp = OptionParser()
# Output verbosity options.
@ -151,7 +152,7 @@ if __name__ == '__main__':
help="Another device to call for data on", default=None)
optp.add_option("-n", "--nodeid", dest="nodeid",
help="I am a device get ready to be called", default=None)
opts, args = optp.parse_args()
# Setup logging.
@ -162,7 +163,7 @@ if __name__ == '__main__':
opts.jid = raw_input("Username: ")
if opts.password is None:
opts.password = getpass.getpass("Password: ")
xmpp = IoT_TestDevice(opts.jid,opts.password)
xmpp.register_plugin('xep_0030')
@ -183,12 +184,12 @@ if __name__ == '__main__':
myDevice._add_field(name="Temperature", typename="numeric", unit="C");
myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});
xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10);
xmpp.beClientOrServer(server=True)
while not(xmpp.testForRelease()):
xmpp.connect()
xmpp.process(block=True)
xmpp.process(block=True)
logging.debug("lost connection")
if opts.sensorjid:
logging.debug("will try to call another device for data")
@ -196,7 +197,7 @@ if __name__ == '__main__':
xmpp.connect()
xmpp.process(block=True)
logging.debug("ready ending")
else:
print "noopp didn't happen"

0
examples/download_avatars.py Normal file → Executable file
View file

View file

@ -151,7 +151,7 @@ if __name__ == '__main__':
#
# if xmpp.connect(('talk.google.com', 5222)):
# ...
xmpp.process(block=True)
xmpp.process(block=False)
print("Done")
else:
print("Unable to connect.")

3
examples/migrate_roster.py Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import logging
import getpass

7
examples/pubsub_client.py Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import logging
import getpass
@ -20,7 +23,7 @@ else:
class PubsubClient(sleekxmpp.ClientXMPP):
def __init__(self, jid, password, server,
def __init__(self, jid, password, server,
node=None, action='list', data=''):
super(PubsubClient, self).__init__(jid, password)
@ -28,7 +31,7 @@ class PubsubClient(sleekxmpp.ClientXMPP):
self.register_plugin('xep_0059')
self.register_plugin('xep_0060')
self.actions = ['nodes', 'create', 'delete',
self.actions = ['nodes', 'create', 'delete',
'publish', 'get', 'retract',
'purge', 'subscribe', 'unsubscribe']

5
examples/pubsub_events.py Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import logging
import getpass
@ -77,7 +80,7 @@ class PubsubEvents(sleekxmpp.ClientXMPP):
"""Handle receiving a node deletion event."""
print('Deleted node %s' % (
msg['pubsub_event']['delete']['node']))
def _config(self, msg):
"""Handle receiving a node configuration event."""
print('Configured node %s:' % (

0
examples/register_account.py Normal file → Executable file
View file

0
examples/roster_browser.py Normal file → Executable file
View file

29
examples/rpc_async.py Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Dann Martens
@ -11,34 +14,34 @@ from sleekxmpp.plugins.xep_0009.remote import Endpoint, remote, Remote, \
import time
class Boomerang(Endpoint):
def FQN(self):
return 'boomerang'
@remote
def throw(self):
print "Duck!"
def main():
session = Remote.new_session('kangaroo@xmpp.org/rpc', '*****')
session.new_handler(ANY_ALL, Boomerang)
session.new_handler(ANY_ALL, Boomerang)
boomerang = session.new_proxy('kangaroo@xmpp.org/rpc', Boomerang)
callback = Future()
boomerang.async(callback).throw()
time.sleep(10)
session.close()
if __name__ == '__main__':
main()

29
examples/rpc_client_side.py Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Dann Martens
@ -12,18 +15,18 @@ import threading
import time
class Thermostat(Endpoint):
def FQN(self):
return 'thermostat'
def __init__(self, initial_temperature):
self._temperature = initial_temperature
self._event = threading.Event()
self._event = threading.Event()
@remote
def set_temperature(self, temperature):
return NotImplemented
@remote
def get_temperature(self):
return NotImplemented
@ -31,23 +34,23 @@ class Thermostat(Endpoint):
@remote(False)
def release(self):
return NotImplemented
def main():
session = Remote.new_session('operator@xmpp.org/rpc', '*****')
thermostat = session.new_proxy('thermostat@xmpp.org/rpc', Thermostat)
print("Current temperature is %s" % thermostat.get_temperature())
thermostat.set_temperature(20)
time.sleep(10)
session.close()
if __name__ == '__main__':
main()

31
examples/rpc_server_side.py Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Dann Martens
@ -11,42 +14,42 @@ from sleekxmpp.plugins.xep_0009.remote import Endpoint, remote, Remote, \
import threading
class Thermostat(Endpoint):
def FQN(self):
return 'thermostat'
def __init__(self, initial_temperature):
self._temperature = initial_temperature
self._event = threading.Event()
self._event = threading.Event()
@remote
def set_temperature(self, temperature):
print("Setting temperature to %s" % temperature)
self._temperature = temperature
@remote
def get_temperature(self):
return self._temperature
@remote(False)
def release(self):
self._event.set()
self._event.set()
def wait_for_release(self):
self._event.wait()
self._event.wait()
def main():
session = Remote.new_session('sleek@xmpp.org/rpc', '*****')
thermostat = session.new_handler(ANY_ALL, Thermostat, 18)
thermostat.wait_for_release()
session.close()
if __name__ == '__main__':
main()

0
examples/set_avatar.py Normal file → Executable file
View file

0
examples/thirdparty_auth.py Normal file → Executable file
View file

0
examples/user_location.py Normal file → Executable file
View file

0
examples/user_tune.py Normal file → Executable file
View file