Tue, 27 Nov 2018 16:54:06 -0600
libpurple: Drop scripts which use the Purple DBus API
| doc/finch.1.in | file | annotate | diff | comparison | revisions | |
| doc/pidgin.1.in | file | annotate | diff | comparison | revisions | |
| libpurple/meson.build | file | annotate | diff | comparison | revisions | |
| libpurple/plugins/startup.py | file | annotate | diff | comparison | revisions | |
| libpurple/purple-notifications-example | file | annotate | diff | comparison | revisions | |
| libpurple/purple-remote | file | annotate | diff | comparison | revisions | |
| libpurple/purple-send | file | annotate | diff | comparison | revisions | |
| libpurple/purple-send-async | file | annotate | diff | comparison | revisions |
--- a/doc/finch.1.in Fri Nov 30 03:02:14 2018 +0000 +++ b/doc/finch.1.in Tue Nov 27 16:54:06 2018 -0600 @@ -590,8 +590,6 @@ .br \fIhttps://developer.pidgin.im/\fR .br -\fBpurple-remote\fR(1) -.br \fBpidgin\fR(1) .SH LICENSE
--- a/doc/pidgin.1.in Fri Nov 30 03:02:14 2018 +0000 +++ b/doc/pidgin.1.in Tue Nov 27 16:54:06 2018 -0600 @@ -34,8 +34,7 @@ many common features found in other clients, as well as many unique features. Pidgin is not endorsed by or affiliated with America Online, ICQ, or Microsoft. .PP -Pidgin can be extended by plugins written in multiple programming languages and -controlled through DBus or \fBpurple-remote\fR. +Pidgin can be extended by plugins written in multiple programming languages. .SH OPTIONS The following options are provided by Pidgin using the standard GNU @@ -570,8 +569,6 @@ .br \fIhttps://developer.pidgin.im/\fR .br -\fBpurple-remote\fR(1) -.br \fBfinch\fR(1) .SH LICENSE
--- a/libpurple/meson.build Fri Nov 30 03:02:14 2018 +0000 +++ b/libpurple/meson.build Tue Nov 27 16:54:06 2018 -0600 @@ -370,11 +370,6 @@ dependencies : [dbus, dbus_glib], install : true) -# scripts - -install_data(['purple-remote', 'purple-send', 'purple-send-async'], - install_dir : get_option('bindir')) - else dbus_sources = []
--- a/libpurple/plugins/startup.py Fri Nov 30 03:02:14 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -# Makes sure only one purple instance is running -# -# Purple is the legal property of its developers, whose names are too numerous -# to list here. Please refer to the COPYRIGHT file distributed with this -# source distribution. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA -# - -from __future__ import absolute_import, division, print_function - -import os -import sys - -import dbus - - -if len(sys.argv) == 1: - print("Usage:", sys.argv[0], "<purple-client> [arguments]") - print("\nExample:\n ", sys.argv[0], "pidgin -d -c /my/home") - sys.exit(1) - -home = os.path.expanduser('~/.purple/') -for arg in range(1, len(sys.argv[1:])): - if sys.argv[arg] == "-c": - home = os.path.expanduser(sys.argv[arg + 1]) - break - -bus = dbus.SessionBus() - -try: - obj = bus.get_object("im.pidgin.purple.PurpleService", - "/im/pidgin/purple/PurpleObject") - purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") - userdir = purple.PurpleUserDir() - if not os.path.isabs(userdir): - userdir = os.path.join(purple.PurpleHomeDir(), userdir) - if home == userdir: - print("Already running.") - purple.PurpleBlistShow() - else: - print("Starting client from a different home directory.") - raise -except: - os.execlp(sys.argv[1], " ".join(sys.argv[2:]))
--- a/libpurple/purple-notifications-example Fri Nov 30 03:02:14 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -#!/usr/bin/env python - -# This is a simple purple notification server. -# It shows notifications when your buddy signs on or you get an IM message. -# -# This script requires Python 2.4 and PyGTK bindings -# -# Note that all function names are resolved dynamically, no -# purple-specific library is needed. - -from __future__ import absolute_import, division, print_function - -import os - -import dbus -import dbus.glib -import dbus.decorators -import gobject - - -def ensureimconversation(conversation, account, name): - if conversation != 0: - return conversation - else: - # 1 = PURPLE_CONV_IM - return purple.PurpleConversationNew(1, account, name) - - -def receivedimmsg(account, name, message, conversation, flags): - buddy = purple.PurpleFindBuddy(account, name) - if buddy != 0: - alias = purple.PurpleBuddyGetAlias(buddy) - else: - alias = name - - text = "%s says %s" % (alias, message) - code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", - "'So what?','Show me',Close,Abuse", text) - - if code == 101: # so what? - pass - else: - conversation = ensureimconversation(conversation, account, name) - - if code == 102: # show me - window = purple.PurpleConversationGetWindow(conversation) - purple.PurpleConvWindowRaise(window) - - if code == 103: # close - purple.PurpleConversationDestroy(conversation) - - if code == 104: # abuse - im = purple.PurpleConversationGetImData(conversation) - purple.PurpleConvImSend(im, "Go away you f...") - - -def buddysignedon(buddyid): - alias = purple.PurpleBuddyGetAlias(buddyid) - text = "%s is online" % alias - - code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", - "'So what?','Let's talk'", text) - - if code == 101: # so what? - pass - - if code == 102: # talk - name = purple.PurpleBuddyGetName(buddyid) - account = purple.PurpleBuddyGetAccount(buddyid) - purple.PurpleConversationNew(1, account, name) - - -bus = dbus.SessionBus() -obj = bus.get_object("im.pidgin.purple.PurpleService", - "/im/pidgin/purple/PurpleObject") -purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") - -bus.add_signal_receiver(receivedimmsg, - dbus_interface="im.pidgin.purple.PurpleInterface", - signal_name="ReceivedImMsg") - -bus.add_signal_receiver(buddysignedon, - dbus_interface="im.pidgin.purple.PurpleInterface", - signal_name="BuddySignedOn") - -print("This is a simple purple notification server.") -print("It shows notifications when your buddy signs on or you get an " - "IM message.") - -loop = gobject.MainLoop() -loop.run()
--- a/libpurple/purple-remote Fri Nov 30 03:02:14 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,266 +0,0 @@ -#!/usr/bin/env python - -from __future__ import absolute_import, division, print_function - -import codecs -import re -import sys -try: - from urllib.parse import unquote -except ImportError: - from urllib import unquote -import xml.dom.minidom - -import dbus - - -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 = None -try: - obj = dbus.SessionBus().get_object("im.pidgin.purple.PurpleService", - "/im/pidgin/purple/PurpleObject") -except: - pass - -purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") - - -class CheckedObject(object): - def __init__(self, obj): - self.obj = obj - - def __getattr__(self, attr): - return CheckedAttribute(self, attr) - - -class CheckedAttribute(object): - def __init__(self, cobj, attr): - self.cobj = cobj - self.attr = attr - - def __call__(self, *args): - result = self.cobj.obj.__getattr__(self.attr)(*args) - if result == 0: - raise Exception("Error: %s %s returned %s" % - (self.attr, args, result)) - return result - - -def show_help(requested=False): - print("""This program uses D-Bus to communicate with purple. - -Usage: - - %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. - -Examples of commands: - - 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 - getstatus - getstatusmessage - quit - - PurpleAccountsFindConnected?name=&protocol=jabber - PurpleAccountsFindConnected(,jabber) -""" % (sys.argv[0], )) - if (requested): - sys.exit(0) - else: - sys.exit(1) - - -cpurple = CheckedObject(purple) - -urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?" - - -def extendlist(list, length, fill): - if len(list) < length: - return list + [fill] * (length - len(list)) - else: - return list - - -def convert(value): - try: - return int(value) - except: - return value - - -def findaccount(accountname, protocolname): - 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 - - -def execute(uri): - match = re.match(urlregexp, uri) - protocol = match.group(2) - if protocol == "xmpp": - protocol = "jabber" - if protocol is not None: - protocol = "prpl-" + protocol - command = match.group(5) - paramstring = match.group(7) - params = {} - if paramstring is not None: - for param in paramstring.split("&"): - key, value = extendlist(param.split("=", 1), 2, "") - params[key] = unquote(value) - - accountname = params.get("account", "") - - if command == "goim": - account = findaccount(accountname, protocol) - conversation = cpurple.PurpleConversationNew(1, account, - params["screenname"]) - if "message" in params: - im = cpurple.PurpleConversationGetImData(conversation) - purple.PurpleConvImSend(im, params["message"]) - return None - - elif command == "gochat": - account = findaccount(accountname, protocol) - connection = cpurple.PurpleAccountGetConnection(account) - return purple.PurpleServJoinChat(connection, params) - - elif command == "addbuddy": - account = findaccount(accountname, protocol) - return cpurple.PurpleBlistRequestAddBuddy(account, - params["screenname"], - params.get("group", ""), - "") - - elif command == "setstatus": - current = purple.PurpleSavedstatusGetCurrent() - - if "status" in params: - status_id = params["status"] - status_type = purple.PurplePrimitiveGetTypeFromId(status_id) - else: - status_type = purple.PurpleSavedstatusGetType(current) - status_id = purple.PurplePrimitiveGetIdFromType(status_type) - - if "message" in params: - message = params["message"] - else: - message = purple.PurpleSavedstatusGetMessage(current) - - if "account" in params: - accounts = [cpurple.PurpleAccountsFindAny(accountname, protocol)] - - for account in accounts: - status = purple.PurpleAccountGetStatus(account, status_id) - type = purple.PurpleStatusGetType(status) - purple.PurpleSavedstatusSetSubstatus(current, account, type, - message) - purple.PurpleSavedstatusActivateForAccount(current, account) - else: - saved = purple.PurpleSavedstatusNew("", status_type) - purple.PurpleSavedstatusSetMessage(saved, message) - purple.PurpleSavedstatusActivate(saved) - - return None - - elif command == "getstatus": - current = purple.PurpleSavedstatusGetCurrent() - status_type = purple.PurpleSavedstatusGetType(current) - status_id = purple.PurplePrimitiveGetIdFromType(status_type) - return status_id - - 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"]) - - elif command == "quit": - return purple.PurpleCoreQuit() - - elif command == "uri": - return None - - else: - match = re.match(r"(\w+)\s*\(([^)]*)\)", command) - if match is not None: - name = match.group(1) - argstr = match.group(2) - if argstr == "": - args = [] - else: - args = argstr.split(",") - fargs = [] - for arg in args: - fargs.append(convert(arg.strip())) - return purple.__getattr__(name)(*fargs) - else: - # Introspect the object to get parameter names and types. This is - # slow because the entire introspection info must be downloaded. - interface = dbus.Interface(obj, - "org.freedesktop.DBus.Introspectable") - data = interface.Introspect() - introspect = xml.dom.minidom.parseString(data).documentElement - for method in introspect.all("method"): - if command == method.getAttribute("name"): - methodparams = [] - for arg in method.all("arg"): - if arg.getAttribute("direction") == "in": - value = params[arg.getAttribute("name")] - type = arg.getAttribute("type") - if type == "s": - methodparams.append(value) - elif type == "i": - methodparams.append(int(value)) - else: - raise Exception( - "Don't know how to handle type \"%s\"" % ( - type, )) - return purple.__getattr__(command)(*methodparams) - show_help() - - -if len(sys.argv) == 1: - show_help() -elif sys.argv[1] == "--help" or sys.argv[1] == "-h": - show_help(True) -elif obj is None: - print("No existing libpurple instance detected.") - sys.exit(1) - -for arg in sys.argv[1:]: - output = execute(arg) - - if output is not None: - print(output)
--- a/libpurple/purple-send Fri Nov 30 03:02:14 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#!/bin/sh - -METHOD_NAME=$1 - -if test -z "$METHOD_NAME" -then - cat <<EOF -This program calls purple API functions using DBus and prints the return value. -If you are not interested in the return value, use purple-send-async. - -Usage: - - $0 method-name type1:parameter1 type2:parameter2 ... - -This shell script just invokes dbus-send, see man dbus-send for how -to specify the parameters. - -Examples: - - $0 PurpleAccountsFindConnected string: string:jabber - $0 PurpleAccountsGetAll - $0 PurpleCoreQuit - -Use dbus-viewer to get the list of supported functions and their parameters. -EOF - exit 1 -fi - -shift -dbus-send --dest=im.pidgin.purple.PurpleService --print-reply --type=method_call /im/pidgin/purple/PurpleObject im.pidgin.purple.PurpleInterface.$METHOD_NAME "$@" -
--- a/libpurple/purple-send-async Fri Nov 30 03:02:14 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -#!/bin/sh - -METHOD_NAME=$1 - -if test -z "$METHOD_NAME" -then - cat <<EOF -This program calls purple API functions using DBus. As opposed to purple-send, -it does not print the return value. - -Usage: - - $0 method-name type1:parameter1 type2:parameter2 ... - -This shell script just invokes dbus-send, see man dbus-send for how -to specify the parameters. - -Examples: - - $0 PurpleCoreQuit - -Use dbus-viewer to get the list of supported functions and their parameters. -EOF - exit 1 -fi - -shift -dbus-send --dest=im.pidgin.purple.PurpleService --type=method_call /im/pidgin/purple/PurpleObject im.pidgin.purple.PurpleInterface.$METHOD_NAME "$@" -