annotate src/gaim-remote @ 13841:f3d4a9902ead

[gaim-migrate @ 16294] This should fix --enable-python to do something reasonable committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Tue, 20 Jun 2006 04:05:56 +0000
parents 95166d0d6037
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13765
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
1 #!/usr/bin/python
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
2
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
3 import dbus
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
4 import re
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
5 import urllib
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
6 import sys
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
7
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
8 import xml.dom.minidom
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
9
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
10 xml.dom.minidom.Element.all = xml.dom.minidom.Element.getElementsByTagName
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
11
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
12 obj = dbus.SessionBus().get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
13 gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
14
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
15 class CheckedObject:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
16 def __init__(self, obj):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
17 self.obj = obj
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
18
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
19 def __getattr__(self, attr):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
20 return CheckedAttribute(self, attr)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
21
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
22 class CheckedAttribute:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
23 def __init__(self, cobj, attr):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
24 self.cobj = cobj
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
25 self.attr = attr
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
26
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
27 def __call__(self, *args):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
28 result = self.cobj.obj.__getattr__(self.attr)(*args)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
29 if result == 0:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
30 raise "Error: " + self.attr + " " + str(args) + " returned " + str(result)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
31 return result
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
32
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
33 cgaim = CheckedObject(gaim)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
34
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
35 urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?"
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
36
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
37 def extendlist(list, length, fill):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
38 if len(list) < length:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
39 return list + [fill] * (length - len(list))
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
40 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
41 return list
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
42
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
43 def convert(value):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
44 try:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
45 return int(value)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
46 except:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
47 return value
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
48
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
49 def findaccount(accountname, protocolname):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
50 try:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
51 # prefer connected accounts
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
52 account = cgaim.GaimAccountsFindConnected(accountname, protocolname)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
53 return account
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
54 except:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
55 # try to get any account and connect it
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
56 account = cgaim.GaimAccountsFindAny(accountname, protocolname)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
57 gaim.GaimAccountSetStatusVargs(account, "online", 1)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
58 gaim.GaimAccountConnect(account)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
59 return account
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
60
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
61
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
62 def execute(uri):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
63 match = re.match(urlregexp, uri)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
64 protocol = match.group(2)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
65 if protocol == "aim" or protocol == "icq":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
66 protocol = "oscar"
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
67 if protocol is not None:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
68 protocol = "prpl-" + protocol
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
69 command = match.group(5)
13772
95166d0d6037 [gaim-migrate @ 16184]
Richard Laager <rlaager@wiktel.com>
parents: 13765
diff changeset
70 paramstring = match.group(7)
13765
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
71 params = {}
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
72 if paramstring is not None:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
73 for param in paramstring.split("&"):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
74 key, value = extendlist(param.split("=",1), 2, "")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
75 params[key] = urllib.unquote(value)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
76
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
77 accountname = params.get("account", "")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
78
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
79 if command == "goim":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
80 account = findaccount(accountname, protocol)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
81 conversation = cgaim.GaimConversationNew(1, account, params["screenname"])
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
82 if "message" in params:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
83 im = cgaim.GaimConversationGetImData(conversation)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
84 gaim.GaimConvImSend(im, params["message"])
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
85 return None
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
86
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
87 elif command == "gochat":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
88 account = findaccount(accountname, protocol)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
89 connection = cgaim.GaimAccountGetConnection(account)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
90 return gaim.ServJoinChat(connection, params)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
91
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
92 elif command == "addbuddy":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
93 account = findaccount(accountname, protocol)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
94 return cgaim.GaimBlistRequestAddBuddy(account, params["screenname"],
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
95 params.get("group", ""), "")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
96
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
97 elif command == "setstatus":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
98 current = gaim.GaimSavedstatusGetCurrent()
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
99
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
100 if "status" in params:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
101 status_id = params["status"]
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
102 status_type = gaim.GaimPrimitiveGetTypeFromId(status_id)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
103 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
104 status_type = gaim.GaimSavedStatusGetType(current)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
105 status_id = gaim.GaimPrimitiveGetIdFromType(status_type)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
106
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
107 if "message" in params:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
108 message = params["message"];
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
109 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
110 message = gaim.GaimSavedstatusGetMessage(current)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
111
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
112 if "account" in params:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
113 accounts = [cgaim.GaimAccountsFindAny(accountname, protocol)]
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
114
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
115 for account in accounts:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
116 status = gaim.GaimAccountGetStatus(account, status_id)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
117 type = gaim.GaimStatusGetType(status)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
118 gaim.GaimSavedstatusSetSubstatus(current, account, type, message)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
119 gaim.GaimSavedstatusActivateForAccount(current, account)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
120 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
121 accounts = gaim.GaimAccountsGetAllActive()
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
122 saved = gaim.GaimSavedstatusNew("", status_type)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
123 gaim.GaimSavedstatusSetMessage(saved, message)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
124 gaim.GaimSavedstatusActivate(saved)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
125
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
126 return None
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
127
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
128 elif command == "getinfo":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
129 account = findaccount(accountname, protocol)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
130 connection = cgaim.GaimAccountGetConnection(account)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
131 return gaim.ServGetInfo(connection, params["screenname"])
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
132
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
133 elif command == "quit":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
134 return gaim.GaimCoreQuit()
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
135
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
136 elif command == "uri":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
137 return None
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
138
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
139 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
140 match = re.match(r"(\w+)\s*\(([^)]*)\)", command)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
141 if match is not None:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
142 name = match.group(1)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
143 argstr = match.group(2)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
144 if argstr == "":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
145 args = []
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
146 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
147 args = argstr.split(",")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
148 fargs = []
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
149 for arg in args:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
150 fargs.append(convert(arg.strip()))
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
151 return gaim.__getattr__(name)(*fargs)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
152 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
153 # introspect the object to get parameter names and types
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
154 # this is slow because the entire introspection info must be downloaded
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
155 data = dbus.Interface(obj, "org.freedesktop.DBus.Introspectable").\
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
156 Introspect()
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
157 introspect = xml.dom.minidom.parseString(data).documentElement
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
158 for method in introspect.all("method"):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
159 if command == method.getAttribute("name"):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
160 methodparams = []
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
161 for arg in method.all("arg"):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
162 if arg.getAttribute("direction") == "in":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
163 value = params[arg.getAttribute("name")]
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
164 type = arg.getAttribute("type")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
165 if type == "s":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
166 methodparams.append(value)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
167 elif type == "i":
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
168 methodparams.append(int(value))
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
169 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
170 raise "Don't know how to handle type \"%s\"" % type
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
171 return gaim.__getattr__(command)(*methodparams)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
172 raise "Unknown command: %s" % command
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
173
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
174
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
175 if len(sys.argv) == 1:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
176 print """This program uses DBus to communicate with gaim.
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
177
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
178 Usage:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
179
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
180 %s "command1" "command2" ...
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
181
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
182 Each command is of one of the three types:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
183
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
184 [protocol:]commandname?param1=value1&param2=value2&...
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
185 FunctionName?param1=value1&param2=value2&...
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
186 FunctionName(value1,value2,...)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
187
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
188 The second and third form are provided for completeness but their use
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
189 is not recommended; use gaim-send or gaim-send-async instead. The
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
190 second form uses introspection to find out the parameter names and
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
191 their types, therefore it is rather slow.
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
192
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
193 Examples of commands:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
194
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
195 jabber:goim?screenname=testone@localhost&message=hi
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
196 jabber:gochat?room=TestRoom&server=conference.localhost
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
197 jabber:getinfo?screenname=testone@localhost
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
198 jabber:addbuddy?screenname=my friend
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
199
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
200 setstatus?status=away&message=don't disturb
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
201 quit
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
202
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
203 GaimAccountsFindConnected?name=&protocol=prpl-jabber
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
204 GaimAccountFindConnected(,prpl-jabber)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
205 """ % sys.argv[0]
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
206
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
207 for arg in sys.argv[1:]:
13772
95166d0d6037 [gaim-migrate @ 16184]
Richard Laager <rlaager@wiktel.com>
parents: 13765
diff changeset
208 output = execute(arg)
95166d0d6037 [gaim-migrate @ 16184]
Richard Laager <rlaager@wiktel.com>
parents: 13765
diff changeset
209
95166d0d6037 [gaim-migrate @ 16184]
Richard Laager <rlaager@wiktel.com>
parents: 13765
diff changeset
210 if (output != None):
95166d0d6037 [gaim-migrate @ 16184]
Richard Laager <rlaager@wiktel.com>
parents: 13765
diff changeset
211 print output
95166d0d6037 [gaim-migrate @ 16184]
Richard Laager <rlaager@wiktel.com>
parents: 13765
diff changeset
212