mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
py: Reformat all Python files consistently
This commit is the unmodified results of running ``` black $(git ls-files '*.py') ``` with black version 19.10b0. See #2046. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
@@ -21,7 +21,9 @@
|
||||
|
||||
import os
|
||||
|
||||
builddir = os.environ.get('UNINSTALLED_GLIB_BUILDDIR')
|
||||
builddir = os.environ.get("UNINSTALLED_GLIB_BUILDDIR")
|
||||
|
||||
if builddir is not None:
|
||||
__path__.append(os.path.abspath(os.path.join(builddir, 'gio', 'gdbus-2.0', 'codegen')))
|
||||
__path__.append(
|
||||
os.path.abspath(os.path.join(builddir, "gio", "gdbus-2.0", "codegen"))
|
||||
)
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,7 @@ from . import parser
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class DocbookCodeGenerator:
|
||||
def __init__(self, ifaces):
|
||||
self.ifaces = ifaces
|
||||
@@ -57,23 +58,36 @@ class DocbookCodeGenerator:
|
||||
max_signature_len = max(len(a.signature), max_signature_len)
|
||||
|
||||
if in_synopsis:
|
||||
self.out.write('<link linkend="gdbus-method-%s.%s">%s</link>%*s ('
|
||||
%(utils.dots_to_hyphens(i.name), m.name, m.name, max_method_len - len(m.name), ''))
|
||||
self.out.write(
|
||||
'<link linkend="gdbus-method-%s.%s">%s</link>%*s ('
|
||||
% (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
m.name,
|
||||
m.name,
|
||||
max_method_len - len(m.name),
|
||||
"",
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.out.write('%s%*s ('
|
||||
%(m.name, max_method_len - len(m.name), ''))
|
||||
self.out.write("%s%*s (" % (m.name, max_method_len - len(m.name), ""))
|
||||
count = 0
|
||||
for a in m.in_args:
|
||||
if (count > 0):
|
||||
self.out.write(',\n%*s'%(max_method_len + 2, ''))
|
||||
self.out.write('IN %s%*s %s'%(a.signature, max_signature_len - len(a.signature), '', a.name))
|
||||
if count > 0:
|
||||
self.out.write(",\n%*s" % (max_method_len + 2, ""))
|
||||
self.out.write(
|
||||
"IN %s%*s %s"
|
||||
% (a.signature, max_signature_len - len(a.signature), "", a.name)
|
||||
)
|
||||
count = count + 1
|
||||
for a in m.out_args:
|
||||
if (count > 0):
|
||||
self.out.write(',\n%*s'%(max_method_len + 2, ''))
|
||||
self.out.write('OUT %s%*s %s'%(a.signature, max_signature_len - len(a.signature), '', a.name))
|
||||
if count > 0:
|
||||
self.out.write(",\n%*s" % (max_method_len + 2, ""))
|
||||
self.out.write(
|
||||
"OUT %s%*s %s"
|
||||
% (a.signature, max_signature_len - len(a.signature), "", a.name)
|
||||
)
|
||||
count = count + 1
|
||||
self.out.write(');\n')
|
||||
self.out.write(");\n")
|
||||
|
||||
def print_signal_prototype(self, i, s, in_synopsis):
|
||||
max_signal_len = 0
|
||||
@@ -93,18 +107,28 @@ class DocbookCodeGenerator:
|
||||
max_signature_len = max(len(a.signature), max_signature_len)
|
||||
|
||||
if in_synopsis:
|
||||
self.out.write('<link linkend="gdbus-signal-%s.%s">%s</link>%*s ('
|
||||
%(utils.dots_to_hyphens(i.name), s.name, s.name, max_signal_len - len(s.name), ''))
|
||||
self.out.write(
|
||||
'<link linkend="gdbus-signal-%s.%s">%s</link>%*s ('
|
||||
% (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
s.name,
|
||||
s.name,
|
||||
max_signal_len - len(s.name),
|
||||
"",
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.out.write('%s%*s ('
|
||||
%(s.name, max_signal_len - len(s.name), ''))
|
||||
self.out.write("%s%*s (" % (s.name, max_signal_len - len(s.name), ""))
|
||||
count = 0
|
||||
for a in s.args:
|
||||
if (count > 0):
|
||||
self.out.write(',\n%*s'%(max_signal_len + 2, ''))
|
||||
self.out.write('%s%*s %s'%(a.signature, max_signature_len - len(a.signature), '', a.name))
|
||||
if count > 0:
|
||||
self.out.write(",\n%*s" % (max_signal_len + 2, ""))
|
||||
self.out.write(
|
||||
"%s%*s %s"
|
||||
% (a.signature, max_signature_len - len(a.signature), "", a.name)
|
||||
)
|
||||
count = count + 1
|
||||
self.out.write(');\n')
|
||||
self.out.write(");\n")
|
||||
|
||||
def print_property_prototype(self, i, p, in_synopsis):
|
||||
max_property_len = 0
|
||||
@@ -122,109 +146,181 @@ class DocbookCodeGenerator:
|
||||
max_signature_len = max(len(p.signature), max_signature_len)
|
||||
|
||||
if in_synopsis:
|
||||
self.out.write('<link linkend="gdbus-property-%s.%s">%s</link>%*s'
|
||||
%(utils.dots_to_hyphens(i.name), p.name, p.name, max_property_len - len(p.name), ''))
|
||||
self.out.write(
|
||||
'<link linkend="gdbus-property-%s.%s">%s</link>%*s'
|
||||
% (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
p.name,
|
||||
p.name,
|
||||
max_property_len - len(p.name),
|
||||
"",
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.out.write('%s%*s'
|
||||
%(p.name, max_property_len - len(p.name), ''))
|
||||
self.out.write("%s%*s" % (p.name, max_property_len - len(p.name), ""))
|
||||
if p.readable and p.writable:
|
||||
access = 'readwrite'
|
||||
access = "readwrite"
|
||||
elif p.readable:
|
||||
access = 'readable '
|
||||
access = "readable "
|
||||
else:
|
||||
access = 'writable '
|
||||
self.out.write(' %s %s\n'%(access, p.signature))
|
||||
|
||||
access = "writable "
|
||||
self.out.write(" %s %s\n" % (access, p.signature))
|
||||
|
||||
def print_synopsis_methods(self, i):
|
||||
self.out.write(' <refsynopsisdiv role="synopsis">\n'%())
|
||||
self.out.write(' <title role="synopsis.title">Methods</title>\n'%())
|
||||
self.out.write(' <synopsis>\n'%())
|
||||
self.out.write(' <refsynopsisdiv role="synopsis">\n' % ())
|
||||
self.out.write(' <title role="synopsis.title">Methods</title>\n' % ())
|
||||
self.out.write(" <synopsis>\n" % ())
|
||||
for m in i.methods:
|
||||
self.print_method_prototype(i, m, in_synopsis=True)
|
||||
self.out.write('</synopsis>\n'%())
|
||||
self.out.write(' </refsynopsisdiv>\n'%())
|
||||
self.out.write("</synopsis>\n" % ())
|
||||
self.out.write(" </refsynopsisdiv>\n" % ())
|
||||
|
||||
def print_synopsis_signals(self, i):
|
||||
self.out.write(' <refsect1 role="signal_proto">\n'%())
|
||||
self.out.write(' <title role="signal_proto.title">Signals</title>\n'%())
|
||||
self.out.write(' <synopsis>\n'%())
|
||||
self.out.write(' <refsect1 role="signal_proto">\n' % ())
|
||||
self.out.write(' <title role="signal_proto.title">Signals</title>\n' % ())
|
||||
self.out.write(" <synopsis>\n" % ())
|
||||
for s in i.signals:
|
||||
self.print_signal_prototype(i, s, in_synopsis=True)
|
||||
self.out.write('</synopsis>\n'%())
|
||||
self.out.write(' </refsect1>\n'%())
|
||||
self.out.write("</synopsis>\n" % ())
|
||||
self.out.write(" </refsect1>\n" % ())
|
||||
|
||||
def print_synopsis_properties(self, i):
|
||||
self.out.write(' <refsect1 role="properties">\n'%())
|
||||
self.out.write(' <title role="properties.title">Properties</title>\n'%())
|
||||
self.out.write(' <synopsis>\n'%())
|
||||
self.out.write(' <refsect1 role="properties">\n' % ())
|
||||
self.out.write(' <title role="properties.title">Properties</title>\n' % ())
|
||||
self.out.write(" <synopsis>\n" % ())
|
||||
for p in i.properties:
|
||||
self.print_property_prototype(i, p, in_synopsis=True)
|
||||
self.out.write('</synopsis>\n'%())
|
||||
self.out.write(' </refsect1>\n'%())
|
||||
self.out.write("</synopsis>\n" % ())
|
||||
self.out.write(" </refsect1>\n" % ())
|
||||
|
||||
def print_method(self, i, m):
|
||||
self.out.write('<refsect2 role="method" id="gdbus-method-%s.%s">\n'%(utils.dots_to_hyphens(i.name), m.name))
|
||||
self.out.write(' <title>The %s() method</title>\n'%(m.name))
|
||||
self.out.write(' <indexterm zone="gdbus-method-%s.%s"><primary sortas="%s.%s">%s.%s()</primary></indexterm>\n'%(utils.dots_to_hyphens(i.name), m.name, i.name_without_prefix, m.name, i.name, m.name))
|
||||
self.out.write('<programlisting>\n')
|
||||
self.out.write(
|
||||
'<refsect2 role="method" id="gdbus-method-%s.%s">\n'
|
||||
% (utils.dots_to_hyphens(i.name), m.name)
|
||||
)
|
||||
self.out.write(" <title>The %s() method</title>\n" % (m.name))
|
||||
self.out.write(
|
||||
' <indexterm zone="gdbus-method-%s.%s"><primary sortas="%s.%s">%s.%s()</primary></indexterm>\n'
|
||||
% (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
m.name,
|
||||
i.name_without_prefix,
|
||||
m.name,
|
||||
i.name,
|
||||
m.name,
|
||||
)
|
||||
)
|
||||
self.out.write("<programlisting>\n")
|
||||
self.print_method_prototype(i, m, in_synopsis=False)
|
||||
self.out.write('</programlisting>\n')
|
||||
self.out.write('%s\n'%(self.expand_paras(m.doc_string, True)))
|
||||
self.out.write("</programlisting>\n")
|
||||
self.out.write("%s\n" % (self.expand_paras(m.doc_string, True)))
|
||||
if m.in_args or m.out_args:
|
||||
self.out.write('<variablelist role="params">\n')
|
||||
for a in m.in_args:
|
||||
self.out.write('<varlistentry>\n'%())
|
||||
self.out.write(' <term><literal>IN %s <parameter>%s</parameter></literal>:</term>\n'%(a.signature, a.name))
|
||||
self.out.write(' <listitem>%s</listitem>\n'%(self.expand_paras(a.doc_string, True)))
|
||||
self.out.write('</varlistentry>\n'%())
|
||||
self.out.write("<varlistentry>\n" % ())
|
||||
self.out.write(
|
||||
" <term><literal>IN %s <parameter>%s</parameter></literal>:</term>\n"
|
||||
% (a.signature, a.name)
|
||||
)
|
||||
self.out.write(
|
||||
" <listitem>%s</listitem>\n"
|
||||
% (self.expand_paras(a.doc_string, True))
|
||||
)
|
||||
self.out.write("</varlistentry>\n" % ())
|
||||
for a in m.out_args:
|
||||
self.out.write('<varlistentry>\n'%())
|
||||
self.out.write(' <term><literal>OUT %s <parameter>%s</parameter></literal>:</term>\n'%(a.signature, a.name))
|
||||
self.out.write(' <listitem>%s</listitem>\n'%(self.expand_paras(a.doc_string, True)))
|
||||
self.out.write('</varlistentry>\n'%())
|
||||
self.out.write('</variablelist>\n')
|
||||
self.out.write("<varlistentry>\n" % ())
|
||||
self.out.write(
|
||||
" <term><literal>OUT %s <parameter>%s</parameter></literal>:</term>\n"
|
||||
% (a.signature, a.name)
|
||||
)
|
||||
self.out.write(
|
||||
" <listitem>%s</listitem>\n"
|
||||
% (self.expand_paras(a.doc_string, True))
|
||||
)
|
||||
self.out.write("</varlistentry>\n" % ())
|
||||
self.out.write("</variablelist>\n")
|
||||
if len(m.since) > 0:
|
||||
self.out.write('<para role="since">Since %s</para>\n'%(m.since))
|
||||
self.out.write('<para role="since">Since %s</para>\n' % (m.since))
|
||||
if m.deprecated:
|
||||
self.out.write('<warning><para>The %s() method is deprecated.</para></warning>'%(m.name))
|
||||
self.out.write('</refsect2>\n')
|
||||
self.out.write(
|
||||
"<warning><para>The %s() method is deprecated.</para></warning>"
|
||||
% (m.name)
|
||||
)
|
||||
self.out.write("</refsect2>\n")
|
||||
|
||||
def print_signal(self, i, s):
|
||||
self.out.write('<refsect2 role="signal" id="gdbus-signal-%s.%s">\n'%(utils.dots_to_hyphens(i.name), s.name))
|
||||
self.out.write(' <title>The "%s" signal</title>\n'%(s.name))
|
||||
self.out.write(' <indexterm zone="gdbus-signal-%s.%s"><primary sortas="%s::%s">%s::%s</primary></indexterm>\n'%(utils.dots_to_hyphens(i.name), s.name, i.name_without_prefix, s.name, i.name, s.name))
|
||||
self.out.write('<programlisting>\n')
|
||||
self.out.write(
|
||||
'<refsect2 role="signal" id="gdbus-signal-%s.%s">\n'
|
||||
% (utils.dots_to_hyphens(i.name), s.name)
|
||||
)
|
||||
self.out.write(' <title>The "%s" signal</title>\n' % (s.name))
|
||||
self.out.write(
|
||||
' <indexterm zone="gdbus-signal-%s.%s"><primary sortas="%s::%s">%s::%s</primary></indexterm>\n'
|
||||
% (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
s.name,
|
||||
i.name_without_prefix,
|
||||
s.name,
|
||||
i.name,
|
||||
s.name,
|
||||
)
|
||||
)
|
||||
self.out.write("<programlisting>\n")
|
||||
self.print_signal_prototype(i, s, in_synopsis=False)
|
||||
self.out.write('</programlisting>\n')
|
||||
self.out.write('%s\n'%(self.expand_paras(s.doc_string, True)))
|
||||
self.out.write("</programlisting>\n")
|
||||
self.out.write("%s\n" % (self.expand_paras(s.doc_string, True)))
|
||||
if s.args:
|
||||
self.out.write('<variablelist role="params">\n')
|
||||
for a in s.args:
|
||||
self.out.write('<varlistentry>\n'%())
|
||||
self.out.write(' <term><literal>%s <parameter>%s</parameter></literal>:</term>\n'%(a.signature, a.name))
|
||||
self.out.write(' <listitem>%s</listitem>\n'%(self.expand_paras(a.doc_string, True)))
|
||||
self.out.write('</varlistentry>\n'%())
|
||||
self.out.write('</variablelist>\n')
|
||||
self.out.write("<varlistentry>\n" % ())
|
||||
self.out.write(
|
||||
" <term><literal>%s <parameter>%s</parameter></literal>:</term>\n"
|
||||
% (a.signature, a.name)
|
||||
)
|
||||
self.out.write(
|
||||
" <listitem>%s</listitem>\n"
|
||||
% (self.expand_paras(a.doc_string, True))
|
||||
)
|
||||
self.out.write("</varlistentry>\n" % ())
|
||||
self.out.write("</variablelist>\n")
|
||||
if len(s.since) > 0:
|
||||
self.out.write('<para role="since">Since %s</para>\n'%(s.since))
|
||||
self.out.write('<para role="since">Since %s</para>\n' % (s.since))
|
||||
if s.deprecated:
|
||||
self.out.write('<warning><para>The "%s" signal is deprecated.</para></warning>'%(s.name))
|
||||
self.out.write('</refsect2>\n')
|
||||
self.out.write(
|
||||
'<warning><para>The "%s" signal is deprecated.</para></warning>'
|
||||
% (s.name)
|
||||
)
|
||||
self.out.write("</refsect2>\n")
|
||||
|
||||
def print_property(self, i, p):
|
||||
self.out.write('<refsect2 role="property" id="gdbus-property-%s.%s">\n'%(utils.dots_to_hyphens(i.name), p.name))
|
||||
self.out.write(' <title>The "%s" property</title>\n'%(p.name))
|
||||
self.out.write(' <indexterm zone="gdbus-property-%s.%s"><primary sortas="%s:%s">%s:%s</primary></indexterm>\n'%(utils.dots_to_hyphens(i.name), p.name, i.name_without_prefix, p.name, i.name, p.name))
|
||||
self.out.write('<programlisting>\n')
|
||||
self.out.write(
|
||||
'<refsect2 role="property" id="gdbus-property-%s.%s">\n'
|
||||
% (utils.dots_to_hyphens(i.name), p.name)
|
||||
)
|
||||
self.out.write(' <title>The "%s" property</title>\n' % (p.name))
|
||||
self.out.write(
|
||||
' <indexterm zone="gdbus-property-%s.%s"><primary sortas="%s:%s">%s:%s</primary></indexterm>\n'
|
||||
% (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
p.name,
|
||||
i.name_without_prefix,
|
||||
p.name,
|
||||
i.name,
|
||||
p.name,
|
||||
)
|
||||
)
|
||||
self.out.write("<programlisting>\n")
|
||||
self.print_property_prototype(i, p, in_synopsis=False)
|
||||
self.out.write('</programlisting>\n')
|
||||
self.out.write('%s\n'%(self.expand_paras(p.doc_string, True)))
|
||||
self.out.write("</programlisting>\n")
|
||||
self.out.write("%s\n" % (self.expand_paras(p.doc_string, True)))
|
||||
if len(p.since) > 0:
|
||||
self.out.write('<para role="since">Since %s</para>\n'%(p.since))
|
||||
self.out.write('<para role="since">Since %s</para>\n' % (p.since))
|
||||
if p.deprecated:
|
||||
self.out.write('<warning><para>The "%s" property is deprecated.</para></warning>'%(p.name))
|
||||
self.out.write('</refsect2>\n')
|
||||
self.out.write(
|
||||
'<warning><para>The "%s" property is deprecated.</para></warning>'
|
||||
% (p.name)
|
||||
)
|
||||
self.out.write("</refsect2>\n")
|
||||
|
||||
def expand(self, s, expandParamsAndConstants):
|
||||
for key in self.expand_member_dict_keys:
|
||||
@@ -233,9 +329,17 @@ class DocbookCodeGenerator:
|
||||
s = s.replace(key, self.expand_iface_dict[key])
|
||||
if expandParamsAndConstants:
|
||||
# replace @foo with <parameter>foo</parameter>
|
||||
s = re.sub('@[a-zA-Z0-9_]*', lambda m: '<parameter>' + m.group(0)[1:] + '</parameter>', s)
|
||||
s = re.sub(
|
||||
"@[a-zA-Z0-9_]*",
|
||||
lambda m: "<parameter>" + m.group(0)[1:] + "</parameter>",
|
||||
s,
|
||||
)
|
||||
# replace e.g. %TRUE with <constant>TRUE</constant>
|
||||
s = re.sub('%[a-zA-Z0-9_]*', lambda m: '<constant>' + m.group(0)[1:] + '</constant>', s)
|
||||
s = re.sub(
|
||||
"%[a-zA-Z0-9_]*",
|
||||
lambda m: "<constant>" + m.group(0)[1:] + "</constant>",
|
||||
s,
|
||||
)
|
||||
return s
|
||||
|
||||
def expand_paras(self, s, expandParamsAndConstants):
|
||||
@@ -248,44 +352,75 @@ class DocbookCodeGenerator:
|
||||
self.expand_member_dict = {}
|
||||
self.expand_iface_dict = {}
|
||||
for i in self.ifaces:
|
||||
key = '#%s'%(i.name)
|
||||
value = '<link linkend="gdbus-interface-%s.top_of_page">%s</link>'%(utils.dots_to_hyphens(i.name), i.name)
|
||||
key = "#%s" % (i.name)
|
||||
value = '<link linkend="gdbus-interface-%s.top_of_page">%s</link>' % (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
i.name,
|
||||
)
|
||||
self.expand_iface_dict[key] = value
|
||||
for m in i.methods:
|
||||
key = '%s.%s()'%(i.name, m.name)
|
||||
value = '<link linkend="gdbus-method-%s.%s">%s()</link>'%(utils.dots_to_hyphens(i.name), m.name, m.name)
|
||||
key = "%s.%s()" % (i.name, m.name)
|
||||
value = '<link linkend="gdbus-method-%s.%s">%s()</link>' % (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
m.name,
|
||||
m.name,
|
||||
)
|
||||
self.expand_member_dict[key] = value
|
||||
for s in i.signals:
|
||||
key = '#%s::%s'%(i.name, s.name)
|
||||
value = '<link linkend="gdbus-signal-%s.%s">"%s"</link>'%(utils.dots_to_hyphens(i.name), s.name, s.name)
|
||||
key = "#%s::%s" % (i.name, s.name)
|
||||
value = '<link linkend="gdbus-signal-%s.%s">"%s"</link>' % (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
s.name,
|
||||
s.name,
|
||||
)
|
||||
self.expand_member_dict[key] = value
|
||||
for p in i.properties:
|
||||
key = '#%s:%s'%(i.name, p.name)
|
||||
value = '<link linkend="gdbus-property-%s.%s">"%s"</link>'%(utils.dots_to_hyphens(i.name), p.name, p.name)
|
||||
key = "#%s:%s" % (i.name, p.name)
|
||||
value = '<link linkend="gdbus-property-%s.%s">"%s"</link>' % (
|
||||
utils.dots_to_hyphens(i.name),
|
||||
p.name,
|
||||
p.name,
|
||||
)
|
||||
self.expand_member_dict[key] = value
|
||||
# Make sure to expand the keys in reverse order so e.g. #org.foo.Iface:MediaCompat
|
||||
# is evaluated before #org.foo.Iface:Media ...
|
||||
self.expand_member_dict_keys = sorted(self.expand_member_dict.keys(), reverse=True)
|
||||
self.expand_iface_dict_keys = sorted(self.expand_iface_dict.keys(), reverse=True)
|
||||
self.expand_member_dict_keys = sorted(
|
||||
self.expand_member_dict.keys(), reverse=True
|
||||
)
|
||||
self.expand_iface_dict_keys = sorted(
|
||||
self.expand_iface_dict.keys(), reverse=True
|
||||
)
|
||||
|
||||
def generate(self, docbook, outdir):
|
||||
for i in self.ifaces:
|
||||
self.out = open(path.join(outdir, '%s-%s.xml'%(docbook, i.name)), 'w')
|
||||
self.out.write(''%())
|
||||
self.out.write('<?xml version="1.0" encoding="utf-8"?>\n'%())
|
||||
self.out.write('<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n'%())
|
||||
self.out.write(' "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [\n'%())
|
||||
self.out.write(']>\n'%())
|
||||
self.out.write('<refentry id="gdbus-%s">\n'%(i.name))
|
||||
self.out.write(' <refmeta>'%())
|
||||
self.out.write(' <refentrytitle role="top_of_page" id="gdbus-interface-%s.top_of_page">%s</refentrytitle>\n'%(utils.dots_to_hyphens(i.name), i.name))
|
||||
self.out.write(' <indexterm zone="gdbus-interface-%s.top_of_page"><primary sortas="%s">%s</primary></indexterm>\n'%(utils.dots_to_hyphens(i.name), i.name_without_prefix, i.name))
|
||||
self.out.write(' </refmeta>'%())
|
||||
self.out = open(path.join(outdir, "%s-%s.xml" % (docbook, i.name)), "w")
|
||||
self.out.write("" % ())
|
||||
self.out.write('<?xml version="1.0" encoding="utf-8"?>\n' % ())
|
||||
self.out.write(
|
||||
'<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n'
|
||||
% ()
|
||||
)
|
||||
self.out.write(
|
||||
' "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [\n'
|
||||
% ()
|
||||
)
|
||||
self.out.write("]>\n" % ())
|
||||
self.out.write('<refentry id="gdbus-%s">\n' % (i.name))
|
||||
self.out.write(" <refmeta>" % ())
|
||||
self.out.write(
|
||||
' <refentrytitle role="top_of_page" id="gdbus-interface-%s.top_of_page">%s</refentrytitle>\n'
|
||||
% (utils.dots_to_hyphens(i.name), i.name)
|
||||
)
|
||||
self.out.write(
|
||||
' <indexterm zone="gdbus-interface-%s.top_of_page"><primary sortas="%s">%s</primary></indexterm>\n'
|
||||
% (utils.dots_to_hyphens(i.name), i.name_without_prefix, i.name)
|
||||
)
|
||||
self.out.write(" </refmeta>" % ())
|
||||
|
||||
self.out.write(' <refnamediv>'%())
|
||||
self.out.write(' <refname>%s</refname>'%(i.name))
|
||||
self.out.write(' <refpurpose>%s</refpurpose>'%(i.doc_string_brief))
|
||||
self.out.write(' </refnamediv>'%())
|
||||
self.out.write(" <refnamediv>" % ())
|
||||
self.out.write(" <refname>%s</refname>" % (i.name))
|
||||
self.out.write(" <refpurpose>%s</refpurpose>" % (i.doc_string_brief))
|
||||
self.out.write(" </refnamediv>" % ())
|
||||
|
||||
if len(i.methods) > 0:
|
||||
self.print_synopsis_methods(i)
|
||||
@@ -294,36 +429,53 @@ class DocbookCodeGenerator:
|
||||
if len(i.properties) > 0:
|
||||
self.print_synopsis_properties(i)
|
||||
|
||||
self.out.write('<refsect1 role="desc" id="gdbus-interface-%s">\n'%(utils.dots_to_hyphens(i.name)))
|
||||
self.out.write(' <title role="desc.title">Description</title>\n'%())
|
||||
self.out.write(' %s\n'%(self.expand_paras(i.doc_string, True)))
|
||||
self.out.write(
|
||||
'<refsect1 role="desc" id="gdbus-interface-%s">\n'
|
||||
% (utils.dots_to_hyphens(i.name))
|
||||
)
|
||||
self.out.write(' <title role="desc.title">Description</title>\n' % ())
|
||||
self.out.write(" %s\n" % (self.expand_paras(i.doc_string, True)))
|
||||
if len(i.since) > 0:
|
||||
self.out.write(' <para role="since">Since %s</para>\n'%(i.since))
|
||||
self.out.write(' <para role="since">Since %s</para>\n' % (i.since))
|
||||
if i.deprecated:
|
||||
self.out.write('<warning><para>The %s interface is deprecated.</para></warning>'%(i.name))
|
||||
self.out.write('</refsect1>\n'%())
|
||||
self.out.write(
|
||||
"<warning><para>The %s interface is deprecated.</para></warning>"
|
||||
% (i.name)
|
||||
)
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
|
||||
if len(i.methods) > 0:
|
||||
self.out.write('<refsect1 role="details" id="gdbus-methods-%s">\n'%(i.name))
|
||||
self.out.write(' <title role="details.title">Method Details</title>\n'%())
|
||||
self.out.write(
|
||||
'<refsect1 role="details" id="gdbus-methods-%s">\n' % (i.name)
|
||||
)
|
||||
self.out.write(
|
||||
' <title role="details.title">Method Details</title>\n' % ()
|
||||
)
|
||||
for m in i.methods:
|
||||
self.print_method(i, m)
|
||||
self.out.write('</refsect1>\n'%())
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
|
||||
if len(i.signals) > 0:
|
||||
self.out.write('<refsect1 role="details" id="gdbus-signals-%s">\n'%(i.name))
|
||||
self.out.write(' <title role="details.title">Signal Details</title>\n'%())
|
||||
self.out.write(
|
||||
'<refsect1 role="details" id="gdbus-signals-%s">\n' % (i.name)
|
||||
)
|
||||
self.out.write(
|
||||
' <title role="details.title">Signal Details</title>\n' % ()
|
||||
)
|
||||
for s in i.signals:
|
||||
self.print_signal(i, s)
|
||||
self.out.write('</refsect1>\n'%())
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
|
||||
if len(i.properties) > 0:
|
||||
self.out.write('<refsect1 role="details" id="gdbus-properties-%s">\n'%(i.name))
|
||||
self.out.write(' <title role="details.title">Property Details</title>\n'%())
|
||||
self.out.write(
|
||||
'<refsect1 role="details" id="gdbus-properties-%s">\n' % (i.name)
|
||||
)
|
||||
self.out.write(
|
||||
' <title role="details.title">Property Details</title>\n' % ()
|
||||
)
|
||||
for s in i.properties:
|
||||
self.print_property(i, s)
|
||||
self.out.write('</refsect1>\n'%())
|
||||
|
||||
self.out.write('</refentry>\n')
|
||||
self.out.write('\n')
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
|
||||
self.out.write("</refentry>\n")
|
||||
self.out.write("\n")
|
||||
|
@@ -32,30 +32,35 @@ from . import codegen
|
||||
from . import codegen_docbook
|
||||
from .utils import print_error, print_warning
|
||||
|
||||
|
||||
def find_arg(arg_list, arg_name):
|
||||
for a in arg_list:
|
||||
if a.name == arg_name:
|
||||
return a
|
||||
return None
|
||||
|
||||
|
||||
def find_method(iface, method):
|
||||
for m in iface.methods:
|
||||
if m.name == method:
|
||||
return m
|
||||
return None
|
||||
|
||||
|
||||
def find_signal(iface, signal):
|
||||
for m in iface.signals:
|
||||
if m.name == signal:
|
||||
return m
|
||||
return None
|
||||
|
||||
|
||||
def find_prop(iface, prop):
|
||||
for m in iface.properties:
|
||||
if m.name == prop:
|
||||
return m
|
||||
return None
|
||||
|
||||
|
||||
def apply_annotation(iface_list, iface, method, signal, prop, arg, key, value):
|
||||
iface_obj = None
|
||||
for i in iface_list:
|
||||
@@ -74,10 +79,14 @@ def apply_annotation(iface_list, iface, method, signal, prop, arg, key, value):
|
||||
print_error('No method "{}" on interface "{}"'.format(method, iface))
|
||||
if arg:
|
||||
arg_obj = find_arg(method_obj.in_args, arg)
|
||||
if (arg_obj is None):
|
||||
if arg_obj is None:
|
||||
arg_obj = find_arg(method_obj.out_args, arg)
|
||||
if (arg_obj is None):
|
||||
print_error('No arg "{}" on method "{}" on interface "{}"'.format(arg, method, iface))
|
||||
if arg_obj is None:
|
||||
print_error(
|
||||
'No arg "{}" on method "{}" on interface "{}"'.format(
|
||||
arg, method, iface
|
||||
)
|
||||
)
|
||||
target_obj = arg_obj
|
||||
else:
|
||||
target_obj = method_obj
|
||||
@@ -87,8 +96,12 @@ def apply_annotation(iface_list, iface, method, signal, prop, arg, key, value):
|
||||
print_error('No signal "{}" on interface "{}"'.format(signal, iface))
|
||||
if arg:
|
||||
arg_obj = find_arg(signal_obj.args, arg)
|
||||
if (arg_obj is None):
|
||||
print_error('No arg "{}" on signal "{}" on interface "{}"'.format(arg, signal, iface))
|
||||
if arg_obj is None:
|
||||
print_error(
|
||||
'No arg "{}" on signal "{}" on interface "{}"'.format(
|
||||
arg, signal, iface
|
||||
)
|
||||
)
|
||||
target_obj = arg_obj
|
||||
else:
|
||||
target_obj = signal_obj
|
||||
@@ -105,198 +118,287 @@ def apply_annotation(iface_list, iface, method, signal, prop, arg, key, value):
|
||||
def apply_annotations(iface_list, annotation_list):
|
||||
# apply annotations given on the command line
|
||||
for (what, key, value) in annotation_list:
|
||||
pos = what.find('::')
|
||||
pos = what.find("::")
|
||||
if pos != -1:
|
||||
# signal
|
||||
iface = what[0:pos];
|
||||
signal = what[pos + 2:]
|
||||
pos = signal.find('[')
|
||||
iface = what[0:pos]
|
||||
signal = what[pos + 2 :]
|
||||
pos = signal.find("[")
|
||||
if pos != -1:
|
||||
arg = signal[pos + 1:]
|
||||
arg = signal[pos + 1 :]
|
||||
signal = signal[0:pos]
|
||||
pos = arg.find(']')
|
||||
pos = arg.find("]")
|
||||
arg = arg[0:pos]
|
||||
apply_annotation(iface_list, iface, None, signal, None, arg, key, value)
|
||||
else:
|
||||
apply_annotation(iface_list, iface, None, signal, None, None, key, value)
|
||||
apply_annotation(
|
||||
iface_list, iface, None, signal, None, None, key, value
|
||||
)
|
||||
else:
|
||||
pos = what.find(':')
|
||||
pos = what.find(":")
|
||||
if pos != -1:
|
||||
# property
|
||||
iface = what[0:pos];
|
||||
prop = what[pos + 1:]
|
||||
iface = what[0:pos]
|
||||
prop = what[pos + 1 :]
|
||||
apply_annotation(iface_list, iface, None, None, prop, None, key, value)
|
||||
else:
|
||||
pos = what.find('()')
|
||||
pos = what.find("()")
|
||||
if pos != -1:
|
||||
# method
|
||||
combined = what[0:pos]
|
||||
pos = combined.rfind('.')
|
||||
pos = combined.rfind(".")
|
||||
iface = combined[0:pos]
|
||||
method = combined[pos + 1:]
|
||||
pos = what.find('[')
|
||||
method = combined[pos + 1 :]
|
||||
pos = what.find("[")
|
||||
if pos != -1:
|
||||
arg = what[pos + 1:]
|
||||
pos = arg.find(']')
|
||||
arg = what[pos + 1 :]
|
||||
pos = arg.find("]")
|
||||
arg = arg[0:pos]
|
||||
apply_annotation(iface_list, iface, method, None, None, arg, key, value)
|
||||
apply_annotation(
|
||||
iface_list, iface, method, None, None, arg, key, value
|
||||
)
|
||||
else:
|
||||
apply_annotation(iface_list, iface, method, None, None, None, key, value)
|
||||
apply_annotation(
|
||||
iface_list, iface, method, None, None, None, key, value
|
||||
)
|
||||
else:
|
||||
# must be an interface
|
||||
iface = what
|
||||
apply_annotation(iface_list, iface, None, None, None, None, key, value)
|
||||
apply_annotation(
|
||||
iface_list, iface, None, None, None, None, key, value
|
||||
)
|
||||
|
||||
|
||||
def codegen_main():
|
||||
arg_parser = argparse.ArgumentParser(description='D-Bus code and documentation generator')
|
||||
arg_parser.add_argument('files', metavar='FILE', nargs='+',
|
||||
help='D-Bus introspection XML file')
|
||||
arg_parser.add_argument('--xml-files', metavar='FILE', action='append', default=[],
|
||||
help=argparse.SUPPRESS)
|
||||
arg_parser.add_argument('--interface-prefix', metavar='PREFIX', default='',
|
||||
help='String to strip from D-Bus interface names for code and docs')
|
||||
arg_parser.add_argument('--c-namespace', metavar='NAMESPACE', default='',
|
||||
help='The namespace to use for generated C code')
|
||||
arg_parser.add_argument('--c-generate-object-manager', action='store_true',
|
||||
help='Generate a GDBusObjectManagerClient subclass when generating C code')
|
||||
arg_parser.add_argument('--c-generate-autocleanup', choices=['none', 'objects', 'all'], default='objects',
|
||||
help='Generate autocleanup support')
|
||||
arg_parser.add_argument('--generate-docbook', metavar='OUTFILES',
|
||||
help='Generate Docbook in OUTFILES-org.Project.IFace.xml')
|
||||
arg_parser.add_argument('--pragma-once', action='store_true',
|
||||
help='Use "pragma once" as the inclusion guard')
|
||||
arg_parser.add_argument('--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
|
||||
help='Add annotation (may be used several times)')
|
||||
arg_parser.add_argument('--glib-min-required', metavar='VERSION',
|
||||
help='Minimum version of GLib to be supported by the outputted code (default: 2.30)')
|
||||
arg_parser.add_argument('--glib-max-allowed', metavar='VERSION',
|
||||
help='Maximum version of GLib to be used by the outputted code (default: current GLib version)')
|
||||
arg_parser.add_argument('--symbol-decorator',
|
||||
help='Macro used to decorate a symbol in the outputted header, possibly to export symbols')
|
||||
arg_parser.add_argument('--symbol-decorator-header',
|
||||
help='Additional header required for decorator specified by --symbol-decorator')
|
||||
arg_parser.add_argument('--symbol-decorator-define',
|
||||
help='Additional define required for decorator specified by --symbol-decorator')
|
||||
arg_parser = argparse.ArgumentParser(
|
||||
description="D-Bus code and documentation generator"
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"files", metavar="FILE", nargs="+", help="D-Bus introspection XML file"
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--xml-files",
|
||||
metavar="FILE",
|
||||
action="append",
|
||||
default=[],
|
||||
help=argparse.SUPPRESS,
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--interface-prefix",
|
||||
metavar="PREFIX",
|
||||
default="",
|
||||
help="String to strip from D-Bus interface names for code and docs",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--c-namespace",
|
||||
metavar="NAMESPACE",
|
||||
default="",
|
||||
help="The namespace to use for generated C code",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--c-generate-object-manager",
|
||||
action="store_true",
|
||||
help="Generate a GDBusObjectManagerClient subclass when generating C code",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--c-generate-autocleanup",
|
||||
choices=["none", "objects", "all"],
|
||||
default="objects",
|
||||
help="Generate autocleanup support",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--generate-docbook",
|
||||
metavar="OUTFILES",
|
||||
help="Generate Docbook in OUTFILES-org.Project.IFace.xml",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--pragma-once",
|
||||
action="store_true",
|
||||
help='Use "pragma once" as the inclusion guard',
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--annotate",
|
||||
nargs=3,
|
||||
action="append",
|
||||
metavar="WHAT KEY VALUE",
|
||||
help="Add annotation (may be used several times)",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--glib-min-required",
|
||||
metavar="VERSION",
|
||||
help="Minimum version of GLib to be supported by the outputted code (default: 2.30)",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--glib-max-allowed",
|
||||
metavar="VERSION",
|
||||
help="Maximum version of GLib to be used by the outputted code (default: current GLib version)",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--symbol-decorator",
|
||||
help="Macro used to decorate a symbol in the outputted header, possibly to export symbols",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--symbol-decorator-header",
|
||||
help="Additional header required for decorator specified by --symbol-decorator",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--symbol-decorator-define",
|
||||
help="Additional define required for decorator specified by --symbol-decorator",
|
||||
)
|
||||
|
||||
group = arg_parser.add_mutually_exclusive_group()
|
||||
group.add_argument('--generate-c-code', metavar='OUTFILES',
|
||||
help='Generate C code in OUTFILES.[ch]')
|
||||
group.add_argument('--header', action='store_true',
|
||||
help='Generate C headers')
|
||||
group.add_argument('--body', action='store_true',
|
||||
help='Generate C code')
|
||||
group.add_argument('--interface-info-header', action='store_true',
|
||||
help='Generate GDBusInterfaceInfo C header')
|
||||
group.add_argument('--interface-info-body', action='store_true',
|
||||
help='Generate GDBusInterfaceInfo C code')
|
||||
group.add_argument(
|
||||
"--generate-c-code", metavar="OUTFILES", help="Generate C code in OUTFILES.[ch]"
|
||||
)
|
||||
group.add_argument("--header", action="store_true", help="Generate C headers")
|
||||
group.add_argument("--body", action="store_true", help="Generate C code")
|
||||
group.add_argument(
|
||||
"--interface-info-header",
|
||||
action="store_true",
|
||||
help="Generate GDBusInterfaceInfo C header",
|
||||
)
|
||||
group.add_argument(
|
||||
"--interface-info-body",
|
||||
action="store_true",
|
||||
help="Generate GDBusInterfaceInfo C code",
|
||||
)
|
||||
|
||||
group = arg_parser.add_mutually_exclusive_group()
|
||||
group.add_argument('--output', metavar='FILE',
|
||||
help='Write output into the specified file')
|
||||
group.add_argument('--output-directory', metavar='OUTDIR', default='',
|
||||
help='Location to output generated files')
|
||||
group.add_argument(
|
||||
"--output", metavar="FILE", help="Write output into the specified file"
|
||||
)
|
||||
group.add_argument(
|
||||
"--output-directory",
|
||||
metavar="OUTDIR",
|
||||
default="",
|
||||
help="Location to output generated files",
|
||||
)
|
||||
|
||||
args = arg_parser.parse_args();
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
if len(args.xml_files) > 0:
|
||||
print_warning('The "--xml-files" option is deprecated; use positional arguments instead')
|
||||
print_warning(
|
||||
'The "--xml-files" option is deprecated; use positional arguments instead'
|
||||
)
|
||||
|
||||
if ((args.generate_c_code is not None or args.generate_docbook is not None) and
|
||||
args.output is not None):
|
||||
print_error('Using --generate-c-code or --generate-docbook and '
|
||||
'--output at the same time is not allowed')
|
||||
if (
|
||||
args.generate_c_code is not None or args.generate_docbook is not None
|
||||
) and args.output is not None:
|
||||
print_error(
|
||||
"Using --generate-c-code or --generate-docbook and "
|
||||
"--output at the same time is not allowed"
|
||||
)
|
||||
|
||||
if args.generate_c_code:
|
||||
header_name = args.generate_c_code + '.h'
|
||||
header_name = args.generate_c_code + ".h"
|
||||
h_file = os.path.join(args.output_directory, header_name)
|
||||
args.header = True
|
||||
c_file = os.path.join(args.output_directory, args.generate_c_code + '.c')
|
||||
c_file = os.path.join(args.output_directory, args.generate_c_code + ".c")
|
||||
args.body = True
|
||||
elif args.header:
|
||||
if args.output is None:
|
||||
print_error('Using --header requires --output')
|
||||
print_error("Using --header requires --output")
|
||||
|
||||
h_file = args.output
|
||||
header_name = os.path.basename(h_file)
|
||||
elif args.body:
|
||||
if args.output is None:
|
||||
print_error('Using --body requires --output')
|
||||
print_error("Using --body requires --output")
|
||||
|
||||
c_file = args.output
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + '.h'
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + ".h"
|
||||
elif args.interface_info_header:
|
||||
if args.output is None:
|
||||
print_error('Using --interface-info-header requires --output')
|
||||
print_error("Using --interface-info-header requires --output")
|
||||
if args.c_generate_object_manager:
|
||||
print_error('--c-generate-object-manager is incompatible with '
|
||||
'--interface-info-header')
|
||||
print_error(
|
||||
"--c-generate-object-manager is incompatible with "
|
||||
"--interface-info-header"
|
||||
)
|
||||
|
||||
h_file = args.output
|
||||
header_name = os.path.basename(h_file)
|
||||
elif args.interface_info_body:
|
||||
if args.output is None:
|
||||
print_error('Using --interface-info-body requires --output')
|
||||
print_error("Using --interface-info-body requires --output")
|
||||
if args.c_generate_object_manager:
|
||||
print_error('--c-generate-object-manager is incompatible with '
|
||||
'--interface-info-body')
|
||||
print_error(
|
||||
"--c-generate-object-manager is incompatible with "
|
||||
"--interface-info-body"
|
||||
)
|
||||
|
||||
c_file = args.output
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + '.h'
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + ".h"
|
||||
|
||||
# Check the minimum GLib version. The minimum --glib-min-required is 2.30,
|
||||
# because that’s when gdbus-codegen was introduced. Support 1, 2 or 3
|
||||
# component versions, but ignore the micro component if it’s present.
|
||||
if args.glib_min_required:
|
||||
try:
|
||||
parts = args.glib_min_required.split('.', 3)
|
||||
glib_min_required = (int(parts[0]),
|
||||
int(parts[1] if len(parts) > 1 else 0))
|
||||
parts = args.glib_min_required.split(".", 3)
|
||||
glib_min_required = (int(parts[0]), int(parts[1] if len(parts) > 1 else 0))
|
||||
# Ignore micro component, but still validate it:
|
||||
_ = int(parts[2] if len(parts) > 2 else 0)
|
||||
except (ValueError, IndexError):
|
||||
print_error('Unrecognized --glib-min-required string ‘{}’'.format(
|
||||
args.glib_min_required))
|
||||
print_error(
|
||||
"Unrecognized --glib-min-required string ‘{}’".format(
|
||||
args.glib_min_required
|
||||
)
|
||||
)
|
||||
|
||||
if glib_min_required < (2, 30):
|
||||
print_error('Invalid --glib-min-required string ‘{}’: minimum '
|
||||
'version is 2.30'.format(args.glib_min_required))
|
||||
print_error(
|
||||
"Invalid --glib-min-required string ‘{}’: minimum "
|
||||
"version is 2.30".format(args.glib_min_required)
|
||||
)
|
||||
else:
|
||||
glib_min_required = (2, 30)
|
||||
|
||||
# And the maximum GLib version.
|
||||
if args.glib_max_allowed:
|
||||
try:
|
||||
parts = args.glib_max_allowed.split('.', 3)
|
||||
glib_max_allowed = (int(parts[0]),
|
||||
int(parts[1] if len(parts) > 1 else 0))
|
||||
parts = args.glib_max_allowed.split(".", 3)
|
||||
glib_max_allowed = (int(parts[0]), int(parts[1] if len(parts) > 1 else 0))
|
||||
# Ignore micro component, but still validate it:
|
||||
_ = int(parts[2] if len(parts) > 2 else 0)
|
||||
except (ValueError, IndexError):
|
||||
print_error('Unrecognized --glib-max-allowed string ‘{}’'.format(
|
||||
args.glib_max_allowed))
|
||||
print_error(
|
||||
"Unrecognized --glib-max-allowed string ‘{}’".format(
|
||||
args.glib_max_allowed
|
||||
)
|
||||
)
|
||||
else:
|
||||
glib_max_allowed = (config.MAJOR_VERSION, config.MINOR_VERSION)
|
||||
|
||||
# Only allow --symbol-decorator-define and --symbol-decorator-header if --symbol-decorator is used
|
||||
if args.symbol_decorator is None:
|
||||
if args.symbol_decorator_header or args.symbol_decorator_define:
|
||||
print_error('--symbol-decorator-define and --symbol-decorator-header must be used with --symbol-decorator')
|
||||
print_error(
|
||||
"--symbol-decorator-define and --symbol-decorator-header must be used with --symbol-decorator"
|
||||
)
|
||||
|
||||
# Round --glib-max-allowed up to the next stable release.
|
||||
glib_max_allowed = \
|
||||
(glib_max_allowed[0], glib_max_allowed[1] + (glib_max_allowed[1] % 2))
|
||||
glib_max_allowed = (
|
||||
glib_max_allowed[0],
|
||||
glib_max_allowed[1] + (glib_max_allowed[1] % 2),
|
||||
)
|
||||
|
||||
if glib_max_allowed < glib_min_required:
|
||||
print_error('Invalid versions: --glib-min-required ({}) must be '
|
||||
'less than or equal to --glib-max-allowed ({})'.format(glib_min_required, glib_max_allowed))
|
||||
print_error(
|
||||
"Invalid versions: --glib-min-required ({}) must be "
|
||||
"less than or equal to --glib-max-allowed ({})".format(
|
||||
glib_min_required, glib_max_allowed
|
||||
)
|
||||
)
|
||||
|
||||
all_ifaces = []
|
||||
input_files_basenames = []
|
||||
for fname in sorted(args.files + args.xml_files):
|
||||
with open(fname, 'rb') as f:
|
||||
with open(fname, "rb") as f:
|
||||
xml_data = f.read()
|
||||
parsed_ifaces = parser.parse_dbus_xml(xml_data,
|
||||
h_type_implies_unix_fd=(glib_min_required >= (2, 64)))
|
||||
parsed_ifaces = parser.parse_dbus_xml(
|
||||
xml_data, h_type_implies_unix_fd=(glib_min_required >= (2, 64))
|
||||
)
|
||||
all_ifaces.extend(parsed_ifaces)
|
||||
input_files_basenames.append(os.path.basename(fname))
|
||||
|
||||
@@ -307,63 +409,72 @@ def codegen_main():
|
||||
i.post_process(args.interface_prefix, args.c_namespace)
|
||||
|
||||
docbook = args.generate_docbook
|
||||
docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces);
|
||||
docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces)
|
||||
if docbook:
|
||||
ret = docbook_gen.generate(docbook, args.output_directory)
|
||||
|
||||
if args.header:
|
||||
with open(h_file, 'w') as outfile:
|
||||
gen = codegen.HeaderCodeGenerator(all_ifaces,
|
||||
args.c_namespace,
|
||||
args.c_generate_object_manager,
|
||||
args.c_generate_autocleanup,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
args.pragma_once,
|
||||
glib_min_required,
|
||||
args.symbol_decorator,
|
||||
args.symbol_decorator_header,
|
||||
outfile)
|
||||
with open(h_file, "w") as outfile:
|
||||
gen = codegen.HeaderCodeGenerator(
|
||||
all_ifaces,
|
||||
args.c_namespace,
|
||||
args.c_generate_object_manager,
|
||||
args.c_generate_autocleanup,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
args.pragma_once,
|
||||
glib_min_required,
|
||||
args.symbol_decorator,
|
||||
args.symbol_decorator_header,
|
||||
outfile,
|
||||
)
|
||||
gen.generate()
|
||||
|
||||
if args.body:
|
||||
with open(c_file, 'w') as outfile:
|
||||
gen = codegen.CodeGenerator(all_ifaces,
|
||||
args.c_namespace,
|
||||
args.c_generate_object_manager,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
docbook_gen,
|
||||
glib_min_required,
|
||||
args.symbol_decorator_define,
|
||||
outfile)
|
||||
with open(c_file, "w") as outfile:
|
||||
gen = codegen.CodeGenerator(
|
||||
all_ifaces,
|
||||
args.c_namespace,
|
||||
args.c_generate_object_manager,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
docbook_gen,
|
||||
glib_min_required,
|
||||
args.symbol_decorator_define,
|
||||
outfile,
|
||||
)
|
||||
gen.generate()
|
||||
|
||||
if args.interface_info_header:
|
||||
with open(h_file, 'w') as outfile:
|
||||
gen = codegen.InterfaceInfoHeaderCodeGenerator(all_ifaces,
|
||||
args.c_namespace,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
args.pragma_once,
|
||||
glib_min_required,
|
||||
args.symbol_decorator,
|
||||
args.symbol_decorator_header,
|
||||
outfile)
|
||||
with open(h_file, "w") as outfile:
|
||||
gen = codegen.InterfaceInfoHeaderCodeGenerator(
|
||||
all_ifaces,
|
||||
args.c_namespace,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
args.pragma_once,
|
||||
glib_min_required,
|
||||
args.symbol_decorator,
|
||||
args.symbol_decorator_header,
|
||||
outfile,
|
||||
)
|
||||
gen.generate()
|
||||
|
||||
if args.interface_info_body:
|
||||
with open(c_file, 'w') as outfile:
|
||||
gen = codegen.InterfaceInfoBodyCodeGenerator(all_ifaces,
|
||||
args.c_namespace,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
glib_min_required,
|
||||
args.symbol_decorator_define,
|
||||
outfile)
|
||||
with open(c_file, "w") as outfile:
|
||||
gen = codegen.InterfaceInfoBodyCodeGenerator(
|
||||
all_ifaces,
|
||||
args.c_namespace,
|
||||
header_name,
|
||||
input_files_basenames,
|
||||
glib_min_required,
|
||||
args.symbol_decorator_define,
|
||||
outfile,
|
||||
)
|
||||
gen.generate()
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
codegen_main()
|
||||
|
@@ -22,22 +22,30 @@
|
||||
from . import utils
|
||||
from .utils import print_error
|
||||
|
||||
|
||||
class Annotation:
|
||||
def __init__(self, key, value):
|
||||
self.key = key
|
||||
self.value = value
|
||||
self.annotations = []
|
||||
self.since = ''
|
||||
self.since = ""
|
||||
|
||||
def post_process(self, interface_prefix, cns, cns_upper, cns_lower, container):
|
||||
key = self.key
|
||||
overridden_key = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
overridden_key = utils.lookup_annotation(
|
||||
self.annotations, "org.gtk.GDBus.C.Name"
|
||||
)
|
||||
if utils.is_ugly_case(overridden_key):
|
||||
self.key_lower = overridden_key.lower()
|
||||
else:
|
||||
if overridden_key:
|
||||
key = overridden_key
|
||||
self.key_lower = utils.camel_case_to_uscore(key).lower().replace('-', '_').replace('.', '_')
|
||||
self.key_lower = (
|
||||
utils.camel_case_to_uscore(key)
|
||||
.lower()
|
||||
.replace("-", "_")
|
||||
.replace(".", "_")
|
||||
)
|
||||
|
||||
if len(self.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
@@ -47,13 +55,14 @@ class Annotation:
|
||||
for a in self.annotations:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
|
||||
class Arg:
|
||||
def __init__(self, name, signature):
|
||||
self.name = name
|
||||
self.signature = signature
|
||||
self.annotations = []
|
||||
self.doc_string = ''
|
||||
self.since = ''
|
||||
self.doc_string = ""
|
||||
self.since = ""
|
||||
|
||||
def post_process(self, interface_prefix, cns, cns_upper, cns_lower, arg_number):
|
||||
if len(self.doc_string) == 0:
|
||||
@@ -62,195 +71,198 @@ class Arg:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
if self.name is None:
|
||||
self.name = 'unnamed_arg%d'%arg_number
|
||||
self.name = "unnamed_arg%d" % arg_number
|
||||
# default to GVariant
|
||||
self.ctype_in_g = 'GVariant *'
|
||||
self.ctype_in = 'GVariant *'
|
||||
self.ctype_in_dup = 'GVariant *'
|
||||
self.ctype_out = 'GVariant **'
|
||||
self.gtype = 'G_TYPE_VARIANT'
|
||||
self.free_func = 'g_variant_unref'
|
||||
self.format_in = '@' + self.signature
|
||||
self.format_out = '@' + self.signature
|
||||
self.gvariant_get = 'XXX'
|
||||
self.gvalue_get = 'g_value_get_variant'
|
||||
self.array_annotation = ''
|
||||
self.ctype_in_g = "GVariant *"
|
||||
self.ctype_in = "GVariant *"
|
||||
self.ctype_in_dup = "GVariant *"
|
||||
self.ctype_out = "GVariant **"
|
||||
self.gtype = "G_TYPE_VARIANT"
|
||||
self.free_func = "g_variant_unref"
|
||||
self.format_in = "@" + self.signature
|
||||
self.format_out = "@" + self.signature
|
||||
self.gvariant_get = "XXX"
|
||||
self.gvalue_get = "g_value_get_variant"
|
||||
self.array_annotation = ""
|
||||
|
||||
if not utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
|
||||
if self.signature == 'b':
|
||||
self.ctype_in_g = 'gboolean '
|
||||
self.ctype_in = 'gboolean '
|
||||
self.ctype_out = 'gboolean *'
|
||||
self.gtype = 'G_TYPE_BOOLEAN'
|
||||
if not utils.lookup_annotation(
|
||||
self.annotations, "org.gtk.GDBus.C.ForceGVariant"
|
||||
):
|
||||
if self.signature == "b":
|
||||
self.ctype_in_g = "gboolean "
|
||||
self.ctype_in = "gboolean "
|
||||
self.ctype_out = "gboolean *"
|
||||
self.gtype = "G_TYPE_BOOLEAN"
|
||||
self.free_func = None
|
||||
self.format_in = 'b'
|
||||
self.format_out = 'b'
|
||||
self.gvariant_get = 'g_variant_get_boolean'
|
||||
self.gvalue_get = 'g_value_get_boolean'
|
||||
elif self.signature == 'y':
|
||||
self.ctype_in_g = 'guchar '
|
||||
self.ctype_in = 'guchar '
|
||||
self.ctype_out = 'guchar *'
|
||||
self.gtype = 'G_TYPE_UCHAR'
|
||||
self.format_in = "b"
|
||||
self.format_out = "b"
|
||||
self.gvariant_get = "g_variant_get_boolean"
|
||||
self.gvalue_get = "g_value_get_boolean"
|
||||
elif self.signature == "y":
|
||||
self.ctype_in_g = "guchar "
|
||||
self.ctype_in = "guchar "
|
||||
self.ctype_out = "guchar *"
|
||||
self.gtype = "G_TYPE_UCHAR"
|
||||
self.free_func = None
|
||||
self.format_in = 'y'
|
||||
self.format_out = 'y'
|
||||
self.gvariant_get = 'g_variant_get_byte'
|
||||
self.gvalue_get = 'g_value_get_uchar'
|
||||
elif self.signature == 'n':
|
||||
self.ctype_in_g = 'gint '
|
||||
self.ctype_in = 'gint16 '
|
||||
self.ctype_out = 'gint16 *'
|
||||
self.gtype = 'G_TYPE_INT'
|
||||
self.format_in = "y"
|
||||
self.format_out = "y"
|
||||
self.gvariant_get = "g_variant_get_byte"
|
||||
self.gvalue_get = "g_value_get_uchar"
|
||||
elif self.signature == "n":
|
||||
self.ctype_in_g = "gint "
|
||||
self.ctype_in = "gint16 "
|
||||
self.ctype_out = "gint16 *"
|
||||
self.gtype = "G_TYPE_INT"
|
||||
self.free_func = None
|
||||
self.format_in = 'n'
|
||||
self.format_out = 'n'
|
||||
self.gvariant_get = 'g_variant_get_int16'
|
||||
self.gvalue_get = 'g_value_get_int'
|
||||
elif self.signature == 'q':
|
||||
self.ctype_in_g = 'guint '
|
||||
self.ctype_in = 'guint16 '
|
||||
self.ctype_out = 'guint16 *'
|
||||
self.gtype = 'G_TYPE_UINT'
|
||||
self.format_in = "n"
|
||||
self.format_out = "n"
|
||||
self.gvariant_get = "g_variant_get_int16"
|
||||
self.gvalue_get = "g_value_get_int"
|
||||
elif self.signature == "q":
|
||||
self.ctype_in_g = "guint "
|
||||
self.ctype_in = "guint16 "
|
||||
self.ctype_out = "guint16 *"
|
||||
self.gtype = "G_TYPE_UINT"
|
||||
self.free_func = None
|
||||
self.format_in = 'q'
|
||||
self.format_out = 'q'
|
||||
self.gvariant_get = 'g_variant_get_uint16'
|
||||
self.gvalue_get = 'g_value_get_uint'
|
||||
elif self.signature == 'i':
|
||||
self.ctype_in_g = 'gint '
|
||||
self.ctype_in = 'gint '
|
||||
self.ctype_out = 'gint *'
|
||||
self.gtype = 'G_TYPE_INT'
|
||||
self.format_in = "q"
|
||||
self.format_out = "q"
|
||||
self.gvariant_get = "g_variant_get_uint16"
|
||||
self.gvalue_get = "g_value_get_uint"
|
||||
elif self.signature == "i":
|
||||
self.ctype_in_g = "gint "
|
||||
self.ctype_in = "gint "
|
||||
self.ctype_out = "gint *"
|
||||
self.gtype = "G_TYPE_INT"
|
||||
self.free_func = None
|
||||
self.format_in = 'i'
|
||||
self.format_out = 'i'
|
||||
self.gvariant_get = 'g_variant_get_int32'
|
||||
self.gvalue_get = 'g_value_get_int'
|
||||
elif self.signature == 'u':
|
||||
self.ctype_in_g = 'guint '
|
||||
self.ctype_in = 'guint '
|
||||
self.ctype_out = 'guint *'
|
||||
self.gtype = 'G_TYPE_UINT'
|
||||
self.format_in = "i"
|
||||
self.format_out = "i"
|
||||
self.gvariant_get = "g_variant_get_int32"
|
||||
self.gvalue_get = "g_value_get_int"
|
||||
elif self.signature == "u":
|
||||
self.ctype_in_g = "guint "
|
||||
self.ctype_in = "guint "
|
||||
self.ctype_out = "guint *"
|
||||
self.gtype = "G_TYPE_UINT"
|
||||
self.free_func = None
|
||||
self.format_in = 'u'
|
||||
self.format_out = 'u'
|
||||
self.gvariant_get = 'g_variant_get_uint32'
|
||||
self.gvalue_get = 'g_value_get_uint'
|
||||
elif self.signature == 'x':
|
||||
self.ctype_in_g = 'gint64 '
|
||||
self.ctype_in = 'gint64 '
|
||||
self.ctype_out = 'gint64 *'
|
||||
self.gtype = 'G_TYPE_INT64'
|
||||
self.format_in = "u"
|
||||
self.format_out = "u"
|
||||
self.gvariant_get = "g_variant_get_uint32"
|
||||
self.gvalue_get = "g_value_get_uint"
|
||||
elif self.signature == "x":
|
||||
self.ctype_in_g = "gint64 "
|
||||
self.ctype_in = "gint64 "
|
||||
self.ctype_out = "gint64 *"
|
||||
self.gtype = "G_TYPE_INT64"
|
||||
self.free_func = None
|
||||
self.format_in = 'x'
|
||||
self.format_out = 'x'
|
||||
self.gvariant_get = 'g_variant_get_int64'
|
||||
self.gvalue_get = 'g_value_get_int64'
|
||||
elif self.signature == 't':
|
||||
self.ctype_in_g = 'guint64 '
|
||||
self.ctype_in = 'guint64 '
|
||||
self.ctype_out = 'guint64 *'
|
||||
self.gtype = 'G_TYPE_UINT64'
|
||||
self.format_in = "x"
|
||||
self.format_out = "x"
|
||||
self.gvariant_get = "g_variant_get_int64"
|
||||
self.gvalue_get = "g_value_get_int64"
|
||||
elif self.signature == "t":
|
||||
self.ctype_in_g = "guint64 "
|
||||
self.ctype_in = "guint64 "
|
||||
self.ctype_out = "guint64 *"
|
||||
self.gtype = "G_TYPE_UINT64"
|
||||
self.free_func = None
|
||||
self.format_in = 't'
|
||||
self.format_out = 't'
|
||||
self.gvariant_get = 'g_variant_get_uint64'
|
||||
self.gvalue_get = 'g_value_get_uint64'
|
||||
elif self.signature == 'd':
|
||||
self.ctype_in_g = 'gdouble '
|
||||
self.ctype_in = 'gdouble '
|
||||
self.ctype_out = 'gdouble *'
|
||||
self.gtype = 'G_TYPE_DOUBLE'
|
||||
self.format_in = "t"
|
||||
self.format_out = "t"
|
||||
self.gvariant_get = "g_variant_get_uint64"
|
||||
self.gvalue_get = "g_value_get_uint64"
|
||||
elif self.signature == "d":
|
||||
self.ctype_in_g = "gdouble "
|
||||
self.ctype_in = "gdouble "
|
||||
self.ctype_out = "gdouble *"
|
||||
self.gtype = "G_TYPE_DOUBLE"
|
||||
self.free_func = None
|
||||
self.format_in = 'd'
|
||||
self.format_out = 'd'
|
||||
self.gvariant_get = 'g_variant_get_double'
|
||||
self.gvalue_get = 'g_value_get_double'
|
||||
elif self.signature == 's':
|
||||
self.ctype_in_g = 'const gchar *'
|
||||
self.ctype_in = 'const gchar *'
|
||||
self.ctype_in_dup = 'gchar *'
|
||||
self.ctype_out = 'gchar **'
|
||||
self.gtype = 'G_TYPE_STRING'
|
||||
self.free_func = 'g_free'
|
||||
self.format_in = 's'
|
||||
self.format_out = 's'
|
||||
self.gvariant_get = 'g_variant_get_string'
|
||||
self.gvalue_get = 'g_value_get_string'
|
||||
elif self.signature == 'o':
|
||||
self.ctype_in_g = 'const gchar *'
|
||||
self.ctype_in = 'const gchar *'
|
||||
self.ctype_in_dup = 'gchar *'
|
||||
self.ctype_out = 'gchar **'
|
||||
self.gtype = 'G_TYPE_STRING'
|
||||
self.free_func = 'g_free'
|
||||
self.format_in = 'o'
|
||||
self.format_out = 'o'
|
||||
self.gvariant_get = 'g_variant_get_string'
|
||||
self.gvalue_get = 'g_value_get_string'
|
||||
elif self.signature == 'g':
|
||||
self.ctype_in_g = 'const gchar *'
|
||||
self.ctype_in = 'const gchar *'
|
||||
self.ctype_in_dup = 'gchar *'
|
||||
self.ctype_out = 'gchar **'
|
||||
self.gtype = 'G_TYPE_STRING'
|
||||
self.free_func = 'g_free'
|
||||
self.format_in = 'g'
|
||||
self.format_out = 'g'
|
||||
self.gvariant_get = 'g_variant_get_string'
|
||||
self.gvalue_get = 'g_value_get_string'
|
||||
elif self.signature == 'ay':
|
||||
self.ctype_in_g = 'const gchar *'
|
||||
self.ctype_in = 'const gchar *'
|
||||
self.ctype_in_dup = 'gchar *'
|
||||
self.ctype_out = 'gchar **'
|
||||
self.gtype = 'G_TYPE_STRING'
|
||||
self.free_func = 'g_free'
|
||||
self.format_in = '^ay'
|
||||
self.format_out = '^ay'
|
||||
self.gvariant_get = 'g_variant_get_bytestring'
|
||||
self.gvalue_get = 'g_value_get_string'
|
||||
elif self.signature == 'as':
|
||||
self.ctype_in_g = 'const gchar *const *'
|
||||
self.ctype_in = 'const gchar *const *'
|
||||
self.ctype_in_dup = 'gchar **'
|
||||
self.ctype_out = 'gchar ***'
|
||||
self.gtype = 'G_TYPE_STRV'
|
||||
self.free_func = 'g_strfreev'
|
||||
self.format_in = '^as'
|
||||
self.format_out = '^as'
|
||||
self.gvariant_get = 'g_variant_get_strv'
|
||||
self.gvalue_get = 'g_value_get_boxed'
|
||||
self.array_annotation = '(array zero-terminated=1)'
|
||||
elif self.signature == 'ao':
|
||||
self.ctype_in_g = 'const gchar *const *'
|
||||
self.ctype_in = 'const gchar *const *'
|
||||
self.ctype_in_dup = 'gchar **'
|
||||
self.ctype_out = 'gchar ***'
|
||||
self.gtype = 'G_TYPE_STRV'
|
||||
self.free_func = 'g_strfreev'
|
||||
self.format_in = '^ao'
|
||||
self.format_out = '^ao'
|
||||
self.gvariant_get = 'g_variant_get_objv'
|
||||
self.gvalue_get = 'g_value_get_boxed'
|
||||
self.array_annotation = '(array zero-terminated=1)'
|
||||
elif self.signature == 'aay':
|
||||
self.ctype_in_g = 'const gchar *const *'
|
||||
self.ctype_in = 'const gchar *const *'
|
||||
self.ctype_in_dup = 'gchar **'
|
||||
self.ctype_out = 'gchar ***'
|
||||
self.gtype = 'G_TYPE_STRV'
|
||||
self.free_func = 'g_strfreev'
|
||||
self.format_in = '^aay'
|
||||
self.format_out = '^aay'
|
||||
self.gvariant_get = 'g_variant_get_bytestring_array'
|
||||
self.gvalue_get = 'g_value_get_boxed'
|
||||
self.array_annotation = '(array zero-terminated=1)'
|
||||
self.format_in = "d"
|
||||
self.format_out = "d"
|
||||
self.gvariant_get = "g_variant_get_double"
|
||||
self.gvalue_get = "g_value_get_double"
|
||||
elif self.signature == "s":
|
||||
self.ctype_in_g = "const gchar *"
|
||||
self.ctype_in = "const gchar *"
|
||||
self.ctype_in_dup = "gchar *"
|
||||
self.ctype_out = "gchar **"
|
||||
self.gtype = "G_TYPE_STRING"
|
||||
self.free_func = "g_free"
|
||||
self.format_in = "s"
|
||||
self.format_out = "s"
|
||||
self.gvariant_get = "g_variant_get_string"
|
||||
self.gvalue_get = "g_value_get_string"
|
||||
elif self.signature == "o":
|
||||
self.ctype_in_g = "const gchar *"
|
||||
self.ctype_in = "const gchar *"
|
||||
self.ctype_in_dup = "gchar *"
|
||||
self.ctype_out = "gchar **"
|
||||
self.gtype = "G_TYPE_STRING"
|
||||
self.free_func = "g_free"
|
||||
self.format_in = "o"
|
||||
self.format_out = "o"
|
||||
self.gvariant_get = "g_variant_get_string"
|
||||
self.gvalue_get = "g_value_get_string"
|
||||
elif self.signature == "g":
|
||||
self.ctype_in_g = "const gchar *"
|
||||
self.ctype_in = "const gchar *"
|
||||
self.ctype_in_dup = "gchar *"
|
||||
self.ctype_out = "gchar **"
|
||||
self.gtype = "G_TYPE_STRING"
|
||||
self.free_func = "g_free"
|
||||
self.format_in = "g"
|
||||
self.format_out = "g"
|
||||
self.gvariant_get = "g_variant_get_string"
|
||||
self.gvalue_get = "g_value_get_string"
|
||||
elif self.signature == "ay":
|
||||
self.ctype_in_g = "const gchar *"
|
||||
self.ctype_in = "const gchar *"
|
||||
self.ctype_in_dup = "gchar *"
|
||||
self.ctype_out = "gchar **"
|
||||
self.gtype = "G_TYPE_STRING"
|
||||
self.free_func = "g_free"
|
||||
self.format_in = "^ay"
|
||||
self.format_out = "^ay"
|
||||
self.gvariant_get = "g_variant_get_bytestring"
|
||||
self.gvalue_get = "g_value_get_string"
|
||||
elif self.signature == "as":
|
||||
self.ctype_in_g = "const gchar *const *"
|
||||
self.ctype_in = "const gchar *const *"
|
||||
self.ctype_in_dup = "gchar **"
|
||||
self.ctype_out = "gchar ***"
|
||||
self.gtype = "G_TYPE_STRV"
|
||||
self.free_func = "g_strfreev"
|
||||
self.format_in = "^as"
|
||||
self.format_out = "^as"
|
||||
self.gvariant_get = "g_variant_get_strv"
|
||||
self.gvalue_get = "g_value_get_boxed"
|
||||
self.array_annotation = "(array zero-terminated=1)"
|
||||
elif self.signature == "ao":
|
||||
self.ctype_in_g = "const gchar *const *"
|
||||
self.ctype_in = "const gchar *const *"
|
||||
self.ctype_in_dup = "gchar **"
|
||||
self.ctype_out = "gchar ***"
|
||||
self.gtype = "G_TYPE_STRV"
|
||||
self.free_func = "g_strfreev"
|
||||
self.format_in = "^ao"
|
||||
self.format_out = "^ao"
|
||||
self.gvariant_get = "g_variant_get_objv"
|
||||
self.gvalue_get = "g_value_get_boxed"
|
||||
self.array_annotation = "(array zero-terminated=1)"
|
||||
elif self.signature == "aay":
|
||||
self.ctype_in_g = "const gchar *const *"
|
||||
self.ctype_in = "const gchar *const *"
|
||||
self.ctype_in_dup = "gchar **"
|
||||
self.ctype_out = "gchar ***"
|
||||
self.gtype = "G_TYPE_STRV"
|
||||
self.free_func = "g_strfreev"
|
||||
self.format_in = "^aay"
|
||||
self.format_out = "^aay"
|
||||
self.gvariant_get = "g_variant_get_bytestring_array"
|
||||
self.gvalue_get = "g_value_get_boxed"
|
||||
self.array_annotation = "(array zero-terminated=1)"
|
||||
|
||||
for a in self.annotations:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
|
||||
class Method:
|
||||
def __init__(self, name, h_type_implies_unix_fd=True):
|
||||
self.name = name
|
||||
@@ -258,12 +270,14 @@ class Method:
|
||||
self.in_args = []
|
||||
self.out_args = []
|
||||
self.annotations = []
|
||||
self.doc_string = ''
|
||||
self.since = ''
|
||||
self.doc_string = ""
|
||||
self.since = ""
|
||||
self.deprecated = False
|
||||
self.unix_fd = False
|
||||
|
||||
def post_process(self, interface_prefix, cns, cns_upper, cns_lower, containing_iface):
|
||||
def post_process(
|
||||
self, interface_prefix, cns, cns_upper, cns_lower, containing_iface
|
||||
):
|
||||
if len(self.doc_string) == 0:
|
||||
self.doc_string = utils.lookup_docs(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
@@ -272,47 +286,55 @@ class Method:
|
||||
self.since = containing_iface.since
|
||||
|
||||
name = self.name
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
overridden_name = utils.lookup_annotation(
|
||||
self.annotations, "org.gtk.GDBus.C.Name"
|
||||
)
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
self.name_lower = overridden_name.lower()
|
||||
else:
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
self.name_hyphen = self.name_lower.replace('_', '-')
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace("-", "_")
|
||||
self.name_hyphen = self.name_lower.replace("_", "-")
|
||||
|
||||
arg_count = 0
|
||||
for a in self.in_args:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
|
||||
arg_count += 1
|
||||
if self.h_type_implies_unix_fd and 'h' in a.signature:
|
||||
if self.h_type_implies_unix_fd and "h" in a.signature:
|
||||
self.unix_fd = True
|
||||
|
||||
for a in self.out_args:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
|
||||
arg_count += 1
|
||||
if self.h_type_implies_unix_fd and 'h' in a.signature:
|
||||
if self.h_type_implies_unix_fd and "h" in a.signature:
|
||||
self.unix_fd = True
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
|
||||
if (
|
||||
utils.lookup_annotation(self.annotations, "org.freedesktop.DBus.Deprecated")
|
||||
== "true"
|
||||
):
|
||||
self.deprecated = True
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.UnixFD'):
|
||||
if utils.lookup_annotation(self.annotations, "org.gtk.GDBus.C.UnixFD"):
|
||||
self.unix_fd = True
|
||||
|
||||
for a in self.annotations:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
|
||||
class Signal:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.args = []
|
||||
self.annotations = []
|
||||
self.doc_string = ''
|
||||
self.since = ''
|
||||
self.doc_string = ""
|
||||
self.since = ""
|
||||
self.deprecated = False
|
||||
|
||||
def post_process(self, interface_prefix, cns, cns_upper, cns_lower, containing_iface):
|
||||
def post_process(
|
||||
self, interface_prefix, cns, cns_upper, cns_lower, containing_iface
|
||||
):
|
||||
if len(self.doc_string) == 0:
|
||||
self.doc_string = utils.lookup_docs(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
@@ -321,51 +343,59 @@ class Signal:
|
||||
self.since = containing_iface.since
|
||||
|
||||
name = self.name
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
overridden_name = utils.lookup_annotation(
|
||||
self.annotations, "org.gtk.GDBus.C.Name"
|
||||
)
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
self.name_lower = overridden_name.lower()
|
||||
else:
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
self.name_hyphen = self.name_lower.replace('_', '-')
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace("-", "_")
|
||||
self.name_hyphen = self.name_lower.replace("_", "-")
|
||||
|
||||
arg_count = 0
|
||||
for a in self.args:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
|
||||
arg_count += 1
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
|
||||
if (
|
||||
utils.lookup_annotation(self.annotations, "org.freedesktop.DBus.Deprecated")
|
||||
== "true"
|
||||
):
|
||||
self.deprecated = True
|
||||
|
||||
for a in self.annotations:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
|
||||
class Property:
|
||||
def __init__(self, name, signature, access):
|
||||
self.name = name
|
||||
self.signature = signature
|
||||
self.access = access
|
||||
self.annotations = []
|
||||
self.arg = Arg('value', self.signature)
|
||||
self.arg = Arg("value", self.signature)
|
||||
self.arg.annotations = self.annotations
|
||||
self.readable = False
|
||||
self.writable = False
|
||||
if self.access == 'readwrite':
|
||||
if self.access == "readwrite":
|
||||
self.readable = True
|
||||
self.writable = True
|
||||
elif self.access == 'read':
|
||||
elif self.access == "read":
|
||||
self.readable = True
|
||||
elif self.access == 'write':
|
||||
elif self.access == "write":
|
||||
self.writable = True
|
||||
else:
|
||||
print_error('Invalid access type "{}"'.format(self.access))
|
||||
self.doc_string = ''
|
||||
self.since = ''
|
||||
self.doc_string = ""
|
||||
self.since = ""
|
||||
self.deprecated = False
|
||||
self.emits_changed_signal = True
|
||||
|
||||
def post_process(self, interface_prefix, cns, cns_upper, cns_lower, containing_iface):
|
||||
def post_process(
|
||||
self, interface_prefix, cns, cns_upper, cns_lower, containing_iface
|
||||
):
|
||||
if len(self.doc_string) == 0:
|
||||
self.doc_string = utils.lookup_docs(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
@@ -374,23 +404,28 @@ class Property:
|
||||
self.since = containing_iface.since
|
||||
|
||||
name = self.name
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
overridden_name = utils.lookup_annotation(
|
||||
self.annotations, "org.gtk.GDBus.C.Name"
|
||||
)
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
self.name_lower = overridden_name.lower()
|
||||
else:
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace('-', '_')
|
||||
self.name_hyphen = self.name_lower.replace('_', '-')
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace("-", "_")
|
||||
self.name_hyphen = self.name_lower.replace("_", "-")
|
||||
# don't clash with the GType getter, e.g.: GType foo_bar_get_type (void); G_GNUC_CONST
|
||||
if self.name_lower == 'type':
|
||||
self.name_lower = 'type_'
|
||||
if self.name_lower == "type":
|
||||
self.name_lower = "type_"
|
||||
|
||||
# recalculate arg
|
||||
self.arg.annotations = self.annotations
|
||||
self.arg.post_process(interface_prefix, cns, cns_upper, cns_lower, 0)
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
|
||||
if (
|
||||
utils.lookup_annotation(self.annotations, "org.freedesktop.DBus.Deprecated")
|
||||
== "true"
|
||||
):
|
||||
self.deprecated = True
|
||||
|
||||
for a in self.annotations:
|
||||
@@ -399,9 +434,12 @@ class Property:
|
||||
# FIXME: for now we only support 'false' and 'const' on the signal itself, see #674913 and
|
||||
# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
|
||||
# for details
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Property.EmitsChangedSignal') in ('false', 'const'):
|
||||
if utils.lookup_annotation(
|
||||
self.annotations, "org.freedesktop.DBus.Property.EmitsChangedSignal"
|
||||
) in ("false", "const"):
|
||||
self.emits_changed_signal = False
|
||||
|
||||
|
||||
class Interface:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
@@ -409,9 +447,9 @@ class Interface:
|
||||
self.signals = []
|
||||
self.properties = []
|
||||
self.annotations = []
|
||||
self.doc_string = ''
|
||||
self.doc_string_brief = ''
|
||||
self.since = ''
|
||||
self.doc_string = ""
|
||||
self.doc_string_brief = ""
|
||||
self.since = ""
|
||||
self.deprecated = False
|
||||
|
||||
def post_process(self, interface_prefix, c_namespace):
|
||||
@@ -424,21 +462,23 @@ class Interface:
|
||||
|
||||
if len(c_namespace) > 0:
|
||||
if utils.is_ugly_case(c_namespace):
|
||||
cns = c_namespace.replace('_', '')
|
||||
cns_upper = c_namespace.upper() + '_'
|
||||
cns_lower = c_namespace.lower() + '_'
|
||||
cns = c_namespace.replace("_", "")
|
||||
cns_upper = c_namespace.upper() + "_"
|
||||
cns_lower = c_namespace.lower() + "_"
|
||||
else:
|
||||
cns = c_namespace
|
||||
cns_upper = utils.camel_case_to_uscore(c_namespace).upper() + '_'
|
||||
cns_lower = utils.camel_case_to_uscore(c_namespace).lower() + '_'
|
||||
cns_upper = utils.camel_case_to_uscore(c_namespace).upper() + "_"
|
||||
cns_lower = utils.camel_case_to_uscore(c_namespace).lower() + "_"
|
||||
else:
|
||||
cns = ''
|
||||
cns_upper = ''
|
||||
cns_lower = ''
|
||||
cns = ""
|
||||
cns_upper = ""
|
||||
cns_lower = ""
|
||||
|
||||
overridden_name = utils.lookup_annotation(self.annotations, 'org.gtk.GDBus.C.Name')
|
||||
overridden_name = utils.lookup_annotation(
|
||||
self.annotations, "org.gtk.GDBus.C.Name"
|
||||
)
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
name = overridden_name.replace('_', '')
|
||||
name = overridden_name.replace("_", "")
|
||||
name_with_ns = cns + name
|
||||
self.name_without_prefix = name
|
||||
self.camel_name = name_with_ns
|
||||
@@ -446,25 +486,28 @@ class Interface:
|
||||
self.name_lower = cns_lower + overridden_name.lower()
|
||||
self.name_upper = overridden_name.upper()
|
||||
|
||||
#print_error('handle Ugly_Case "{}"'.format(overridden_name))
|
||||
# print_error('handle Ugly_Case "{}"'.format(overridden_name))
|
||||
else:
|
||||
if overridden_name:
|
||||
name = overridden_name
|
||||
else:
|
||||
name = self.name
|
||||
if name.startswith(interface_prefix):
|
||||
name = name[len(interface_prefix):]
|
||||
name = name[len(interface_prefix) :]
|
||||
self.name_without_prefix = name
|
||||
name = utils.strip_dots(name)
|
||||
name_with_ns = utils.strip_dots(cns + '.' + name)
|
||||
name_with_ns = utils.strip_dots(cns + "." + name)
|
||||
self.camel_name = name_with_ns
|
||||
self.ns_upper = cns_upper
|
||||
self.name_lower = cns_lower + utils.camel_case_to_uscore(name)
|
||||
self.name_upper = utils.camel_case_to_uscore(name).upper()
|
||||
|
||||
self.name_hyphen = self.name_upper.lower().replace('_', '-')
|
||||
self.name_hyphen = self.name_upper.lower().replace("_", "-")
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
|
||||
if (
|
||||
utils.lookup_annotation(self.annotations, "org.freedesktop.DBus.Deprecated")
|
||||
== "true"
|
||||
):
|
||||
self.deprecated = True
|
||||
|
||||
for m in self.methods:
|
||||
|
@@ -25,16 +25,17 @@ import xml.parsers.expat
|
||||
from . import dbustypes
|
||||
from .utils import print_error
|
||||
|
||||
|
||||
class DBusXMLParser:
|
||||
STATE_TOP = 'top'
|
||||
STATE_NODE = 'node'
|
||||
STATE_INTERFACE = 'interface'
|
||||
STATE_METHOD = 'method'
|
||||
STATE_SIGNAL = 'signal'
|
||||
STATE_PROPERTY = 'property'
|
||||
STATE_ARG = 'arg'
|
||||
STATE_ANNOTATION = 'annotation'
|
||||
STATE_IGNORED = 'ignored'
|
||||
STATE_TOP = "top"
|
||||
STATE_NODE = "node"
|
||||
STATE_INTERFACE = "interface"
|
||||
STATE_METHOD = "method"
|
||||
STATE_SIGNAL = "signal"
|
||||
STATE_PROPERTY = "property"
|
||||
STATE_ARG = "arg"
|
||||
STATE_ANNOTATION = "annotation"
|
||||
STATE_IGNORED = "ignored"
|
||||
|
||||
def __init__(self, xml_data, h_type_implies_unix_fd=True):
|
||||
self._parser = xml.parsers.expat.ParserCreate()
|
||||
@@ -51,21 +52,22 @@ class DBusXMLParser:
|
||||
self._cur_object = None
|
||||
self._cur_object_stack = []
|
||||
|
||||
self.doc_comment_last_symbol = ''
|
||||
self.doc_comment_last_symbol = ""
|
||||
|
||||
self._h_type_implies_unix_fd = h_type_implies_unix_fd
|
||||
|
||||
self._parser.Parse(xml_data)
|
||||
|
||||
COMMENT_STATE_BEGIN = 'begin'
|
||||
COMMENT_STATE_PARAMS = 'params'
|
||||
COMMENT_STATE_BODY = 'body'
|
||||
COMMENT_STATE_SKIP = 'skip'
|
||||
COMMENT_STATE_BEGIN = "begin"
|
||||
COMMENT_STATE_PARAMS = "params"
|
||||
COMMENT_STATE_BODY = "body"
|
||||
COMMENT_STATE_SKIP = "skip"
|
||||
|
||||
def handle_comment(self, data):
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BEGIN;
|
||||
lines = data.split('\n')
|
||||
symbol = ''
|
||||
body = ''
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BEGIN
|
||||
lines = data.split("\n")
|
||||
symbol = ""
|
||||
body = ""
|
||||
in_para = False
|
||||
params = {}
|
||||
for line in lines:
|
||||
@@ -73,59 +75,59 @@ class DBusXMLParser:
|
||||
line = line.lstrip()
|
||||
if comment_state == DBusXMLParser.COMMENT_STATE_BEGIN:
|
||||
if len(line) > 0:
|
||||
colon_index = line.find(': ')
|
||||
colon_index = line.find(": ")
|
||||
if colon_index == -1:
|
||||
if line.endswith(':'):
|
||||
symbol = line[0:len(line)-1]
|
||||
if line.endswith(":"):
|
||||
symbol = line[0 : len(line) - 1]
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_PARAMS
|
||||
else:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_SKIP
|
||||
else:
|
||||
symbol = line[0:colon_index]
|
||||
rest_of_line = line[colon_index+2:].strip()
|
||||
rest_of_line = line[colon_index + 2 :].strip()
|
||||
if len(rest_of_line) > 0:
|
||||
body += '<para>' + rest_of_line + '</para>'
|
||||
body += "<para>" + rest_of_line + "</para>"
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_PARAMS
|
||||
elif comment_state == DBusXMLParser.COMMENT_STATE_PARAMS:
|
||||
if line.startswith('@'):
|
||||
colon_index = line.find(': ')
|
||||
if line.startswith("@"):
|
||||
colon_index = line.find(": ")
|
||||
if colon_index == -1:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BODY
|
||||
if not in_para:
|
||||
body += '<para>'
|
||||
body += "<para>"
|
||||
in_para = True
|
||||
body += orig_line + '\n'
|
||||
body += orig_line + "\n"
|
||||
else:
|
||||
param = line[1:colon_index]
|
||||
docs = line[colon_index + 2:]
|
||||
docs = line[colon_index + 2 :]
|
||||
params[param] = docs
|
||||
else:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BODY
|
||||
if len(line) > 0:
|
||||
if not in_para:
|
||||
body += '<para>'
|
||||
body += "<para>"
|
||||
in_para = True
|
||||
body += orig_line + '\n'
|
||||
body += orig_line + "\n"
|
||||
elif comment_state == DBusXMLParser.COMMENT_STATE_BODY:
|
||||
if len(line) > 0:
|
||||
if not in_para:
|
||||
body += '<para>'
|
||||
body += "<para>"
|
||||
in_para = True
|
||||
body += orig_line + '\n'
|
||||
body += orig_line + "\n"
|
||||
else:
|
||||
if in_para:
|
||||
body += '</para>'
|
||||
body += "</para>"
|
||||
in_para = False
|
||||
if in_para:
|
||||
body += '</para>'
|
||||
body += "</para>"
|
||||
|
||||
if symbol != '':
|
||||
if symbol != "":
|
||||
self.doc_comment_last_symbol = symbol
|
||||
self.doc_comment_params = params
|
||||
self.doc_comment_body = body
|
||||
|
||||
def handle_char_data(self, data):
|
||||
#print 'char_data=%s'%data
|
||||
# print 'char_data=%s'%data
|
||||
pass
|
||||
|
||||
def handle_start_element(self, name, attrs):
|
||||
@@ -141,77 +143,76 @@ class DBusXMLParser:
|
||||
elif self.state == DBusXMLParser.STATE_NODE:
|
||||
if name == DBusXMLParser.STATE_INTERFACE:
|
||||
self.state = DBusXMLParser.STATE_INTERFACE
|
||||
iface = dbustypes.Interface(attrs['name'])
|
||||
iface = dbustypes.Interface(attrs["name"])
|
||||
self._cur_object = iface
|
||||
self.parsed_interfaces.append(iface)
|
||||
elif name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs['name'], attrs['value'])
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
|
||||
# assign docs, if any
|
||||
if 'name' in attrs and self.doc_comment_last_symbol == attrs['name']:
|
||||
if "name" in attrs and self.doc_comment_last_symbol == attrs["name"]:
|
||||
self._cur_object.doc_string = self.doc_comment_body
|
||||
if 'short_description' in self.doc_comment_params:
|
||||
short_description = self.doc_comment_params['short_description']
|
||||
if "short_description" in self.doc_comment_params:
|
||||
short_description = self.doc_comment_params["short_description"]
|
||||
self._cur_object.doc_string_brief = short_description
|
||||
if 'since' in self.doc_comment_params:
|
||||
self._cur_object.since = \
|
||||
self.doc_comment_params['since'].strip()
|
||||
if "since" in self.doc_comment_params:
|
||||
self._cur_object.since = self.doc_comment_params["since"].strip()
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_INTERFACE:
|
||||
if name == DBusXMLParser.STATE_METHOD:
|
||||
self.state = DBusXMLParser.STATE_METHOD
|
||||
method = dbustypes.Method(attrs['name'],
|
||||
h_type_implies_unix_fd=self._h_type_implies_unix_fd)
|
||||
method = dbustypes.Method(
|
||||
attrs["name"], h_type_implies_unix_fd=self._h_type_implies_unix_fd
|
||||
)
|
||||
self._cur_object.methods.append(method)
|
||||
self._cur_object = method
|
||||
elif name == DBusXMLParser.STATE_SIGNAL:
|
||||
self.state = DBusXMLParser.STATE_SIGNAL
|
||||
signal = dbustypes.Signal(attrs['name'])
|
||||
signal = dbustypes.Signal(attrs["name"])
|
||||
self._cur_object.signals.append(signal)
|
||||
self._cur_object = signal
|
||||
elif name == DBusXMLParser.STATE_PROPERTY:
|
||||
self.state = DBusXMLParser.STATE_PROPERTY
|
||||
prop = dbustypes.Property(attrs['name'], attrs['type'], attrs['access'])
|
||||
prop = dbustypes.Property(attrs["name"], attrs["type"], attrs["access"])
|
||||
self._cur_object.properties.append(prop)
|
||||
self._cur_object = prop
|
||||
elif name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs['name'], attrs['value'])
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
|
||||
# assign docs, if any
|
||||
if 'name' in attrs and self.doc_comment_last_symbol == attrs['name']:
|
||||
if "name" in attrs and self.doc_comment_last_symbol == attrs["name"]:
|
||||
self._cur_object.doc_string = self.doc_comment_body
|
||||
if 'since' in self.doc_comment_params:
|
||||
self._cur_object.since = \
|
||||
self.doc_comment_params['since'].strip()
|
||||
if "since" in self.doc_comment_params:
|
||||
self._cur_object.since = self.doc_comment_params["since"].strip()
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_METHOD:
|
||||
if name == DBusXMLParser.STATE_ARG:
|
||||
self.state = DBusXMLParser.STATE_ARG
|
||||
arg_name = None
|
||||
if 'name' in attrs:
|
||||
arg_name = attrs['name']
|
||||
arg = dbustypes.Arg(arg_name, attrs['type'])
|
||||
direction = attrs.get('direction', 'in')
|
||||
if direction == 'in':
|
||||
if "name" in attrs:
|
||||
arg_name = attrs["name"]
|
||||
arg = dbustypes.Arg(arg_name, attrs["type"])
|
||||
direction = attrs.get("direction", "in")
|
||||
if direction == "in":
|
||||
self._cur_object.in_args.append(arg)
|
||||
elif direction == 'out':
|
||||
elif direction == "out":
|
||||
self._cur_object.out_args.append(arg)
|
||||
else:
|
||||
print_error('Invalid direction "{}"'.format(direction))
|
||||
self._cur_object = arg
|
||||
elif name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs['name'], attrs['value'])
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
@@ -219,26 +220,27 @@ class DBusXMLParser:
|
||||
|
||||
# assign docs, if any
|
||||
if self.doc_comment_last_symbol == old_cur_object.name:
|
||||
if 'name' in attrs and attrs['name'] in self.doc_comment_params:
|
||||
doc_string = self.doc_comment_params[attrs['name']]
|
||||
if "name" in attrs and attrs["name"] in self.doc_comment_params:
|
||||
doc_string = self.doc_comment_params[attrs["name"]]
|
||||
if doc_string != None:
|
||||
self._cur_object.doc_string = doc_string
|
||||
if 'since' in self.doc_comment_params:
|
||||
self._cur_object.since = \
|
||||
self.doc_comment_params['since'].strip()
|
||||
if "since" in self.doc_comment_params:
|
||||
self._cur_object.since = self.doc_comment_params[
|
||||
"since"
|
||||
].strip()
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_SIGNAL:
|
||||
if name == DBusXMLParser.STATE_ARG:
|
||||
self.state = DBusXMLParser.STATE_ARG
|
||||
arg_name = None
|
||||
if 'name' in attrs:
|
||||
arg_name = attrs['name']
|
||||
arg = dbustypes.Arg(arg_name, attrs['type'])
|
||||
if "name" in attrs:
|
||||
arg_name = attrs["name"]
|
||||
arg = dbustypes.Arg(arg_name, attrs["type"])
|
||||
self._cur_object.args.append(arg)
|
||||
self._cur_object = arg
|
||||
elif name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs['name'], attrs['value'])
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
@@ -246,18 +248,19 @@ class DBusXMLParser:
|
||||
|
||||
# assign docs, if any
|
||||
if self.doc_comment_last_symbol == old_cur_object.name:
|
||||
if 'name' in attrs and attrs['name'] in self.doc_comment_params:
|
||||
doc_string = self.doc_comment_params[attrs['name']]
|
||||
if "name" in attrs and attrs["name"] in self.doc_comment_params:
|
||||
doc_string = self.doc_comment_params[attrs["name"]]
|
||||
if doc_string != None:
|
||||
self._cur_object.doc_string = doc_string
|
||||
if 'since' in self.doc_comment_params:
|
||||
self._cur_object.since = \
|
||||
self.doc_comment_params['since'].strip()
|
||||
if "since" in self.doc_comment_params:
|
||||
self._cur_object.since = self.doc_comment_params[
|
||||
"since"
|
||||
].strip()
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_PROPERTY:
|
||||
if name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs['name'], attrs['value'])
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
@@ -266,7 +269,7 @@ class DBusXMLParser:
|
||||
elif self.state == DBusXMLParser.STATE_ARG:
|
||||
if name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs['name'], attrs['value'])
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
@@ -275,14 +278,18 @@ class DBusXMLParser:
|
||||
elif self.state == DBusXMLParser.STATE_ANNOTATION:
|
||||
if name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs['name'], attrs['value'])
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
|
||||
else:
|
||||
print_error('Unhandled state "{}" while entering element with name "{}"'.format(self.state, name))
|
||||
print_error(
|
||||
'Unhandled state "{}" while entering element with name "{}"'.format(
|
||||
self.state, name
|
||||
)
|
||||
)
|
||||
|
||||
self.state_stack.append(old_state)
|
||||
self._cur_object_stack.append(old_cur_object)
|
||||
@@ -291,6 +298,7 @@ class DBusXMLParser:
|
||||
self.state = self.state_stack.pop()
|
||||
self._cur_object = self._cur_object_stack.pop()
|
||||
|
||||
|
||||
def parse_dbus_xml(xml_data, h_type_implies_unix_fd):
|
||||
parser = DBusXMLParser(xml_data, h_type_implies_unix_fd)
|
||||
return parser.parsed_interfaces
|
||||
|
@@ -25,47 +25,55 @@ import sys
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class Color:
|
||||
'''ANSI Terminal colors'''
|
||||
GREEN = '\033[1;32m'
|
||||
BLUE = '\033[1;34m'
|
||||
YELLOW = '\033[1;33m'
|
||||
RED = '\033[1;31m'
|
||||
END = '\033[0m'
|
||||
"""ANSI Terminal colors"""
|
||||
|
||||
def print_color(msg, color=Color.END, prefix='MESSAGE'):
|
||||
'''Print a string with a color prefix'''
|
||||
GREEN = "\033[1;32m"
|
||||
BLUE = "\033[1;34m"
|
||||
YELLOW = "\033[1;33m"
|
||||
RED = "\033[1;31m"
|
||||
END = "\033[0m"
|
||||
|
||||
|
||||
def print_color(msg, color=Color.END, prefix="MESSAGE"):
|
||||
"""Print a string with a color prefix"""
|
||||
if os.isatty(sys.stderr.fileno()):
|
||||
real_prefix = '{start}{prefix}{end}'.format(start=color, prefix=prefix, end=Color.END)
|
||||
real_prefix = "{start}{prefix}{end}".format(
|
||||
start=color, prefix=prefix, end=Color.END
|
||||
)
|
||||
else:
|
||||
real_prefix = prefix
|
||||
sys.stderr.write('{prefix}: {msg}\n'.format(prefix=real_prefix, msg=msg))
|
||||
sys.stderr.write("{prefix}: {msg}\n".format(prefix=real_prefix, msg=msg))
|
||||
|
||||
|
||||
def print_error(msg):
|
||||
'''Print an error, and terminate'''
|
||||
print_color(msg, color=Color.RED, prefix='ERROR')
|
||||
"""Print an error, and terminate"""
|
||||
print_color(msg, color=Color.RED, prefix="ERROR")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def print_warning(msg, fatal=False):
|
||||
'''Print a warning, and optionally terminate'''
|
||||
"""Print a warning, and optionally terminate"""
|
||||
if fatal:
|
||||
color = Color.RED
|
||||
prefix = 'ERROR'
|
||||
prefix = "ERROR"
|
||||
else:
|
||||
color = Color.YELLOW
|
||||
prefix = 'WARNING'
|
||||
prefix = "WARNING"
|
||||
print_color(msg, color, prefix)
|
||||
if fatal:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def print_info(msg):
|
||||
'''Print a message'''
|
||||
print_color(msg, color=Color.GREEN, prefix='INFO')
|
||||
"""Print a message"""
|
||||
print_color(msg, color=Color.GREEN, prefix="INFO")
|
||||
|
||||
|
||||
def strip_dots(s):
|
||||
ret = ''
|
||||
ret = ""
|
||||
force_upper = False
|
||||
for c in s:
|
||||
if c == '.':
|
||||
if c == ".":
|
||||
force_upper = True
|
||||
else:
|
||||
if force_upper:
|
||||
@@ -75,19 +83,21 @@ def strip_dots(s):
|
||||
ret += c
|
||||
return ret
|
||||
|
||||
|
||||
def dots_to_hyphens(s):
|
||||
return s.replace('.', '-')
|
||||
return s.replace(".", "-")
|
||||
|
||||
|
||||
def camel_case_to_uscore(s):
|
||||
ret = ''
|
||||
ret = ""
|
||||
insert_uscore = False
|
||||
prev_was_lower = False
|
||||
initial = True;
|
||||
initial = True
|
||||
for c in s:
|
||||
# Keep initial underscores in camel case
|
||||
if initial and c == '_':
|
||||
ret += '_'
|
||||
continue;
|
||||
if initial and c == "_":
|
||||
ret += "_"
|
||||
continue
|
||||
initial = False
|
||||
|
||||
if c.isupper():
|
||||
@@ -97,16 +107,18 @@ def camel_case_to_uscore(s):
|
||||
else:
|
||||
prev_was_lower = True
|
||||
if insert_uscore:
|
||||
ret += '_'
|
||||
ret += "_"
|
||||
ret += c.lower()
|
||||
insert_uscore = False
|
||||
return ret
|
||||
|
||||
|
||||
def is_ugly_case(s):
|
||||
if s and s.find('_') > 0:
|
||||
if s and s.find("_") > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def lookup_annotation(annotations, key):
|
||||
if annotations:
|
||||
for a in annotations:
|
||||
@@ -114,35 +126,39 @@ def lookup_annotation(annotations, key):
|
||||
return a.value
|
||||
return None
|
||||
|
||||
|
||||
def lookup_docs(annotations):
|
||||
s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString')
|
||||
s = lookup_annotation(annotations, "org.gtk.GDBus.DocString")
|
||||
if s is None:
|
||||
return ''
|
||||
return ""
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def lookup_since(annotations):
|
||||
s = lookup_annotation(annotations, 'org.gtk.GDBus.Since')
|
||||
s = lookup_annotation(annotations, "org.gtk.GDBus.Since")
|
||||
if s is None:
|
||||
return ''
|
||||
return ""
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def lookup_brief_docs(annotations):
|
||||
s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString.Short')
|
||||
s = lookup_annotation(annotations, "org.gtk.GDBus.DocString.Short")
|
||||
if s is None:
|
||||
return ''
|
||||
return ""
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def version_cmp_key(key):
|
||||
# If the 'since' version is 'UNRELEASED', compare higher than anything else
|
||||
# If it is empty put a 0 in its place as this will
|
||||
# allow LooseVersion to work and will always compare lower.
|
||||
if key[0] == 'UNRELEASED':
|
||||
v = '9999'
|
||||
if key[0] == "UNRELEASED":
|
||||
v = "9999"
|
||||
elif key[0]:
|
||||
v = str(key[0])
|
||||
else:
|
||||
v = '0'
|
||||
v = "0"
|
||||
return (distutils.version.LooseVersion(v), key[1])
|
||||
|
Reference in New Issue
Block a user