Mercurial > pidgin
comparison libpurple/purple-url-handler @ 16145:d06673964ff9
Print decent error messages instead of stack traces if there's a problem.
Users generally won't be calling this from the command line anyway, so
the lack of i18n here isn't a huge problem, but maybe we should address
that some day.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 15 Apr 2007 18:15:18 +0000 |
parents | 598b1b15b199 |
children | 81015b477483 27dfbca8dd40 |
comparison
equal
deleted
inserted
replaced
16144:1f42dbf360e3 | 16145:d06673964ff9 |
---|---|
20 def __init__(self, cobj, attr): | 20 def __init__(self, cobj, attr): |
21 self.cobj = cobj | 21 self.cobj = cobj |
22 self.attr = attr | 22 self.attr = attr |
23 | 23 |
24 def __call__(self, *args): | 24 def __call__(self, *args): |
25 # Redirect stderr to suppress the printing of an " Introspect error" | |
26 # message if nothing is listening on the bus. We print a friendly | |
27 # error message ourselves. | |
28 real_stderr = sys.stderr | |
29 sys.stderr = None | |
25 result = self.cobj.obj.__getattr__(self.attr)(*args) | 30 result = self.cobj.obj.__getattr__(self.attr)(*args) |
26 if result == 0: | 31 sys.stderr = real_stderr |
27 raise "Error: " + self.attr + " " + str(args) + " returned " + str(result) | 32 |
33 # This can be useful for debugging. | |
34 # if (result == 0): | |
35 # print "Error: " + self.attr + " " + str(args) + " returned " + str(result) | |
36 | |
28 return result | 37 return result |
29 | 38 |
30 cpurple = CheckedObject(purple) | 39 cpurple = CheckedObject(purple) |
31 | 40 |
32 def extendlist(list, length, fill): | 41 def extendlist(list, length, fill): |
40 return int(value) | 49 return int(value) |
41 except: | 50 except: |
42 return value | 51 return value |
43 | 52 |
44 def findaccount(protocolname, accountname=""): | 53 def findaccount(protocolname, accountname=""): |
45 try: | 54 # prefer connected accounts |
46 # prefer connected accounts | 55 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) |
47 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) | 56 if (account != 0): |
48 return account | 57 return account |
49 except: | 58 |
50 # try to get any account and connect it | 59 # try to get any account and connect it |
51 account = cpurple.PurpleAccountsFindAny(accountname, protocolname) | 60 account = cpurple.PurpleAccountsFindAny(accountname, protocolname) |
52 purple.PurpleAccountSetStatusVargs(account, "online", 1) | 61 if (account == 0): |
53 purple.PurpleAccountConnect(account) | 62 print "No matching account found." |
54 return account | 63 sys.exit(1) |
64 | |
65 purple.PurpleAccountSetStatusVargs(account, "online", 1) | |
66 purple.PurpleAccountConnect(account) | |
67 return account | |
55 | 68 |
56 def goim(account, screenname, message=None): | 69 def goim(account, screenname, message=None): |
57 # XXX: 1 == PURPLE_CONV_TYPE_IM | 70 # XXX: 1 == PURPLE_CONV_TYPE_IM |
58 conversation = cpurple.PurpleConversationNew(1, account, screenname) | 71 conversation = cpurple.PurpleConversationNew(1, account, screenname) |
59 if message: | 72 if message: |
283 return | 296 return |
284 | 297 |
285 uri = argv[1] | 298 uri = argv[1] |
286 type = uri.split(":")[0] | 299 type = uri.split(":")[0] |
287 | 300 |
288 if type == "aim": | 301 try: |
289 aim(uri) | 302 if type == "aim": |
290 elif type == "gg": | 303 aim(uri) |
291 gg(uri) | 304 elif type == "gg": |
292 elif type == "icq": | 305 gg(uri) |
293 icq(uri) | 306 elif type == "icq": |
294 elif type == "irc": | 307 icq(uri) |
295 irc(uri) | 308 elif type == "irc": |
296 elif type == "msnim": | 309 irc(uri) |
297 msnim(uri) | 310 elif type == "msnim": |
298 elif type == "sip": | 311 msnim(uri) |
299 sip(uri) | 312 elif type == "sip": |
300 elif type == "xmpp": | 313 sip(uri) |
301 xmpp(uri) | 314 elif type == "xmpp": |
302 elif type == "ymsgr": | 315 xmpp(uri) |
303 ymsgr(uri) | 316 elif type == "ymsgr": |
304 else: | 317 ymsgr(uri) |
305 print "Unkown protocol: %s" % type | 318 else: |
319 print "Unkown protocol: %s" % type | |
320 except dbus.dbus_bindings.DBusException: | |
321 print "ERROR: Is there a libpurple-powered client (e.g. Pidgin or Finch) running?" | |
322 | |
306 | 323 |
307 if __name__ == "__main__": | 324 if __name__ == "__main__": |
308 main() | 325 main() |