1 # This program takes a C source as the input and produces the list of
2 # all signals registered.
5 # <signal name="Changed">
6 # <arg name="new_value" type="b"/>
8 from __future__
import absolute_import
, division
, print_function
16 # List "excluded" contains signals that shouldn't be exported via
17 # DBus. If you remove a signal from this list, please make sure
18 # that it does not break "make" with the configure option
19 # "--enable-dbus" turned on.
22 # purple_dbus_signal_emit_purple prevents our "dbus-method-called"
23 # signal from being propagated to dbus.
27 registerregex
= re
.compile(
28 "purple_signal_register[^;]+\"([\w\-]+)\"[^;]+(purple_marshal_\w+)[^;]+;")
29 nameregex
= re
.compile('[-_][a-z]')
31 parser
= argparse
.ArgumentParser()
32 parser
.add_argument('input', nargs
='*',
33 help='Input files (or stdin if not specified)')
34 parser
.add_argument('-o', '--output', type=argparse
.FileType('w'),
35 help='Output to file instead of stdout')
36 cmd_args
= parser
.parse_args()
38 print("/* Generated by %s. Do not edit! */" % (sys
.argv
[0], ),
40 print("const char *dbus_signals = ", file=cmd_args
.output
)
41 input = ''.join(list(fileinput
.input(cmd_args
.input)))
42 for match
in registerregex
.finditer(input):
43 signal
= match
.group(1)
44 marshal
= match
.group(2)
45 if signal
in excluded
:
48 signal
= nameregex
.sub(lambda x
: x
.group()[1].upper(), '-' + signal
)
49 print("\" <signal name='%s'>\\n\"" % (signal
, ), file=cmd_args
.output
)
51 args
= marshal
.split('_')
52 # ['purple', 'marshal', <return type>, '', args...]
67 elif arg
== "BOOLEAN":
69 print("\" <arg type='%s'/>\\n\"" % (type, ),
72 print("\" </signal>\\n\"", file=cmd_args
.output
)
74 print(";", file=cmd_args
.output
)