/pidgin/main: 65e477a02dd6: Refactor DBus Python scripts to avoi...
Elliott Sales de Andrade <[email protected]> Tue, 23 Aug 2016 19:45:07 -0400
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 65e477a02dd6a79c0da37103c4b650ec1b8af658 Author: Elliott Sales de Andrade <[email protected]> Date: 2016-08-21 05:32 -0400 Branch: default URL: https://hg.pidgin.im/pidgin/main/rev/65e477a02dd6 Description: Refactor DBus Python scripts to avoid redirection. diffstat: libpurple/Makefile.am | 14 +- libpurple/dbus-analyze-functions.py | 171 ++++++++++++++++++++--------------- libpurple/dbus-analyze-signals.py | 27 ++++- libpurple/dbus-analyze-types.py | 54 +++++----- 4 files changed, 150 insertions(+), 116 deletions(-) diffs (truncated from 494 to 300 lines): diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am --- a/libpurple/Makefile.am +++ b/libpurple/Makefile.am @@ -324,16 +324,16 @@ dbus_signals = $(addprefix $(srcdir)/, $ $(srcdir)/protocols/jabber/jabber.c dbus-types.c: dbus-analyze-types.py $(purple_build_coreheaders) - $(AM_V_GEN)cat $(purple_build_coreheaders) | $(PYTHON) $(srcdir)/dbus-analyze-types.py --pattern=PURPLE_DBUS_DEFINE_TYPE\(%s\) > $@ + $(AM_V_GEN) $(PYTHON) $(srcdir)/dbus-analyze-types.py --pattern=PURPLE_DBUS_DEFINE_TYPE\(%s\) -o $@ $(purple_build_coreheaders) dbus-types.h: dbus-analyze-types.py $(purple_build_coreheaders) - $(AM_V_GEN)cat $(purple_build_coreheaders) | $(PYTHON) $(srcdir)/dbus-analyze-types.py --pattern=PURPLE_DBUS_DECLARE_TYPE\(%s\) > $@ + $(AM_V_GEN) $(PYTHON) $(srcdir)/dbus-analyze-types.py --pattern=PURPLE_DBUS_DECLARE_TYPE\(%s\) -o $@ $(purple_build_coreheaders) dbus-bindings.c: dbus-analyze-functions.py $(dbus_exported) - $(AM_V_GEN)cat $(dbus_build_exported) | $(PYTHON) $(srcdir)/dbus-analyze-functions.py > $@ + $(AM_V_GEN)$(PYTHON) $(srcdir)/dbus-analyze-functions.py -o $@ $(dbus_build_exported) dbus-signals.c: dbus-analyze-signals.py $(dbus_signals) - $(AM_V_GEN)cat $(dbus_signals) | $(PYTHON) $(srcdir)/dbus-analyze-signals.py > $@ + $(AM_V_GEN) $(PYTHON) $(srcdir)/dbus-analyze-signals.py -o $@ $(dbus_signals) dbus-server.$(OBJEXT): dbus-bindings.c dbus-signals.c dbus-types.c dbus-types.h dbus-server.lo: dbus-bindings.c dbus-signals.c dbus-types.c dbus-types.h @@ -348,11 +348,11 @@ libpurple_client_la_LDFLAGS = -version-i libpurple_client_la_LIBADD = $(DBUS_LIBS) purple-client-bindings.c: dbus-analyze-functions.py $(dbus_exported) - $(AM_V_GEN)cat $(dbus_build_exported) | $(PYTHON) $(srcdir)/dbus-analyze-functions.py --client > $@ + $(AM_V_GEN) $(PYTHON) $(srcdir)/dbus-analyze-functions.py --client -o $@ $(dbus_build_exported) purple-client-bindings.h: dbus-analyze-types.py dbus-analyze-functions.py $(purple_coreheaders) $(addprefix ciphers/, $(purple_cipherheaders)) $(addprefix media/, $(purple_mediaheaders)) $(purple_builtheaders) $(dbus_exported) - $(AM_V_GEN)cat $(purple_build_coreheaders) | $(PYTHON) $(srcdir)/dbus-analyze-types.py --keyword=enum --verbatim > $@ - $(AM_V_at)cat $(dbus_build_exported) | $(PYTHON) $(srcdir)/dbus-analyze-functions.py --client --headers >> $@ + $(AM_V_GEN) $(PYTHON) $(srcdir)/dbus-analyze-types.py --keyword=enum --verbatim -o $@ $(purple_build_coreheaders) + $(AM_V_at) $(PYTHON) $(srcdir)/dbus-analyze-functions.py --client --headers --append -o $@ $(dbus_build_exported) $(libpurple_client_la_OBJECTS): purple-client-bindings.h purple-client-bindings.c diff --git a/libpurple/dbus-analyze-functions.py b/libpurple/dbus-analyze-functions.py --- a/libpurple/dbus-analyze-functions.py +++ b/libpurple/dbus-analyze-functions.py @@ -1,4 +1,7 @@ from __future__ import print_function + +import argparse +import fileinput import re import string import sys @@ -126,7 +129,7 @@ class Parameter: fromtokens = staticmethod(fromtokens) class Binding: - def __init__(self, functiontext, paramtexts): + def __init__(self, functiontext, paramtexts, output=None): self.function = Parameter.fromtokens(functiontext.split()) if self.function.name in excluded: @@ -138,15 +141,15 @@ class Binding: self.call = "%s(%s)" % (self.function.name, ", ".join(param.name for param in self.params)) - - + + self.output = output + def process(self): for param in self.params: self.processinput(param.type, param.name) self.processoutput(self.function.type, "RESULT") self.flush() - def processinput(self, type, name): const = False @@ -233,8 +236,9 @@ class Binding: class ClientBinding (Binding): - def __init__(self, functiontext, paramtexts, knowntypes, headersonly): - Binding.__init__(self, functiontext, paramtexts) + def __init__(self, functiontext, paramtexts, knowntypes, headersonly, + **kwargs): + Binding.__init__(self, functiontext, paramtexts, **kwargs) self.knowntypes = knowntypes self.headersonly = headersonly self.paramshdr = [] @@ -248,37 +252,41 @@ class ClientBinding (Binding): if (paramslist == "") : paramslist = "void" print("%s %s(%s)" % (self.functiontype, self.function.name, - paramslist), end=' ') + paramslist), + end=' ', + file=self.output) if self.headersonly: - print(";") + print(";", file=self.output) return - print("{") + print("{", file=self.output) for decl in self.decls: - print(decl) + print(decl, file=self.output) - print('dbus_g_proxy_call(purple_proxy, "%s", NULL,' % ctopascal(self.function.name)) + print('dbus_g_proxy_call(purple_proxy, "%s", NULL,' % ( + ctopascal(self.function.name), ), + file=self.output) for type_name in self.inputparams: - print("\t%s, %s, " % type_name, end=' ') - print("G_TYPE_INVALID,") + print("\t%s, %s, " % type_name, end=' ', file=self.output) + print("G_TYPE_INVALID,", file=self.output) for type_name in self.outputparams: - print("\t%s, &%s, " % type_name, end=' ') - print("G_TYPE_INVALID);") + print("\t%s, &%s, " % type_name, end=' ', file=self.output) + print("G_TYPE_INVALID);", file=self.output) for code in self.returncode: - print(code) + print(code, file=self.output) - print("}\n") - + print("}\n", file=self.output) def definepurplestructure(self, type): if (self.headersonly) and (type[0] not in self.knowntypes): - print("struct _%s;" % type[0]) - print("typedef struct _%s %s;" % (type[0], type[0])) + print("struct _%s;" % type[0], file=self.output) + print("typedef struct _%s %s;" % (type[0], type[0]), + file=self.output) self.knowntypes.append(type[0]) def inputsimple(self, type, name, us): @@ -353,8 +361,8 @@ class ClientBinding (Binding): raise myexception class ServerBinding (Binding): - def __init__(self, functiontext, paramtexts): - Binding.__init__(self, functiontext, paramtexts) + def __init__(self, functiontext, paramtexts, **kwargs): + Binding.__init__(self, functiontext, paramtexts, **kwargs) self.dparams = "" self.cparams = [] self.cdecls = [] @@ -364,40 +372,43 @@ class ServerBinding (Binding): self.argfunc = "dbus_message_get_args" def flush(self): - print("static DBusMessage*") + print("static DBusMessage*", file=self.output) print("%s_DBUS(DBusMessage *message_DBUS, DBusError *error_DBUS) {" % \ - self.function.name) + self.function.name, + file=self.output) - print("\tDBusMessage *reply_DBUS;") + print("\tDBusMessage *reply_DBUS;", file=self.output) for decl in self.cdecls: - print(decl) + print(decl, file=self.output) - print("\t%s(message_DBUS, error_DBUS," % self.argfunc,end=' ') + print("\t%s(message_DBUS, error_DBUS," % self.argfunc, end=' ', + file=self.output) for param in self.cparams: - print("DBUS_TYPE_%s, &%s," % param, end=' ') - print("DBUS_TYPE_INVALID);") + print("DBUS_TYPE_%s, &%s," % param, end=' ', file=self.output) + print("DBUS_TYPE_INVALID);", file=self.output) - print("\tCHECK_ERROR(error_DBUS);") + print("\tCHECK_ERROR(error_DBUS);", file=self.output) for code in self.ccode: - print(code) + print(code, file=self.output) - print("\treply_DBUS = dbus_message_new_method_return (message_DBUS);") + print("\treply_DBUS = dbus_message_new_method_return (message_DBUS);", + file=self.output) - print("\tdbus_message_append_args(reply_DBUS,", end=' ') + print("\tdbus_message_append_args(reply_DBUS,", end=' ', + file=self.output) for param in self.cparamsout: if type(param) is str: - print("%s," % param, end=' ') + print("%s," % param, end=' ', file=self.output) else: - print("DBUS_TYPE_%s, &%s," % param, end=' ') - print("DBUS_TYPE_INVALID);") + print("DBUS_TYPE_%s, &%s," % param, end=' ', file=self.output) + print("DBUS_TYPE_INVALID);", file=self.output) for code in self.ccodeout: - print(code) + print(code, file=self.output) - print("\treturn reply_DBUS;\n}\n") - + print("\treturn reply_DBUS;\n}\n", file=self.output) def addstring(self, *items): for item in items: @@ -541,16 +552,16 @@ class ServerBinding (Binding): class BindingSet: regexp = r"^(\w[^()]*)\(([^()]*)\)\s*;\s*$"; - def __init__(self, inputfile, fprefix): + def __init__(self, inputfile, fprefix, output=None): self.inputiter = iter(inputfile) self.functionregexp = \ re.compile("^%s(\w[^()]*)\(([^()]*)\)\s*;\s*$" % fprefix) self.typeregexp = re.compile("^\w+\s*\*?\s*$") + self.output = output - - def process(self): - print("/* Generated by %s. Do not edit! */" % sys.argv[0]) + print("/* Generated by %s. Do not edit! */" % sys.argv[0], + file=self.output) for line in self.inputiter: words = line.split() @@ -596,37 +607,43 @@ class BindingSet: self.flush() + class ServerBindingSet (BindingSet): - def __init__(self, inputfile, fprefix): - BindingSet.__init__(self, inputfile, fprefix) + def __init__(self, inputfile, fprefix, **kwargs): + BindingSet.__init__(self, inputfile, fprefix, **kwargs) self.functions = [] def processfunction(self, functiontext, paramtexts): - binding = ServerBinding(functiontext, paramtexts) + binding = ServerBinding(functiontext, paramtexts, output=self.output) binding.process() self.functions.append((binding.function.name, binding.dparams)) def flush(self): - print("static PurpleDBusBinding bindings_DBUS[] = { ") + print("static PurpleDBusBinding bindings_DBUS[] = { ", + file=self.output) for function, params in self.functions: print('{"%s", "%s", %s_DBUS},' % \ - (ctopascal(function), params, function)) + (ctopascal(function), params, function), file=self.output) - print("{NULL, NULL, NULL}") - print("};") + print("{NULL, NULL, NULL}", file=self.output) + print("};", file=self.output) - print("#define PURPLE_DBUS_REGISTER_BINDINGS(handle) purple_dbus_register_bindings(handle, bindings_DBUS)") - + print("#define PURPLE_DBUS_REGISTER_BINDINGS(handle) " + "purple_dbus_register_bindings(handle, bindings_DBUS)", + file=self.output) + + class ClientBindingSet (BindingSet): - def __init__(self, inputfile, fprefix, headersonly): - BindingSet.__init__(self, inputfile, fprefix) + def __init__(self, inputfile, fprefix, headersonly, **kwargs): + BindingSet.__init__(self, inputfile, fprefix, **kwargs) self.functions = [] self.knowntypes = [] self.headersonly = headersonly def processfunction(self, functiontext, paramtexts): - binding = ClientBinding(functiontext, paramtexts, self.knowntypes, self.headersonly) + binding = ClientBinding(functiontext, paramtexts, self.knowntypes, + self.headersonly, output=self.output) binding.process() def flush(self): @@ -634,31 +651,35 @@ class ClientBindingSet (BindingSet): # Main program -options = {} _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits