file isExecutable
update tags
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") def __getattr__(self, attr): return CheckedAttribute(self, attr) def __init__(self, cobj, attr): def __call__(self, *args): result = self.cobj.obj.__getattr__(self.attr)(*args) raise "Error: " + self.attr + " " + str(args) + " returned " + str(result) cgaim = CheckedObject(gaim) urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?" def extendlist(list, length, fill): return list + [fill] * (length - len(list)) def findaccount(accountname, protocolname): # prefer connected accounts account = cgaim.GaimAccountsFindConnected(accountname, protocolname) # 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) match = re.match(urlregexp, uri) protocol = match.group(2) if protocol == "aim" or protocol == "icq": protocol = "prpl-" + protocol paramstring = match.group(7) 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", "") account = findaccount(accountname, protocol) conversation = cgaim.GaimConversationNew(1, account, params["screenname"]) im = cgaim.GaimConversationGetImData(conversation) gaim.GaimConvImSend(im, params["message"]) 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": accounts = [cgaim.GaimAccountsFindAny(accountname, protocol)] accounts = gaim.GaimAccountsGetAllActive() status = cgaim.GaimAccountGetStatus(account, params["status"]) for key, value in params.items(): if key not in ["status", "account"]: gaim.GaimStatusSetAttrString(status, key, value) gaim.GaimAccountSetStatusVargs(account, params["status"], 1) elif command == "getinfo": account = findaccount(accountname, protocol) connection = cgaim.GaimAccountGetConnection(account) return gaim.ServGetInfo(connection, params["screenname"]) return gaim.GaimCoreQuit() match = re.match(r"(\w+)\s*\(([^)]*)\)", command) fargs.append(convert(arg.strip())) return gaim.__getattr__(name)(*fargs) # 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 = xml.dom.minidom.parseString(data).documentElement for method in introspect.all("method"): if command == method.getAttribute("name"): for arg in method.all("arg"): if arg.getAttribute("direction") == "in": value = params[arg.getAttribute("name")] type = arg.getAttribute("type") methodparams.append(value) methodparams.append(int(value)) raise "Don't know how to handle type \"%s\"" % type return gaim.__getattr__(command)(*methodparams) raise "Unknown command: %s" % command print """This program uses DBus to communicate with gaim. %s "command1" "command2" ... Each command is of one of the three types: [protocol:]commandname?param1=value1¶m2=value2&... FunctionName?param1=value1¶m2=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. 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 GaimAccountsFindConnected?name=&protocol=prpl-jabber GaimAccountFindConnected(,prpl-jabber)