file isExecutable
Prep for 2.10.10
sys.stdin = codecs.getwriter('utf-8')(sys.stdin); sys.stdout = codecs.getwriter('utf-8')(sys.stdout); xml.dom.minidom.Element.all = xml.dom.minidom.Element.getElementsByTagName obj = dbus.SessionBus().get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") 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 Exception("Error: %s %s returned %s" % (self.attr, args, result)) def show_help(requested=False): print """This program uses D-Bus to communicate with purple. %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 purple-send or purple-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 PurpleAccountsFindConnected?name=&protocol=prpl-jabber PurpleAccountsFindConnected(,prpl-jabber) cpurple = CheckedObject(purple) urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?" def extendlist(list, length, fill): return list + [fill] * (length - len(list)) def findaccount(accountname, protocolname): # prefer connected accounts account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) # try to get any account and connect it account = cpurple.PurpleAccountsFindAny(accountname, protocolname) purple.PurpleAccountSetStatusVargs(account, "online", 1) purple.PurpleAccountConnect(account) match = re.match(urlregexp, uri) protocol = match.group(2) 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 = cpurple.PurpleConversationNew(1, account, params["screenname"]) im = cpurple.PurpleConversationGetImData(conversation) purple.PurpleConvImSend(im, params["message"]) elif command == "gochat": account = findaccount(accountname, protocol) connection = cpurple.PurpleAccountGetConnection(account) return purple.ServJoinChat(connection, params) elif command == "addbuddy": account = findaccount(accountname, protocol) return cpurple.PurpleBlistRequestAddBuddy(account, params["screenname"], params.get("group", ""), "") elif command == "setstatus": current = purple.PurpleSavedstatusGetCurrent() status_id = params["status"] status_type = purple.PurplePrimitiveGetTypeFromId(status_id) status_type = purple.PurpleSavedstatusGetType(current) status_id = purple.PurplePrimitiveGetIdFromType(status_type) message = params["message"]; message = purple.PurpleSavedstatusGetMessage(current) accounts = [cpurple.PurpleAccountsFindAny(accountname, protocol)] status = purple.PurpleAccountGetStatus(account, status_id) type = purple.PurpleStatusGetType(status) purple.PurpleSavedstatusSetSubstatus(current, account, type, message) purple.PurpleSavedstatusActivateForAccount(current, account) saved = purple.PurpleSavedstatusNew("", status_type) purple.PurpleSavedstatusSetMessage(saved, message) purple.PurpleSavedstatusActivate(saved) elif command == "getstatus": current = purple.PurpleSavedstatusGetCurrent() status_type = purple.PurpleSavedstatusGetType(current) status_id = purple.PurplePrimitiveGetIdFromType(status_type) elif command == "getstatusmessage": current = purple.PurpleSavedstatusGetCurrent() return purple.PurpleSavedstatusGetMessage(current) elif command == "getinfo": account = findaccount(accountname, protocol) connection = cpurple.PurpleAccountGetConnection(account) return purple.ServGetInfo(connection, params["screenname"]) return purple.PurpleCoreQuit() match = re.match(r"(\w+)\s*\(([^)]*)\)", command) fargs.append(convert(arg.strip())) return purple.__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 Exception("Don't know how to handle type \"%s\"" % type) return purple.__getattr__(command)(*methodparams) elif (sys.argv[1] == "--help" or sys.argv[1] == "-h"): print "No existing libpurple instance detected."