# HG changeset patch # User Richard Laager # Date 1176660918 0 # Node ID d06673964ff97e3f4eabfffd205df89ab7919c0a # Parent 1f42dbf360e30478b08c608dbd2ad4c995a1e94e 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. diff -r 1f42dbf360e3 -r d06673964ff9 libpurple/purple-url-handler --- a/libpurple/purple-url-handler Sun Apr 15 18:13:53 2007 +0000 +++ b/libpurple/purple-url-handler Sun Apr 15 18:15:18 2007 +0000 @@ -22,9 +22,18 @@ self.attr = attr def __call__(self, *args): + # Redirect stderr to suppress the printing of an " Introspect error" + # message if nothing is listening on the bus. We print a friendly + # error message ourselves. + real_stderr = sys.stderr + sys.stderr = None result = self.cobj.obj.__getattr__(self.attr)(*args) - if result == 0: - raise "Error: " + self.attr + " " + str(args) + " returned " + str(result) + sys.stderr = real_stderr + +# This can be useful for debugging. +# if (result == 0): +# print "Error: " + self.attr + " " + str(args) + " returned " + str(result) + return result cpurple = CheckedObject(purple) @@ -42,16 +51,20 @@ return value def findaccount(protocolname, accountname=""): - try: - # prefer connected accounts - account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) - return account - except: - # try to get any account and connect it - account = cpurple.PurpleAccountsFindAny(accountname, protocolname) - purple.PurpleAccountSetStatusVargs(account, "online", 1) - purple.PurpleAccountConnect(account) - return account + # prefer connected accounts + account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) + if (account != 0): + return account + + # try to get any account and connect it + account = cpurple.PurpleAccountsFindAny(accountname, protocolname) + if (account == 0): + print "No matching account found." + sys.exit(1) + + purple.PurpleAccountSetStatusVargs(account, "online", 1) + purple.PurpleAccountConnect(account) + return account def goim(account, screenname, message=None): # XXX: 1 == PURPLE_CONV_TYPE_IM @@ -285,24 +298,28 @@ uri = argv[1] type = uri.split(":")[0] - if type == "aim": - aim(uri) - elif type == "gg": - gg(uri) - elif type == "icq": - icq(uri) - elif type == "irc": - irc(uri) - elif type == "msnim": - msnim(uri) - elif type == "sip": - sip(uri) - elif type == "xmpp": - xmpp(uri) - elif type == "ymsgr": - ymsgr(uri) - else: - print "Unkown protocol: %s" % type + try: + if type == "aim": + aim(uri) + elif type == "gg": + gg(uri) + elif type == "icq": + icq(uri) + elif type == "irc": + irc(uri) + elif type == "msnim": + msnim(uri) + elif type == "sip": + sip(uri) + elif type == "xmpp": + xmpp(uri) + elif type == "ymsgr": + ymsgr(uri) + else: + print "Unkown protocol: %s" % type + except dbus.dbus_bindings.DBusException: + print "ERROR: Is there a libpurple-powered client (e.g. Pidgin or Finch) running?" + if __name__ == "__main__": main()