changeset 13765:13b7e59a0759

[gaim-migrate @ 16177] SF Bug #1485718 "At Solaris ARC review, the architect committee noticed that gaim installs two files to /usr/bin with the *.py extension. These include: gaim-notifications-example.py gaim-remote.py ARC also noticed that there are no other applications in /usr/bin with this extension, and questioned whether it makes sense to add applications to the default user PATH like this. Does it make more sense to remove the .py from the filenames if you are planning to install them into PATH? They recommend changing the name for consistancy. Also, not sure it is a good idea to install example programs to /usr/bin. Perhaps gaim-notifications-example should be installed to a /usr/demo directory, or elsewhere?" I've renamed gaim-remote.py to gaim-remote and moved gaim-notifications-example to /usr/share/gaim/doc/examples. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 11 May 2006 17:02:46 +0000
parents 8d972f41b4de
children e55e52d41287
files src/Makefile.am src/gaim-notifications-example src/gaim-notifications-example.py src/gaim-remote src/gaim-remote.py
diffstat 5 files changed, 304 insertions(+), 301 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Thu May 11 01:35:30 2006 +0000
+++ b/src/Makefile.am	Thu May 11 17:02:46 2006 +0000
@@ -1,8 +1,8 @@
 EXTRA_DIST = \
 		dbus-analyze-functions.py \
 		dbus-analyze-types.py \
-		gaim-notifications-example.py \
-		gaim-remote.py \
+		gaim-notifications-example \
+		gaim-remote \
 		gaim-send \
 		gaim-send-async \
 		getopt.c \
@@ -228,7 +228,10 @@
 
 # scripts
 
-bin_SCRIPTS = gaim-remote.py gaim-notifications-example.py gaim-send gaim-send-async
+bin_SCRIPTS = gaim-remote gaim-send gaim-send-async
+
+exampledir = $(datadir)/doc/@PACKAGE@/examples
+example_DATA = gaim-notifications-example
 
 endif
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gaim-notifications-example	Thu May 11 17:02:46 2006 +0000
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+
+# This is a simple gaim notification server.
+# It shows notifications when your buddy signs on or you get an IM message.
+#
+# This script requires Python 2.4 and PyGTK bindings
+#
+# Note that all function names are resolved dynamically, no
+# gaim-specific library is needed.
+
+import dbus
+import dbus.glib
+import dbus.decorators
+import gobject
+import os
+
+def ensureimconversation(conversation, account, name):
+    if conversation != 0:
+        return conversation
+    else:
+        # 1 = GAIM_CONV_IM 
+        return gaim.GaimConversationNew(1, account, name)
+
+def receivedimmsg(account, name, message, conversation, flags):
+    buddy = gaim.GaimFindBuddy(account, name)
+    if buddy != 0:
+        alias = gaim.GaimBuddyGetAlias(buddy)
+    else:
+        alias = name
+
+    text = "%s says %s" % (alias, message)
+    code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
+                      "'So what?','Show me',Close,Abuse", text)
+
+    if code == 101:                     # so what?
+        pass
+    else:
+        conversation = ensureimconversation(conversation, account, name)
+
+    if code == 102:                     # show me
+        window = gaim.GaimConversationGetWindow(conversation)
+        gaim.GaimConvWindowRaise(window)
+
+    if code == 103:                     # close 
+        gaim.GaimConversationDestroy(conversation)
+
+    if code == 104:                     # abuse
+        im = gaim.GaimConversationGetImData(conversation)
+        gaim.GaimConvImSend(im, "Go away you f...")
+                                 
+        
+def buddysignedon(buddyid):
+    alias = gaim.GaimBuddyGetAlias(buddyid)
+    text = "%s is online" % alias
+
+    code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
+                      "'So what?','Let's talk'", text)
+
+    if code == 101:                     # so what?
+        pass
+
+    if code == 102:                     # talk
+        name = gaim.GaimBuddyGetName(buddyid)
+        account = gaim.GaimBuddyGetAccount(buddyid)
+        gaim.GaimConversationNew(1, account, name)
+    
+
+bus = dbus.SessionBus()
+obj = bus.get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
+gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
+
+bus.add_signal_receiver(receivedimmsg,
+                        dbus_interface = "net.sf.gaim.GaimInterface",
+                        signal_name = "ReceivedImMsg")
+
+bus.add_signal_receiver(buddysignedon,
+                        dbus_interface = "net.sf.gaim.GaimInterface",
+                        signal_name = "BuddySignedOn")
+
+print "This is a simple gaim notification server."
+print "It shows notifications when your buddy signs on or you get an IM message."
+
+loop = gobject.MainLoop()
+loop.run()
+
+
--- a/src/gaim-notifications-example.py	Thu May 11 01:35:30 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-#!/usr/bin/env python
-
-# This is a simple gaim notification server.
-# It shows notifications when your buddy signs on or you get an IM message.
-#
-# This script requires Python 2.4 and PyGTK bindings
-#
-# Note that all function names are resolved dynamically, no
-# gaim-specific library is needed.
-
-import dbus
-import dbus.glib
-import dbus.decorators
-import gobject
-import os
-
-def ensureimconversation(conversation, account, name):
-    if conversation != 0:
-        return conversation
-    else:
-        # 1 = GAIM_CONV_IM 
-        return gaim.GaimConversationNew(1, account, name)
-
-def receivedimmsg(account, name, message, conversation, flags):
-    buddy = gaim.GaimFindBuddy(account, name)
-    if buddy != 0:
-        alias = gaim.GaimBuddyGetAlias(buddy)
-    else:
-        alias = name
-
-    text = "%s says %s" % (alias, message)
-    code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
-                      "'So what?','Show me',Close,Abuse", text)
-
-    if code == 101:                     # so what?
-        pass
-    else:
-        conversation = ensureimconversation(conversation, account, name)
-
-    if code == 102:                     # show me
-        window = gaim.GaimConversationGetWindow(conversation)
-        gaim.GaimConvWindowRaise(window)
-
-    if code == 103:                     # close 
-        gaim.GaimConversationDestroy(conversation)
-
-    if code == 104:                     # abuse
-        im = gaim.GaimConversationGetImData(conversation)
-        gaim.GaimConvImSend(im, "Go away you f...")
-                                 
-        
-def buddysignedon(buddyid):
-    alias = gaim.GaimBuddyGetAlias(buddyid)
-    text = "%s is online" % alias
-
-    code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
-                      "'So what?','Let's talk'", text)
-
-    if code == 101:                     # so what?
-        pass
-
-    if code == 102:                     # talk
-        name = gaim.GaimBuddyGetName(buddyid)
-        account = gaim.GaimBuddyGetAccount(buddyid)
-        gaim.GaimConversationNew(1, account, name)
-    
-
-bus = dbus.SessionBus()
-obj = bus.get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
-gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
-
-bus.add_signal_receiver(receivedimmsg,
-                        dbus_interface = "net.sf.gaim.GaimInterface",
-                        signal_name = "ReceivedImMsg")
-
-bus.add_signal_receiver(buddysignedon,
-                        dbus_interface = "net.sf.gaim.GaimInterface",
-                        signal_name = "BuddySignedOn")
-
-print "This is a simple gaim notification server."
-print "It shows notifications when your buddy signs on or you get an IM message."
-
-loop = gobject.MainLoop()
-loop.run()
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gaim-remote	Thu May 11 17:02:46 2006 +0000
@@ -0,0 +1,212 @@
+#!/usr/bin/python
+
+import dbus
+import re
+import urllib
+import sys
+
+import xml.dom.minidom 
+
+xml.dom.minidom.Element.all   = xml.dom.minidom.Element.getElementsByTagName
+
+obj = dbus.SessionBus().get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
+gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
+
+class CheckedObject:
+    def __init__(self, obj):
+        self.obj = obj
+
+    def __getattr__(self, attr):
+        return CheckedAttribute(self, attr)
+
+class CheckedAttribute:
+    def __init__(self, cobj, attr):
+        self.cobj = cobj
+        self.attr = attr
+        
+    def __call__(self, *args):
+        result = self.cobj.obj.__getattr__(self.attr)(*args)
+        if result == 0:
+            raise "Error: " + self.attr + " " + str(args) + " returned " + str(result)
+        return result
+            
+cgaim = CheckedObject(gaim)
+
+urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?"
+
+def extendlist(list, length, fill):
+    if len(list) < length:
+        return list + [fill] * (length - len(list))
+    else:
+        return list
+
+def convert(value):
+    try:
+        return int(value)
+    except:
+        return value
+
+def findaccount(accountname, protocolname):
+    try:
+        # prefer connected accounts
+        account = cgaim.GaimAccountsFindConnected(accountname, protocolname)
+        return account
+    except:
+        # try to get any account and connect it
+        account = cgaim.GaimAccountsFindAny(accountname, protocolname)
+        print gaim.GaimAccountGetUsername(account)
+        gaim.GaimAccountSetStatusVargs(account, "online", 1)
+        gaim.GaimAccountConnect(account)
+        return account
+    
+
+def execute(uri):
+    match = re.match(urlregexp, uri)
+    protocol = match.group(2)
+    if protocol == "aim" or protocol == "icq":
+        protocol = "oscar"
+    if protocol is not None:
+        protocol = "prpl-" + protocol
+    command = match.group(5)
+    paramstring = match.group(7) 
+    params = {}
+    if paramstring is not None:
+        for param in paramstring.split("&"):
+            key, value = extendlist(param.split("=",1), 2, "")
+            params[key] = urllib.unquote(value)
+
+    accountname = params.get("account", "")
+
+    if command == "goim":
+        print params
+        account = findaccount(accountname, protocol)
+        conversation = cgaim.GaimConversationNew(1, account, params["screenname"])
+        if "message" in params:
+            im = cgaim.GaimConversationGetImData(conversation)
+            gaim.GaimConvImSend(im, params["message"])
+        return None
+
+    elif command == "gochat":
+        account = findaccount(accountname, protocol)
+        connection = cgaim.GaimAccountGetConnection(account)
+        return gaim.ServJoinChat(connection, params)
+
+    elif command == "addbuddy":
+        account = findaccount(accountname, protocol)
+        return cgaim.GaimBlistRequestAddBuddy(account, params["screenname"],
+                                              params.get("group", ""), "")
+
+    elif command == "setstatus":
+        current = gaim.GaimSavedstatusGetCurrent()
+
+        if "status" in params:
+            status_id = params["status"]
+            status_type = gaim.GaimPrimitiveGetTypeFromId(status_id)
+        else:
+            status_type = gaim.GaimSavedStatusGetType(current)
+            status_id = gaim.GaimPrimitiveGetIdFromType(status_type)
+
+        if "message" in params:
+            message = params["message"];
+        else:
+            message = gaim.GaimSavedstatusGetMessage(current)
+
+        if "account" in params:
+            accounts = [cgaim.GaimAccountsFindAny(accountname, protocol)]
+
+            for account in accounts:
+                status = gaim.GaimAccountGetStatus(account, status_id)
+                type = gaim.GaimStatusGetType(status)
+                gaim.GaimSavedstatusSetSubstatus(current, account, type, message)
+                gaim.GaimSavedstatusActivateForAccount(current, account)
+        else:
+            accounts = gaim.GaimAccountsGetAllActive()
+            saved = gaim.GaimSavedstatusNew("", status_type)
+            gaim.GaimSavedstatusSetMessage(saved, message)
+            gaim.GaimSavedstatusActivate(saved)
+
+        return None
+
+    elif command == "getinfo":
+        account = findaccount(accountname, protocol)
+        connection = cgaim.GaimAccountGetConnection(account)
+        return gaim.ServGetInfo(connection, params["screenname"])
+
+    elif command == "quit":
+        return gaim.GaimCoreQuit()
+
+    elif command == "uri":
+        return None
+
+    else:
+        match = re.match(r"(\w+)\s*\(([^)]*)\)", command)
+        if match is not None:
+            name = match.group(1)
+            argstr = match.group(2)
+            if argstr == "":
+                args = []
+            else:
+                args = argstr.split(",")
+            fargs = []
+            for arg in args:
+                fargs.append(convert(arg.strip()))
+            return gaim.__getattr__(name)(*fargs)
+        else:
+            # introspect the object to get parameter names and types
+            # this is slow because the entire introspection info must be downloaded
+            data = dbus.Interface(obj, "org.freedesktop.DBus.Introspectable").\
+                   Introspect()
+            introspect = xml.dom.minidom.parseString(data).documentElement
+            for method in introspect.all("method"):
+                if command == method.getAttribute("name"):
+                    methodparams = []
+                    for arg in method.all("arg"):
+                        if arg.getAttribute("direction") == "in":
+                            value = params[arg.getAttribute("name")]
+                            type = arg.getAttribute("type")
+                            if type == "s":
+                                methodparams.append(value)
+                            elif type == "i":
+                                methodparams.append(int(value))
+                            else:
+                                raise "Don't know how to handle type \"%s\"" % type
+                    return gaim.__getattr__(command)(*methodparams)
+            raise "Unknown command: %s" % command
+
+
+if len(sys.argv) == 1:
+    print """This program uses DBus to communicate with gaim.
+
+Usage:
+
+    %s "command1" "command2" ...
+
+Each command is of one of the three types:
+
+    [protocol:]commandname?param1=value1&param2=value2&...
+    FunctionName?param1=value1&param2=value2&...
+    FunctionName(value1,value2,...)
+
+The second and third form are provided for completeness but their use
+is not recommended; use gaim-send or gaim-send-async instead.  The
+second form uses introspection to find out the parameter names and
+their types, therefore it is rather slow.
+
+Examples of commands:
+
+    jabber:goim?screenname=testone@localhost&message=hi
+    jabber:gochat?room=TestRoom&server=conference.localhost
+    jabber:getinfo?screenname=testone@localhost
+    jabber:addbuddy?screenname=my friend
+
+    setstatus?status=away&message=don't disturb
+    quit
+
+    GaimAccountsFindConnected?name=&protocol=prpl-jabber
+    GaimAccountFindConnected(,prpl-jabber)
+""" % sys.argv[0]
+
+for arg in sys.argv[1:]:
+    print execute(arg)
+    
+    
--- a/src/gaim-remote.py	Thu May 11 01:35:30 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-#!/usr/bin/python
-
-import dbus
-import re
-import urllib
-import sys
-
-import xml.dom.minidom 
-
-xml.dom.minidom.Element.all   = xml.dom.minidom.Element.getElementsByTagName
-
-obj = dbus.SessionBus().get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
-gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
-
-class CheckedObject:
-    def __init__(self, obj):
-        self.obj = obj
-
-    def __getattr__(self, attr):
-        return CheckedAttribute(self, attr)
-
-class CheckedAttribute:
-    def __init__(self, cobj, attr):
-        self.cobj = cobj
-        self.attr = attr
-        
-    def __call__(self, *args):
-        result = self.cobj.obj.__getattr__(self.attr)(*args)
-        if result == 0:
-            raise "Error: " + self.attr + " " + str(args) + " returned " + str(result)
-        return result
-            
-cgaim = CheckedObject(gaim)
-
-urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?"
-
-def extendlist(list, length, fill):
-    if len(list) < length:
-        return list + [fill] * (length - len(list))
-    else:
-        return list
-
-def convert(value):
-    try:
-        return int(value)
-    except:
-        return value
-
-def findaccount(accountname, protocolname):
-    try:
-        # prefer connected accounts
-        account = cgaim.GaimAccountsFindConnected(accountname, protocolname)
-        return account
-    except:
-        # try to get any account and connect it
-        account = cgaim.GaimAccountsFindAny(accountname, protocolname)
-        print gaim.GaimAccountGetUsername(account)
-        gaim.GaimAccountSetStatusVargs(account, "online", 1)
-        gaim.GaimAccountConnect(account)
-        return account
-    
-
-def execute(uri):
-    match = re.match(urlregexp, uri)
-    protocol = match.group(2)
-    if protocol == "aim" or protocol == "icq":
-        protocol = "oscar"
-    if protocol is not None:
-        protocol = "prpl-" + protocol
-    command = match.group(5)
-    paramstring = match.group(7) 
-    params = {}
-    if paramstring is not None:
-        for param in paramstring.split("&"):
-            key, value = extendlist(param.split("=",1), 2, "")
-            params[key] = urllib.unquote(value)
-
-    accountname = params.get("account", "")
-
-    if command == "goim":
-        print params
-        account = findaccount(accountname, protocol)
-        conversation = cgaim.GaimConversationNew(1, account, params["screenname"])
-        if "message" in params:
-            im = cgaim.GaimConversationGetImData(conversation)
-            gaim.GaimConvImSend(im, params["message"])
-        return None
-
-    elif command == "gochat":
-        account = findaccount(accountname, protocol)
-        connection = cgaim.GaimAccountGetConnection(account)
-        return gaim.ServJoinChat(connection, params)
-
-    elif command == "addbuddy":
-        account = findaccount(accountname, protocol)
-        return cgaim.GaimBlistRequestAddBuddy(account, params["screenname"],
-                                              params.get("group", ""), "")
-
-    elif command == "setstatus":
-        current = gaim.GaimSavedstatusGetCurrent()
-
-        if "status" in params:
-            status_id = params["status"]
-            status_type = gaim.GaimPrimitiveGetTypeFromId(status_id)
-        else:
-            status_type = gaim.GaimSavedStatusGetType(current)
-            status_id = gaim.GaimPrimitiveGetIdFromType(status_type)
-
-        if "message" in params:
-            message = params["message"];
-        else:
-            message = gaim.GaimSavedstatusGetMessage(current)
-
-        if "account" in params:
-            accounts = [cgaim.GaimAccountsFindAny(accountname, protocol)]
-
-            for account in accounts:
-                status = gaim.GaimAccountGetStatus(account, status_id)
-                type = gaim.GaimStatusGetType(status)
-                gaim.GaimSavedstatusSetSubstatus(current, account, type, message)
-                gaim.GaimSavedstatusActivateForAccount(current, account)
-        else:
-            accounts = gaim.GaimAccountsGetAllActive()
-            saved = gaim.GaimSavedstatusNew("", status_type)
-            gaim.GaimSavedstatusSetMessage(saved, message)
-            gaim.GaimSavedstatusActivate(saved)
-
-        return None
-
-    elif command == "getinfo":
-        account = findaccount(accountname, protocol)
-        connection = cgaim.GaimAccountGetConnection(account)
-        return gaim.ServGetInfo(connection, params["screenname"])
-
-    elif command == "quit":
-        return gaim.GaimCoreQuit()
-
-    elif command == "uri":
-        return None
-
-    else:
-        match = re.match(r"(\w+)\s*\(([^)]*)\)", command)
-        if match is not None:
-            name = match.group(1)
-            argstr = match.group(2)
-            if argstr == "":
-                args = []
-            else:
-                args = argstr.split(",")
-            fargs = []
-            for arg in args:
-                fargs.append(convert(arg.strip()))
-            return gaim.__getattr__(name)(*fargs)
-        else:
-            # introspect the object to get parameter names and types
-            # this is slow because the entire introspection info must be downloaded
-            data = dbus.Interface(obj, "org.freedesktop.DBus.Introspectable").\
-                   Introspect()
-            introspect = xml.dom.minidom.parseString(data).documentElement
-            for method in introspect.all("method"):
-                if command == method.getAttribute("name"):
-                    methodparams = []
-                    for arg in method.all("arg"):
-                        if arg.getAttribute("direction") == "in":
-                            value = params[arg.getAttribute("name")]
-                            type = arg.getAttribute("type")
-                            if type == "s":
-                                methodparams.append(value)
-                            elif type == "i":
-                                methodparams.append(int(value))
-                            else:
-                                raise "Don't know how to handle type \"%s\"" % type
-                    return gaim.__getattr__(command)(*methodparams)
-            raise "Unknown command: %s" % command
-
-
-if len(sys.argv) == 1:
-    print """This program uses DBus to communicate with gaim.
-
-Usage:
-
-    %s "command1" "command2" ...
-
-Each command is of one of the three types:
-
-    [protocol:]commandname?param1=value1&param2=value2&...
-    FunctionName?param1=value1&param2=value2&...
-    FunctionName(value1,value2,...)
-
-The second and third form are provided for completeness but their use
-is not recommended; use gaim-send or gaim-send-async instead.  The
-second form uses introspection to find out the parameter names and
-their types, therefore it is rather slow.
-
-Examples of commands:
-
-    jabber:goim?screenname=testone@localhost&message=hi
-    jabber:gochat?room=TestRoom&server=conference.localhost
-    jabber:getinfo?screenname=testone@localhost
-    jabber:addbuddy?screenname=my friend
-
-    setstatus?status=away&message=don't disturb
-    quit
-
-    GaimAccountsFindConnected?name=&protocol=prpl-jabber
-    GaimAccountFindConnected(,prpl-jabber)
-""" % sys.argv[0]
-
-for arg in sys.argv[1:]:
-    print execute(arg)
-    
-