Upload to builder support plus adding some hand tests
authorEd Page <eopage@byu.net>
Tue, 8 Dec 2009 04:20:37 +0000 (22:20 -0600)
committerEd Page <eopage@byu.net>
Tue, 8 Dec 2009 04:20:37 +0000 (22:20 -0600)
Makefile
hand_tests/generic.py [new file with mode: 0755]
hand_tests/params.py [new file with mode: 0755]
hand_tests/presence.py [new file with mode: 0755]

index cf97536..1bfbe22 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -64,6 +64,11 @@ package: $(OBJ)
        cp -R $(BUILD_PATH)/generic/* $(BUILD_PATH)/mer
        cd $(BUILD_PATH)/mer ; python builddeb.py mer
 
+upload: package
+       dput fremantle-extras-builder $(BUILD_PATH)/fremantle/$(PROJECT_NAME)*.changes
+       dput diablo-extras-builder $(BUILD_PATH)/diablo/$(PROJECT_NAME)*.changes
+       dput chinook-extras-builder $(BUILD_PATH)/chinook/$(PROJECT_NAME)*.changes
+
 lint: $(OBJ)
        $(foreach file, $(SOURCE), $(LINT) $(file) ; )
 
diff --git a/hand_tests/generic.py b/hand_tests/generic.py
new file mode 100755 (executable)
index 0000000..13fbe06
--- /dev/null
@@ -0,0 +1,182 @@
+#!/usr/bin/env python
+
+import sys
+
+import gobject
+import dbus.mainloop.glib
+dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+
+import telepathy
+
+
+def get_registry():
+       reg = telepathy.client.ManagerRegistry()
+       reg.LoadManagers()
+       return reg
+
+
+def get_connection_manager(reg):
+       cm = reg.GetManager('theonering')
+       return cm
+
+
+class Action(object):
+
+       def __init__(self):
+               self._action = None
+
+       def queue_action(self):
+               pass
+
+       def append_action(self, action):
+               assert self._action is None
+               self._action = action
+
+       def _on_done(self):
+               if self._action is None:
+                       return
+               self._action.queue_action()
+
+       def _on_error(self, error):
+               print error
+
+       def _on_generic_message(self, *args):
+               pass
+
+
+class QuitLoop(Action):
+
+       def __init__(self, loop):
+               super(QuitLoop, self).__init__()
+               self._loop = loop
+
+       def queue_action(self):
+               self._loop.quit()
+
+
+class DisplayParams(Action):
+
+       def __init__(self, cm):
+               super(DisplayParams, self).__init__()
+               self._cm = cm
+
+       def queue_action(self):
+               self._cm[telepathy.interfaces.CONN_MGR_INTERFACE].GetParameters(
+                       'sip',
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self, params):
+               super(DisplayParams, self)._on_done()
+               for name, flags, signature, default in params:
+                       print "%s (%s)" % (name, signature),
+
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REQUIRED:
+                               print "required",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REGISTER:
+                               print "register",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_SECRET:
+                               print "secret",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_DBUS_PROPERTY:
+                               print "dbus-property",
+                       if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_HAS_DEFAULT:
+                               print "has-default(%s)" % default,
+
+                       print ""
+
+
+class Connect(Action):
+
+       def __init__(self, cm, username, password, forward):
+               super(Connect, self).__init__()
+               self._cm = cm
+               self._conn = None
+               self._username = username
+               self._password = password
+               self._forward = forward
+
+       @property
+       def conn(self):
+               return self._conn
+
+       def queue_action(self):
+               self._cm[telepathy.server.CONNECTION_MANAGER].RequestConnection(
+                       'sip',
+                       {
+                               'username':  self._username,
+                               'password': self._password,
+                               'forward':  self._forward,
+                       },
+                       reply_handler = self._on_connection_requested,
+                       error_handler = self._on_error,
+               )
+
+       def _on_connection_requested(self, busName, objectPath):
+               self._conn = telepathy.client.Connection(busName, objectPath)
+               self._conn[telepathy.server.CONNECTION].connect_to_signal(
+                       'StatusChanged',
+                       self._on_change,
+               )
+               self._conn[telepathy.server.CONNECTION].Connect(
+                       reply_handler = self._on_generic_message,
+                       error_handler = self._on_error,
+               )
+
+       def _on_done(self):
+               super(Connect, self)._on_done()
+
+       def _on_change(self, status, reason):
+               if status == telepathy.constants.CONNECTION_STATUS_DISCONNECTED:
+                       print "Disconnected!"
+                       self._conn = None
+               elif status == telepathy.constants.CONNECTION_STATUS_CONNECTED:
+                       print "Connected"
+                       self._on_done()
+               else:
+                       print "Status: %r" % status
+
+
+class Disconnect(Action):
+
+       def __init__(self, connAction):
+               super(Disconnect, self).__init__()
+               self._connAction = connAction
+
+       def queue_action(self):
+               self._connAction.conn[telepathy.server.CONNECTION].Disconnect(
+                       reply_handler = self._on_done,
+                       error_handler = self._on_error,
+               )
+
+
+if __name__ == '__main__':
+       loop = gobject.MainLoop()
+
+       reg = get_registry()
+       cm = get_connection_manager(reg)
+
+       dummy = Action()
+       lastAction = dummy
+
+       dp = DisplayParams(cm)
+       lastAction.append_action(dp)
+       lastAction = dp
+
+       username = sys.argv[1]
+       password = sys.argv[2]
+       forward = sys.argv[3]
+       con = Connect(cm, username, password, forward)
+       lastAction.append_action(con)
+       lastAction = con
+
+       dis = Disconnect(con)
+       lastAction.append_action(dis)
+       lastAction = dis
+
+       quitter = QuitLoop(loop)
+       lastAction.append_action(quitter)
+       lastAction = quitter
+
+       dp.queue_action()
+       loop.run()
diff --git a/hand_tests/params.py b/hand_tests/params.py
new file mode 100755 (executable)
index 0000000..e2f663f
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import gobject
+import dbus.mainloop.glib
+dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+
+import telepathy
+from telepathy.interfaces import CONN_MGR_INTERFACE
+from telepathy.constants import CONN_MGR_PARAM_FLAG_DBUS_PROPERTY, \
+                                                               CONN_MGR_PARAM_FLAG_HAS_DEFAULT, \
+                                                               CONN_MGR_PARAM_FLAG_REGISTER, \
+                                                               CONN_MGR_PARAM_FLAG_REQUIRED, \
+                                                               CONN_MGR_PARAM_FLAG_SECRET
+
+def print_params (params):
+       for name, flags, signature, default in params:
+               print "%s (%s)" % (name, signature),
+
+               if flags & CONN_MGR_PARAM_FLAG_REQUIRED: print "required",
+               if flags & CONN_MGR_PARAM_FLAG_REGISTER: print "register",
+               if flags & CONN_MGR_PARAM_FLAG_SECRET: print "secret",
+               if flags & CONN_MGR_PARAM_FLAG_DBUS_PROPERTY: print "dbus-property",
+               if flags & CONN_MGR_PARAM_FLAG_HAS_DEFAULT: print "has-default(%s)" % default,
+
+               print ""
+
+       loop.quit ()
+
+def error_cb (*args):
+       print "Error:", args
+       loop.quit ()
+
+
+if __name__ == "__main__":
+       reg = telepathy.client.ManagerRegistry()
+       reg.LoadManagers()
+
+       # get the gabble Connection Manager
+       cm = reg.GetManager('theonering')
+
+       # get the parameters required to make a Jabber connection
+       cm[CONN_MGR_INTERFACE].GetParameters('sip',
+               reply_handler = print_params, error_handler = error_cb)
+
+       loop = gobject.MainLoop()
+       loop.run()
diff --git a/hand_tests/presence.py b/hand_tests/presence.py
new file mode 100755 (executable)
index 0000000..5339038
--- /dev/null
@@ -0,0 +1,250 @@
+#!/usr/bin/env python
+
+import sys
+
+import gobject
+# Begin Example 2-1
+import dbus.mainloop.glib
+dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+# End Example 2-1
+
+import telepathy
+import telepathy.client
+from telepathy.interfaces import CONNECTION_MANAGER, \
+                                                                CONNECTION, \
+                                                                CONNECTION_INTERFACE_REQUESTS, \
+                                                                CONNECTION_INTERFACE_ALIASING, \
+                                                                CONNECTION_INTERFACE_SIMPLE_PRESENCE, \
+                                                                CONNECTION_INTERFACE_CONTACTS, \
+                                                                CHANNEL, \
+                                                                CHANNEL_TYPE_CONTACT_LIST, \
+                                                                CHANNEL_INTERFACE_GROUP
+from telepathy.constants import CONNECTION_STATUS_CONNECTED, \
+                                                               CONNECTION_STATUS_DISCONNECTED, \
+                                                               HANDLE_TYPE_LIST, \
+                                                               HANDLE_TYPE_GROUP
+
+DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
+
+
+class Example (object):
+
+       def __init__ (self, account, password, forward):
+               """e.g. account  = 'bob@example.com/test'
+                               password = 'bigbob'
+               """
+               self.conn = None
+
+               reg = telepathy.client.ManagerRegistry()
+               reg.LoadManagers()
+
+               # get the gabble Connection Manager
+               self.cm = cm = reg.GetManager('theonering')
+
+               # get the parameters required to make a Jabber connection
+               # Begin Example 2-3
+               cm[CONNECTION_MANAGER].RequestConnection('sip',
+                       {
+                               'username':  account,
+                               'forward':  forward,
+                               'password': password,
+                       },
+                       reply_handler = self.request_connection_cb,
+                       error_handler = self.error_cb)
+               # End Example 2-3
+
+       def run(self):
+               self.loop = gobject.MainLoop()
+               try:
+                       self.loop.run()
+               except KeyboardInterrupt:
+                       print "Terminating connection..."
+                       self.disconnect()
+                       # reengage the mainloop so that we can disconnect cleanly
+                       self.loop.run()
+
+       def generic_reply (self, *args): pass
+
+       def error_cb (self, error):
+               print "Error:", error
+               self.disconnect()
+
+       def disconnect (self):
+               if self.conn is None:
+                       return
+               self.conn[CONNECTION].Disconnect(reply_handler = self.generic_reply,
+                                                                                error_handler = self.error_cb)
+
+       # Begin Example 2-4
+       def request_connection_cb (self, bus_name, object_path):
+               print bus_name, object_path
+               # End Example 2-4
+               self.conn = conn = telepathy.client.Connection(bus_name, object_path)
+
+               conn[CONNECTION].connect_to_signal('StatusChanged',
+                       self.status_changed_cb)
+
+               print "Establishing connection..."
+               conn[CONNECTION].Connect(reply_handler = self.generic_reply,
+                                                                error_handler = self.error_cb)
+
+       def status_changed_cb (self, status, reason):
+               conn = self.conn
+
+               if status == CONNECTION_STATUS_DISCONNECTED:
+                       print "Disconnected!"
+                       self.loop.quit()
+
+               if status != CONNECTION_STATUS_CONNECTED: return
+
+               print 'Carrier Detected' # remember dialup modems?
+               print 'Ctrl-C to disconnect'
+
+               # get a list of interfaces on this connection
+               conn[CONNECTION].GetInterfaces(reply_handler = self.get_interfaces_cb,
+                                                                          error_handler = self.error_cb)
+
+       def request_contact_list (self, *groups):
+               conn = self.conn
+
+               class ensure_channel_cb (object):
+                       def __init__ (self, parent, group):
+                               self.parent = parent
+                               self.group = group
+
+                       def __call__ (self, yours, path, properties):
+                               print "got channel for %s -> %s, yours = %s" % (
+                                       self.group, path, yours)
+
+                               channel = telepathy.client.Channel(conn.service_name, path)
+                               self.channel = channel
+
+                               # Begin Example 6-8
+                               # request the list of members
+                               channel[DBUS_PROPERTIES].Get(CHANNEL_INTERFACE_GROUP,
+                                                                                'Members',
+                                                                                reply_handler = self.members_cb,
+                                                                                error_handler = self.parent.error_cb)
+
+                       def members_cb (self, handles):
+                               # request information for this list of handles using the
+                               # Contacts interface
+                               conn[CONNECTION_INTERFACE_CONTACTS].GetContactAttributes(
+                                       handles, [
+                                               CONNECTION,
+                                               CONNECTION_INTERFACE_ALIASING,
+                                               CONNECTION_INTERFACE_SIMPLE_PRESENCE,
+                                       ],
+                                       False,
+                                       reply_handler = self.get_contact_attributes_cb,
+                                       error_handler = self.parent.error_cb)
+                               # End Example 6-8
+
+                       def get_contact_attributes_cb (self, attributes):
+                               return # DEBUG
+
+                               print '-' * 78
+                               print self.group
+                               print '-' * 78
+                               for member in attributes.values():
+                                       for key, value in member.iteritems():
+                                               print '%s: %s' % (key, value)
+                                       print
+                               print '-' * 78
+
+               def no_channel_available (error):
+                       print error
+
+               # we can either use TargetID if we know a name, or TargetHandle
+               # if we already have a handle
+               for group in groups:
+                       # Begin Example 6-6
+                       print "Ensuring channel to %s..." % group
+                       conn[CONNECTION_INTERFACE_REQUESTS].EnsureChannel({
+                               CHANNEL + '.ChannelType'         : CHANNEL_TYPE_CONTACT_LIST,
+                               CHANNEL + '.TargetHandleType': HANDLE_TYPE_LIST,
+                               CHANNEL + '.TargetID'           : group,
+                               },
+                               reply_handler = ensure_channel_cb(self, group),
+                               error_handler = no_channel_available)
+                       # End Example 6-6
+
+       def get_interfaces_cb (self, interfaces):
+               conn = self.conn
+
+               print "Interfaces:"
+               for interface in interfaces:
+                       print " - %s" % interface
+
+               if CONNECTION_INTERFACE_REQUESTS in interfaces:
+                       self.request_contact_list('subscribe',
+                                                                         'publish',
+                                                                         'hide',
+                                                                         'allow',
+                                                                         'deny',
+                                                                         'known')
+
+                       # get the open channelsA
+                       # Begin Example 2-6
+                       conn[CONNECTION_INTERFACE_REQUESTS].connect_to_signal(
+                                                                       'NewChannels',
+                                                                       self.get_channels_cb)
+                       # End Example 2-6
+                       # Begin Example 2-5
+                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_REQUESTS,
+                                                                       'Channels',
+                                                                       reply_handler = self.get_channels_cb,
+                                                                       error_handler = self.error_cb)
+                       # End Example 2-5
+
+               if CONNECTION_INTERFACE_SIMPLE_PRESENCE in interfaces:
+                       # Begin Example 5-4
+                       # request the statuses
+                       print 'Requesting statuses...'
+                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_SIMPLE_PRESENCE,
+                                                                       'Statuses',
+                                                                       reply_handler = self.get_statuses_cb,
+                                                                       error_handler = self.error_cb)
+
+                       # set our presence
+                       #print 'Setting presence...'
+                       #conn[CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
+                       #                                               'away',
+                       #                                               'At the Movies',
+                       #                                               reply_handler = self.generic_reply,
+                       #                                               error_handler = self.error_cb)
+                       # End Example 5-4
+
+               if CONNECTION_INTERFACE_CONTACTS in interfaces:
+                       print 'Requesting contact attribute interfaces...'
+                       conn[DBUS_PROPERTIES].Get(CONNECTION_INTERFACE_CONTACTS,
+                                                                       'ContactAttributeInterfaces',
+                                                                       reply_handler = self.get_contact_ifaces_cb,
+                                                                       error_handler = self.error_cb)
+
+       def get_channels_cb (self, channels):
+               for channel, props in channels:
+                       # find the group channels
+                       if props[CHANNEL + '.ChannelType'] != CHANNEL_TYPE_CONTACT_LIST or \
+                          props[CHANNEL + '.TargetHandleType'] != HANDLE_TYPE_GROUP:
+                               continue
+
+                       print 'GROUP: Got channel %s: %s' % (channel, props[CHANNEL + '.TargetID'])
+
+       def get_statuses_cb (self, value):
+               print "Statuses:"
+
+               for (key, value) in value.iteritems():
+                       print " - %s" % key
+
+       def get_contact_ifaces_cb (self, interfaces):
+               print "Contact Attribute Interfaces:"
+               for interface in interfaces:
+                       print " - %s" % interface
+
+if __name__ == '__main__':
+       username = sys.argv[1]
+       password = sys.argv[2]
+       forward = sys.argv[3]
+       e = Example(username, password, forward)
+       e.run()