Updated nullclient.py
authorBruno Abinader <bruno.abinader@openbossa.org>
Fri, 12 Dec 2008 11:54:04 +0000 (11:54 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:23 +0000 (17:11 -0400)
FIXES:
 - Updated nullclient.py example.

Signed-off-by: Bruno Abinader <bruno.abinader@openbossa.org>
Acked-by: Ragner Magalhaes <ragner.magalhaes@openbossa.org>

git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1699 596f6dd7-e928-0410-a184-9e12fd12cf7e

README
nullclient.py

diff --git a/README b/README
index 00a6a8e..edef032 100644 (file)
--- a/README
+++ b/README
@@ -43,3 +43,15 @@ $ sudo python2.5 setup.py install --root=/usr
 You can also create a debian package of it:
 
 $ dpkg-buildpackage -rfakeroot
+
+Testing python-purple
+---------------------
+
+Python-purple provides a client example (nullclient) which connects to a
+Gtalk account and displays libpurple's debug messages. In order to execute it,
+issue the following command:
+
+$ LD_PRELOAD=/usr/lib/libpurple.so.0 python2.5 nullclient.py
+
+It will ask for a username and then password. Insert it and it will
+automatically connect to the given account.
index 112ea10..0438951 100644 (file)
-import purple
+#
+#  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
+#
+#  This file is part of python-purple.
+#
+#  python-purple 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.
+#
+#  python-purple 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/>.
+#
+
 import ecore
 import getpass
+import purple
 import sys
-from xml.dom import minidom
-
-
-class ClientModel:
-    def __init__(self):
-        self.purple = purple.Purple(debug_enabled=True)
-        self.purple.purple_init()
-        self.account = purple.Account()
-
-    def add_account(self, acc):
-        ''' @param acc: {'username': "foo@gmail.com", 'protocol': "XMPP"} '''
-
-        new_acc = self.account.new(acc['username'], acc['protocol'])
-
-        return new_acc
-
-    def get_protocols(self):
-        return self.account.protocol.get_all()
-
-    def get_protocol_options(self, protocol_id):
-        return self.account.protocol.get_options(protocol_id)
 
-    def set_account_info(self, acc, info):
-        ''' @param info: {protocol: 'prpl-jabber', alias: '', password: ' ', server: 'new server', port: '' } ||
-                    {server: 'new server'} '''
+# The information below is needed by libpurple
+__NAME__ = "nullclient"
+__VERSION__ = "0.1"
+__WEBSITE__ = "N/A"
+__DEV_WEBSITE__ = "N/A"
 
-        if info.has_key('protocol'):
-            self.account.set_protocol_id(acc, info['protocol'])
-        if info.has_key('alias'):
-            self.account.set_alias(acc, info['alias'])
-        if info.has_key('password'):
-            self.account.set_password(acc, info['password'])
-
-        self.account.protocol.set_options(acc, info)
-
-    def get_account_info(self, acc):
-        info = {}
-        po = self.account.protocol.get_options(acc[1], acc[0])
-        info['protocol'] = self.account.get_protocol_id(acc)
-        info['alias'] = self.account.get_alias(acc)
-        info['password'] = self.account.get_password(acc)
-        info['connect_server'] = po['connect_server'][1]
-        info['port'] = po['port'][1]
-
-        return info
-
-    def set_account_proxy(self, acc, info):
-        self.account.proxy.set_info(acc, info)
-
-    def account_connect(self, acc):
-        self.account.set_enabled(acc, "carman-purple-python", True)
-        # self.account.connect(acc)
-        self.purple.connect()
-
-    def account_disconnect(self, acc):
-        self.account.disconnect(acc)
-
-   
-class ClientCtrl:
-    def __init__(self):
-        self.clientmodel = ClientModel()
-        new_acc = {}
-        acc_info = {}
-        new_acc['username'] = self.getuser()
-        new_acc['protocol'] = 'prpl-jabber'
-
-        acc = self.clientmodel.add_account(new_acc)
+if __name__ == '__main__':
+    # Sets initial parameters
+    core = purple.Purple(__NAME__, __VERSION__, __WEBSITE__, __DEV_WEBSITE__, \
+            debug_enabled=True, default_path="/tmp")
 
-        acc_info = self.clientmodel.get_account_info(acc)
-        acc_info['password'] = self.getpassword()
-        acc_info['connect_server'] = 'talk.google.com'
-        acc_info['port'] = 443
-        acc_info['old_ssl'] = True
-        self.clientmodel.set_account_info(acc, acc_info)
+    # Initializes libpurple
+    core.purple_init()
 
-        acc_proxy = {}
-        acc_proxy['type'] = 'HTTP' 
-        acc_proxy['host'] = '172.18.216.211'
-        acc_proxy['port'] = 8080
-        self.clientmodel.set_account_proxy(acc, acc_proxy)
+    # Get username from user
+    sys.stdout.write("Enter GTalk account: ")
+    username = sys.stdin.readline()[:-1]
 
-        self.clientmodel.account_connect(acc)
+    # Initialize protocol class
+    protocol = purple.Protocol('prpl-jabber')
 
-    def getuser(self):
-        sys.stdout.write("GTalk account: ")
-        username = sys.stdin.readline()
-        return username[:-1]
+    # Creates new account inside libpurple
+    account = purple.Account(username, protocol, core)
+    account.new()
 
-    def getpassword(self):
-        return getpass.getpass()
+    # Get password from user
+    account.set_password(getpass.getpass())
 
-if __name__ == '__main__':
+    # Set account protocol options
+    info = {}
+    info['connect_server'] = 'talk.google.com'
+    info['port'] = '443'
+    info['old_ssl'] = True
+    account.set_protocol_options(info)
 
-    ctrl = ClientCtrl()
+    # Enable account (connects automatically)
+    account.set_enabled(True)
 
+    # Initializes ecore mainloop
     ecore.main_loop_begin()