Import Upstream version 2.72.4
This commit is contained in:
commit
4ef3ff9793
2003 changed files with 1332420 additions and 0 deletions
4
gio/gdbus-2.0/codegen/.flake8
Normal file
4
gio/gdbus-2.0/codegen/.flake8
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[flake8]
|
||||
# We are generating long lines through templates
|
||||
max-line-length = 120
|
||||
exclude = __pycache__
|
||||
3
gio/gdbus-2.0/codegen/.gitignore
vendored
Normal file
3
gio/gdbus-2.0/codegen/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
*.pyc
|
||||
config.py
|
||||
gdbus-codegen
|
||||
29
gio/gdbus-2.0/codegen/__init__.py
Normal file
29
gio/gdbus-2.0/codegen/__init__.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# -*- Mode: Python -*-
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import os
|
||||
|
||||
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"))
|
||||
)
|
||||
5234
gio/gdbus-2.0/codegen/codegen.py
Normal file
5234
gio/gdbus-2.0/codegen/codegen.py
Normal file
File diff suppressed because it is too large
Load diff
480
gio/gdbus-2.0/codegen/codegen_docbook.py
Normal file
480
gio/gdbus-2.0/codegen/codegen_docbook.py
Normal file
|
|
@ -0,0 +1,480 @@
|
|||
# -*- Mode: Python -*-
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import re
|
||||
from os import path
|
||||
|
||||
from . import utils
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class DocbookCodeGenerator:
|
||||
def __init__(self, ifaces):
|
||||
self.ifaces = ifaces
|
||||
self.generate_expand_dicts()
|
||||
|
||||
def print_method_prototype(self, i, m, in_synopsis):
|
||||
max_method_len = 0
|
||||
if in_synopsis:
|
||||
for _m in i.methods:
|
||||
max_method_len = max(len(_m.name), max_method_len)
|
||||
else:
|
||||
max_method_len = max(len(m.name), max_method_len)
|
||||
|
||||
max_signature_len = 0
|
||||
if in_synopsis:
|
||||
for _m in i.methods:
|
||||
for a in _m.in_args:
|
||||
max_signature_len = max(len(a.signature), max_signature_len)
|
||||
for a in _m.out_args:
|
||||
max_signature_len = max(len(a.signature), max_signature_len)
|
||||
else:
|
||||
for a in m.in_args:
|
||||
max_signature_len = max(len(a.signature), max_signature_len)
|
||||
for a in m.out_args:
|
||||
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),
|
||||
"",
|
||||
)
|
||||
)
|
||||
else:
|
||||
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)
|
||||
)
|
||||
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)
|
||||
)
|
||||
count = count + 1
|
||||
self.out.write(");\n")
|
||||
|
||||
def print_signal_prototype(self, i, s, in_synopsis):
|
||||
max_signal_len = 0
|
||||
if in_synopsis:
|
||||
for _s in i.signals:
|
||||
max_signal_len = max(len(_s.name), max_signal_len)
|
||||
else:
|
||||
max_signal_len = max(len(s.name), max_signal_len)
|
||||
|
||||
max_signature_len = 0
|
||||
if in_synopsis:
|
||||
for _s in i.signals:
|
||||
for a in _s.args:
|
||||
max_signature_len = max(len(a.signature), max_signature_len)
|
||||
else:
|
||||
for a in s.args:
|
||||
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),
|
||||
"",
|
||||
)
|
||||
)
|
||||
else:
|
||||
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)
|
||||
)
|
||||
count = count + 1
|
||||
self.out.write(");\n")
|
||||
|
||||
def print_property_prototype(self, i, p, in_synopsis):
|
||||
max_property_len = 0
|
||||
if in_synopsis:
|
||||
for _p in i.properties:
|
||||
max_property_len = max(len(_p.name), max_property_len)
|
||||
else:
|
||||
max_property_len = max(len(p.name), max_property_len)
|
||||
|
||||
max_signature_len = 0
|
||||
if in_synopsis:
|
||||
for _p in i.properties:
|
||||
max_signature_len = max(len(_p.signature), max_signature_len)
|
||||
else:
|
||||
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),
|
||||
"",
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.out.write("%s%*s" % (p.name, max_property_len - len(p.name), ""))
|
||||
if p.readable and p.writable:
|
||||
access = "readwrite"
|
||||
elif p.readable:
|
||||
access = "readable "
|
||||
else:
|
||||
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")
|
||||
for m in i.methods:
|
||||
self.print_method_prototype(i, m, in_synopsis=True)
|
||||
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")
|
||||
for s in i.signals:
|
||||
self.print_signal_prototype(i, s, in_synopsis=True)
|
||||
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")
|
||||
for p in i.properties:
|
||||
self.print_property_prototype(i, p, in_synopsis=True)
|
||||
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.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)))
|
||||
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")
|
||||
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")
|
||||
if len(m.since) > 0:
|
||||
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")
|
||||
|
||||
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.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)))
|
||||
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")
|
||||
if len(s.since) > 0:
|
||||
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")
|
||||
|
||||
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.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)))
|
||||
if len(p.since) > 0:
|
||||
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")
|
||||
|
||||
def expand(self, s, expandParamsAndConstants):
|
||||
for key in self.expand_member_dict_keys:
|
||||
s = s.replace(key, self.expand_member_dict[key])
|
||||
for key in self.expand_iface_dict_keys:
|
||||
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,
|
||||
)
|
||||
# replace e.g. %TRUE with <constant>TRUE</constant>
|
||||
s = re.sub(
|
||||
"%[a-zA-Z0-9_]*",
|
||||
lambda m: "<constant>" + m.group(0)[1:] + "</constant>",
|
||||
s,
|
||||
)
|
||||
return s
|
||||
|
||||
def expand_paras(self, s, expandParamsAndConstants):
|
||||
s = self.expand(s, expandParamsAndConstants).strip()
|
||||
res = []
|
||||
if not s.startswith("<para>"):
|
||||
res.append("<para>")
|
||||
for line in s.split("\n"):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
line = "</para><para>"
|
||||
res.append(line)
|
||||
if not s.endswith("</para>"):
|
||||
res.append("</para>")
|
||||
return "\n".join(res)
|
||||
|
||||
def generate_expand_dicts(self):
|
||||
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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
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
|
||||
)
|
||||
|
||||
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.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)
|
||||
if len(i.signals) > 0:
|
||||
self.print_synopsis_signals(i)
|
||||
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)))
|
||||
if len(i.since) > 0:
|
||||
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")
|
||||
|
||||
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')
|
||||
for m in i.methods:
|
||||
self.print_method(i, m)
|
||||
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')
|
||||
for s in i.signals:
|
||||
self.print_signal(i, s)
|
||||
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'
|
||||
)
|
||||
for s in i.properties:
|
||||
self.print_property(i, s)
|
||||
self.out.write("</refsect1>\n")
|
||||
|
||||
self.out.write("</refentry>\n")
|
||||
self.out.write("\n")
|
||||
500
gio/gdbus-2.0/codegen/codegen_main.py
Normal file
500
gio/gdbus-2.0/codegen/codegen_main.py
Normal file
|
|
@ -0,0 +1,500 @@
|
|||
# -*- Mode: Python -*-
|
||||
# coding=utf-8
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
# Copyright (C) 2018 Iñigo Martínez <inigomartinez@gmail.com>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from . import config
|
||||
from . import dbustypes
|
||||
from . import parser
|
||||
from . import codegen
|
||||
from . import codegen_docbook
|
||||
from . import codegen_rst
|
||||
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:
|
||||
if i.name == iface:
|
||||
iface_obj = i
|
||||
break
|
||||
|
||||
if iface_obj is None:
|
||||
print_error('No interface "{}"'.format(iface))
|
||||
|
||||
target_obj = None
|
||||
|
||||
if method:
|
||||
method_obj = find_method(iface_obj, method)
|
||||
if method_obj is None:
|
||||
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:
|
||||
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
|
||||
)
|
||||
)
|
||||
target_obj = arg_obj
|
||||
else:
|
||||
target_obj = method_obj
|
||||
elif signal:
|
||||
signal_obj = find_signal(iface_obj, signal)
|
||||
if signal_obj is None:
|
||||
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
|
||||
)
|
||||
)
|
||||
target_obj = arg_obj
|
||||
else:
|
||||
target_obj = signal_obj
|
||||
elif prop:
|
||||
prop_obj = find_prop(iface_obj, prop)
|
||||
if prop_obj is None:
|
||||
print_error('No property "{}" on interface "{}"'.format(prop, iface))
|
||||
target_obj = prop_obj
|
||||
else:
|
||||
target_obj = iface_obj
|
||||
target_obj.annotations.insert(0, dbustypes.Annotation(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("::")
|
||||
if pos != -1:
|
||||
# signal
|
||||
iface = what[0:pos]
|
||||
signal = what[pos + 2 :]
|
||||
pos = signal.find("[")
|
||||
if pos != -1:
|
||||
arg = signal[pos + 1 :]
|
||||
signal = signal[0:pos]
|
||||
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
|
||||
)
|
||||
else:
|
||||
pos = what.find(":")
|
||||
if pos != -1:
|
||||
# property
|
||||
iface = what[0:pos]
|
||||
prop = what[pos + 1 :]
|
||||
apply_annotation(iface_list, iface, None, None, prop, None, key, value)
|
||||
else:
|
||||
pos = what.find("()")
|
||||
if pos != -1:
|
||||
# method
|
||||
combined = what[0:pos]
|
||||
pos = combined.rfind(".")
|
||||
iface = combined[0:pos]
|
||||
method = combined[pos + 1 :]
|
||||
pos = what.find("[")
|
||||
if pos != -1:
|
||||
arg = what[pos + 1 :]
|
||||
pos = arg.find("]")
|
||||
arg = arg[0:pos]
|
||||
apply_annotation(
|
||||
iface_list, iface, method, None, None, arg, key, value
|
||||
)
|
||||
else:
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
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(
|
||||
"--generate-rst",
|
||||
metavar="OUTFILES",
|
||||
help="Generate reStructuredText in OUTFILES-org.Project.IFace.rst",
|
||||
)
|
||||
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 = 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",
|
||||
)
|
||||
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
if len(args.xml_files) > 0:
|
||||
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
|
||||
or args.generate_rst is not None
|
||||
) and args.output is not None:
|
||||
print_error(
|
||||
"Using --generate-c-code or --generate-docbook or --generate-rst and "
|
||||
"--output at the same time is not allowed"
|
||||
)
|
||||
|
||||
if args.generate_c_code:
|
||||
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")
|
||||
args.body = True
|
||||
elif args.header:
|
||||
if args.output is None:
|
||||
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")
|
||||
|
||||
c_file = args.output
|
||||
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")
|
||||
if args.c_generate_object_manager:
|
||||
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")
|
||||
if args.c_generate_object_manager:
|
||||
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"
|
||||
|
||||
# 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))
|
||||
# Ignore micro component, but still validate it:
|
||||
_ = int(parts[2] if len(parts) > 2 else 0) # noqa: F841
|
||||
except (ValueError, IndexError):
|
||||
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)
|
||||
)
|
||||
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))
|
||||
# Ignore micro component, but still validate it:
|
||||
_ = int(parts[2] if len(parts) > 2 else 0) # noqa: F841
|
||||
except (ValueError, IndexError):
|
||||
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"
|
||||
)
|
||||
|
||||
# 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),
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
)
|
||||
|
||||
all_ifaces = []
|
||||
input_files_basenames = []
|
||||
for fname in sorted(args.files + args.xml_files):
|
||||
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))
|
||||
)
|
||||
all_ifaces.extend(parsed_ifaces)
|
||||
input_files_basenames.append(os.path.basename(fname))
|
||||
|
||||
if args.annotate is not None:
|
||||
apply_annotations(all_ifaces, args.annotate)
|
||||
|
||||
for i in all_ifaces:
|
||||
i.post_process(args.interface_prefix, args.c_namespace)
|
||||
|
||||
docbook = args.generate_docbook
|
||||
docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces)
|
||||
if docbook:
|
||||
docbook_gen.generate(docbook, args.output_directory)
|
||||
|
||||
rst = args.generate_rst
|
||||
rst_gen = codegen_rst.RstCodeGenerator(all_ifaces)
|
||||
if rst:
|
||||
rst_gen.generate(rst, 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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
gen.generate()
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
codegen_main()
|
||||
332
gio/gdbus-2.0/codegen/codegen_rst.py
Normal file
332
gio/gdbus-2.0/codegen/codegen_rst.py
Normal file
|
|
@ -0,0 +1,332 @@
|
|||
# SPDX-FileCopyrightText: 2022 Emmanuele Bassi
|
||||
#
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from . import utils
|
||||
|
||||
# Disable line length warnings as wrapping the templates would be hard
|
||||
# flake8: noqa: E501
|
||||
|
||||
|
||||
class RstCodeGenerator:
|
||||
"""Generates documentation in reStructuredText format."""
|
||||
|
||||
def __init__(self, ifaces):
|
||||
self.ifaces = ifaces
|
||||
self._generate_expand_dicts()
|
||||
|
||||
def _expand(self, s, expandParamsAndConstants):
|
||||
"""Expands parameters and constant literals."""
|
||||
res = []
|
||||
for line in s.split("\n"):
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
res.append("")
|
||||
continue
|
||||
for key in self._expand_member_dict_keys:
|
||||
line = line.replace(key, self._expand_member_dict[key])
|
||||
for key in self._expand_iface_dict_keys:
|
||||
line = line.replace(key, self._expand_iface_dict[key])
|
||||
if expandParamsAndConstants:
|
||||
# replace @foo with ``foo``
|
||||
line = re.sub(
|
||||
"@[a-zA-Z0-9_]*",
|
||||
lambda m: "``" + m.group(0)[1:] + "``",
|
||||
line,
|
||||
)
|
||||
# replace e.g. %TRUE with ``TRUE``
|
||||
line = re.sub(
|
||||
"%[a-zA-Z0-9_]*",
|
||||
lambda m: "``" + m.group(0)[1:] + "``",
|
||||
line,
|
||||
)
|
||||
res.append(line)
|
||||
return "\n".join(res)
|
||||
|
||||
def _generate_expand_dicts(self):
|
||||
"""Generates the dictionaries used to expand gtk-doc sigils."""
|
||||
self._expand_member_dict = {}
|
||||
self._expand_iface_dict = {}
|
||||
for i in self.ifaces:
|
||||
key = f"#{i.name}"
|
||||
value = f"`{i.name}`_"
|
||||
self._expand_iface_dict[key] = value
|
||||
|
||||
for m in i.methods:
|
||||
key = "%s.%s()" % (i.name, m.name)
|
||||
value = f"`{i.name}.{m.name}`_"
|
||||
self._expand_member_dict[key] = value
|
||||
|
||||
for s in i.signals:
|
||||
key = "#%s::%s" % (i.name, s.name)
|
||||
value = f"`{i.name}::{s.name}`_"
|
||||
self._expand_member_dict[key] = value
|
||||
|
||||
for p in i.properties:
|
||||
key = "#%s:%s" % (i.name, p.name)
|
||||
value = f"`{i.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
|
||||
)
|
||||
|
||||
def _generate_header(self, iface):
|
||||
"""Generates the header and preamble of the document."""
|
||||
header_len = len(iface.name)
|
||||
res = [
|
||||
f".. _{iface.name}:",
|
||||
"",
|
||||
"=" * header_len,
|
||||
iface.name,
|
||||
"=" * header_len,
|
||||
"",
|
||||
"-----------",
|
||||
"Description",
|
||||
"-----------",
|
||||
"",
|
||||
f".. _{iface.name} Description:",
|
||||
"",
|
||||
iface.doc_string_brief.strip(),
|
||||
"",
|
||||
self._expand(iface.doc_string, True),
|
||||
"",
|
||||
]
|
||||
if iface.since:
|
||||
res += [
|
||||
f"Interface available since: {iface.since}.",
|
||||
"",
|
||||
]
|
||||
if iface.deprecated:
|
||||
res += [
|
||||
".. warning::",
|
||||
"",
|
||||
" This interface is deprecated.",
|
||||
"",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
return "\n".join(res)
|
||||
|
||||
def _generate_section(self, title, name):
|
||||
"""Generates a section with the given title."""
|
||||
res = [
|
||||
"-" * len(title),
|
||||
title,
|
||||
"-" * len(title),
|
||||
"",
|
||||
f".. {name} {title}:",
|
||||
"",
|
||||
"",
|
||||
]
|
||||
return "\n".join(res)
|
||||
|
||||
def _generate_properties(self, iface):
|
||||
"""Generates the properties section."""
|
||||
res = []
|
||||
for p in iface.properties:
|
||||
title = f"{iface.name}:{p.name}"
|
||||
if p.readable and p.writable:
|
||||
access = "readwrite"
|
||||
elif p.writable:
|
||||
access = "writable"
|
||||
else:
|
||||
access = "readable"
|
||||
res += [
|
||||
title,
|
||||
"^" * len(title),
|
||||
"",
|
||||
"::",
|
||||
"",
|
||||
f" {p.name} {access} {p.signature}",
|
||||
"",
|
||||
"",
|
||||
self._expand(p.doc_string, True),
|
||||
"",
|
||||
]
|
||||
if p.since:
|
||||
res += [
|
||||
f"Property available since: {p.since}.",
|
||||
"",
|
||||
]
|
||||
if p.deprecated:
|
||||
res += [
|
||||
".. warning::",
|
||||
"",
|
||||
" This property is deprecated.",
|
||||
"",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
return "\n".join(res)
|
||||
|
||||
def _generate_method_signature(self, method):
|
||||
"""Generates the method signature as a code block."""
|
||||
res = [
|
||||
"::",
|
||||
"",
|
||||
]
|
||||
n_in_args = len(method.in_args)
|
||||
n_out_args = len(method.out_args)
|
||||
if n_in_args == 0 and n_out_args == 0:
|
||||
res += [
|
||||
f" {method.name} ()",
|
||||
]
|
||||
else:
|
||||
res += [
|
||||
f" {method.name} (",
|
||||
]
|
||||
for idx, arg in enumerate(method.in_args):
|
||||
if idx == n_in_args - 1 and n_out_args == 0:
|
||||
res += [
|
||||
f" IN {arg.name} {arg.signature}",
|
||||
]
|
||||
else:
|
||||
res += [
|
||||
f" IN {arg.name} {arg.signature},",
|
||||
]
|
||||
for idx, arg in enumerate(method.out_args):
|
||||
if idx == n_out_args - 1:
|
||||
res += [
|
||||
f" OUT {arg.name} {arg.signature}",
|
||||
]
|
||||
else:
|
||||
res += [
|
||||
f" OUT {arg.name} {arg.signature},",
|
||||
]
|
||||
res += [
|
||||
" )",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
return "\n".join(res)
|
||||
|
||||
def _generate_methods(self, iface):
|
||||
"""Generates the methods section."""
|
||||
res = []
|
||||
for m in iface.methods:
|
||||
title = f"{iface.name}.{m.name}"
|
||||
res += [
|
||||
title,
|
||||
"^" * len(title),
|
||||
"",
|
||||
self._generate_method_signature(m),
|
||||
"",
|
||||
self._expand(m.doc_string, True),
|
||||
"",
|
||||
]
|
||||
for a in m.in_args:
|
||||
arg_desc = self._expand(a.doc_string, True)
|
||||
res += [
|
||||
f"{a.name}",
|
||||
f" {arg_desc}",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
if m.since:
|
||||
res += [
|
||||
f"Method available since: {m.since}.",
|
||||
"",
|
||||
]
|
||||
if m.deprecated:
|
||||
res += [
|
||||
".. warning::",
|
||||
"",
|
||||
" This method is deprecated.",
|
||||
"",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
return "\n".join(res)
|
||||
|
||||
def _generate_signal_signature(self, signal):
|
||||
"""Generates the signal signature."""
|
||||
res = [
|
||||
"::",
|
||||
"",
|
||||
]
|
||||
n_args = len(signal.args)
|
||||
if n_args == 0:
|
||||
res += [
|
||||
f" {signal.name} ()",
|
||||
]
|
||||
else:
|
||||
res += [
|
||||
f" {signal.name} (",
|
||||
]
|
||||
for idx, arg in enumerate(signal.args):
|
||||
if idx == n_args - 1:
|
||||
res += [
|
||||
f" {arg.name} {arg.signature}",
|
||||
]
|
||||
else:
|
||||
res += [
|
||||
f" {arg.name} {arg.signature},",
|
||||
]
|
||||
res += [
|
||||
" )",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
return "\n".join(res)
|
||||
|
||||
def _generate_signals(self, iface):
|
||||
"""Generates the signals section."""
|
||||
res = []
|
||||
for s in iface.signals:
|
||||
title = f"{iface.name}::{s.name}"
|
||||
res += [
|
||||
title,
|
||||
"^" * len(title),
|
||||
"",
|
||||
self._generate_signal_signature(s),
|
||||
"",
|
||||
self._expand(s.doc_string, True),
|
||||
"",
|
||||
]
|
||||
for a in s.args:
|
||||
arg_desc = self._expand(a.doc_string, True)
|
||||
res += [
|
||||
f"{a.name}",
|
||||
f" {arg_desc}",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
if s.since:
|
||||
res += [
|
||||
f"Signal available since: {s.since}.",
|
||||
"",
|
||||
]
|
||||
if s.deprecated:
|
||||
res += [
|
||||
".. warning::",
|
||||
"",
|
||||
" This signal is deprecated.",
|
||||
"",
|
||||
"",
|
||||
]
|
||||
res += [""]
|
||||
return "\n".join(res)
|
||||
|
||||
def generate(self, rst, outdir):
|
||||
"""Generates the reStructuredText file for each interface."""
|
||||
for i in self.ifaces:
|
||||
with open(os.path.join(outdir, f"{rst}-{i.name}.rst"), "w") as outfile:
|
||||
outfile.write(self._generate_header(i))
|
||||
if len(i.properties) > 0:
|
||||
outfile.write(self._generate_section("Properties", i.name))
|
||||
outfile.write(self._generate_properties(i))
|
||||
if len(i.methods) > 0:
|
||||
outfile.write(self._generate_section("Methods", i.name))
|
||||
outfile.write(self._generate_methods(i))
|
||||
if len(i.signals) > 0:
|
||||
outfile.write(self._generate_section("Signals", i.name))
|
||||
outfile.write(self._generate_signals(i))
|
||||
24
gio/gdbus-2.0/codegen/config.py.in
Normal file
24
gio/gdbus-2.0/codegen/config.py.in
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# -*- Mode: Python -*-
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
VERSION = "@VERSION@"
|
||||
MAJOR_VERSION = @MAJOR_VERSION@
|
||||
MINOR_VERSION = @MINOR_VERSION@
|
||||
525
gio/gdbus-2.0/codegen/dbustypes.py
Normal file
525
gio/gdbus-2.0/codegen/dbustypes.py
Normal file
|
|
@ -0,0 +1,525 @@
|
|||
# -*- Mode: Python -*-
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
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 = ""
|
||||
|
||||
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"
|
||||
)
|
||||
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(".", "_")
|
||||
)
|
||||
|
||||
if len(self.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = container.since
|
||||
|
||||
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 = ""
|
||||
|
||||
def post_process(self, interface_prefix, cns, cns_upper, cns_lower, arg_number):
|
||||
if len(self.doc_string) == 0:
|
||||
self.doc_string = utils.lookup_docs(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
if self.name is None:
|
||||
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 = ""
|
||||
|
||||
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.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.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.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.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.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.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.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.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)"
|
||||
|
||||
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
|
||||
self.h_type_implies_unix_fd = h_type_implies_unix_fd
|
||||
self.in_args = []
|
||||
self.out_args = []
|
||||
self.annotations = []
|
||||
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
|
||||
):
|
||||
if len(self.doc_string) == 0:
|
||||
self.doc_string = utils.lookup_docs(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = containing_iface.since
|
||||
|
||||
name = self.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("_", "-")
|
||||
|
||||
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:
|
||||
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:
|
||||
self.unix_fd = 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"):
|
||||
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.deprecated = False
|
||||
|
||||
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:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = containing_iface.since
|
||||
|
||||
name = self.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("_", "-")
|
||||
|
||||
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"
|
||||
):
|
||||
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.annotations = self.annotations
|
||||
self.readable = False
|
||||
self.writable = False
|
||||
if self.access == "readwrite":
|
||||
self.readable = True
|
||||
self.writable = True
|
||||
elif self.access == "read":
|
||||
self.readable = True
|
||||
elif self.access == "write":
|
||||
self.writable = True
|
||||
else:
|
||||
print_error('Invalid access type "{}"'.format(self.access))
|
||||
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
|
||||
):
|
||||
if len(self.doc_string) == 0:
|
||||
self.doc_string = utils.lookup_docs(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = containing_iface.since
|
||||
|
||||
name = self.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("_", "-")
|
||||
# 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_"
|
||||
|
||||
# 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"
|
||||
):
|
||||
self.deprecated = True
|
||||
|
||||
for a in self.annotations:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
# 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"):
|
||||
self.emits_changed_signal = False
|
||||
|
||||
|
||||
class Interface:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.methods = []
|
||||
self.signals = []
|
||||
self.properties = []
|
||||
self.annotations = []
|
||||
self.doc_string = ""
|
||||
self.doc_string_brief = ""
|
||||
self.since = ""
|
||||
self.deprecated = False
|
||||
|
||||
def post_process(self, interface_prefix, c_namespace):
|
||||
if len(self.doc_string) == 0:
|
||||
self.doc_string = utils.lookup_docs(self.annotations)
|
||||
if len(self.doc_string_brief) == 0:
|
||||
self.doc_string_brief = utils.lookup_brief_docs(self.annotations)
|
||||
if len(self.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
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() + "_"
|
||||
else:
|
||||
cns = c_namespace
|
||||
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 = ""
|
||||
|
||||
overridden_name = utils.lookup_annotation(
|
||||
self.annotations, "org.gtk.GDBus.C.Name"
|
||||
)
|
||||
if utils.is_ugly_case(overridden_name):
|
||||
name = overridden_name.replace("_", "")
|
||||
name_with_ns = cns + name
|
||||
self.name_without_prefix = name
|
||||
self.camel_name = name_with_ns
|
||||
self.ns_upper = cns_upper
|
||||
self.name_lower = cns_lower + overridden_name.lower()
|
||||
self.name_upper = overridden_name.upper()
|
||||
|
||||
# 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) :]
|
||||
self.name_without_prefix = name
|
||||
name = utils.strip_dots(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("_", "-")
|
||||
|
||||
if (
|
||||
utils.lookup_annotation(self.annotations, "org.freedesktop.DBus.Deprecated")
|
||||
== "true"
|
||||
):
|
||||
self.deprecated = True
|
||||
|
||||
for m in self.methods:
|
||||
m.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
for s in self.signals:
|
||||
s.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
for p in self.properties:
|
||||
p.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
for a in self.annotations:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
55
gio/gdbus-2.0/codegen/gdbus-codegen.in
Executable file
55
gio/gdbus-2.0/codegen/gdbus-codegen.in
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env @PYTHON@
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
srcdir = os.getenv('UNINSTALLED_GLIB_SRCDIR', None)
|
||||
filedir = os.path.dirname(__file__)
|
||||
|
||||
if srcdir is not None:
|
||||
path = os.path.join(srcdir, 'gio', 'gdbus-2.0')
|
||||
elif os.path.basename(filedir) == 'bin':
|
||||
# Make the prefix containing gdbus-codegen 'relocatable' at runtime by
|
||||
# adding /some/prefix/bin/../share/glib-2.0 to the python path
|
||||
path = os.path.join(filedir, '..', 'share', 'glib-2.0')
|
||||
else:
|
||||
# Assume that the modules we need are in the current directory and add the
|
||||
# parent directory to the python path.
|
||||
path = os.path.join(filedir, '..')
|
||||
|
||||
# Canonicalize, then do further testing
|
||||
path = os.path.abspath(path)
|
||||
|
||||
# If the above path detection failed, use the hard-coded datadir. This can
|
||||
# happen when, for instance, bindir and datadir are not in the same prefix or
|
||||
# on Windows where we cannot make any guarantees about the directory structure.
|
||||
#
|
||||
# In these cases our installation cannot be relocatable, but at least we should
|
||||
# be able to find the codegen module.
|
||||
if not os.path.isfile(os.path.join(path, 'codegen', 'codegen_main.py')):
|
||||
path = os.path.join('@DATADIR@', 'glib-2.0')
|
||||
|
||||
sys.path.insert(0, path)
|
||||
from codegen import codegen_main
|
||||
|
||||
sys.exit(codegen_main.codegen_main())
|
||||
42
gio/gdbus-2.0/codegen/meson.build
Normal file
42
gio/gdbus-2.0/codegen/meson.build
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
gdbus_codegen_files = [
|
||||
'__init__.py',
|
||||
'codegen.py',
|
||||
'codegen_main.py',
|
||||
'codegen_docbook.py',
|
||||
'codegen_rst.py',
|
||||
'dbustypes.py',
|
||||
'parser.py',
|
||||
'utils.py',
|
||||
]
|
||||
|
||||
gdbus_codegen_conf = configuration_data()
|
||||
gdbus_codegen_conf.set('VERSION', glib_version)
|
||||
gdbus_codegen_conf.set('MAJOR_VERSION', major_version)
|
||||
gdbus_codegen_conf.set('MINOR_VERSION', minor_version)
|
||||
gdbus_codegen_conf.set('PYTHON', python_name)
|
||||
gdbus_codegen_conf.set('DATADIR', glib_datadir)
|
||||
|
||||
# Install gdbus-codegen executable
|
||||
gdbus_codegen = configure_file(input : 'gdbus-codegen.in',
|
||||
output : 'gdbus-codegen',
|
||||
install_dir : get_option('bindir'),
|
||||
configuration : gdbus_codegen_conf
|
||||
)
|
||||
# Provide tools for others when we're a subproject and they use the Meson GNOME module
|
||||
meson.override_find_program('gdbus-codegen', gdbus_codegen)
|
||||
|
||||
codegen_dir = join_paths(glib_datadir, 'glib-2.0', 'codegen')
|
||||
|
||||
gdbus_codegen_built_files = []
|
||||
gdbus_codegen_built_files += configure_file(input : 'config.py.in',
|
||||
output : 'config.py',
|
||||
install_dir : codegen_dir,
|
||||
configuration : gdbus_codegen_conf)
|
||||
|
||||
foreach f : gdbus_codegen_files
|
||||
# Copy these into the builddir so that gdbus-codegen can be used uninstalled
|
||||
# and then install it too so that it can be used after installation
|
||||
gdbus_codegen_built_files += configure_file(input : f, output : f,
|
||||
install_dir : codegen_dir,
|
||||
copy : true)
|
||||
endforeach
|
||||
302
gio/gdbus-2.0/codegen/parser.py
Normal file
302
gio/gdbus-2.0/codegen/parser.py
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
# -*- Mode: Python -*-
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
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"
|
||||
|
||||
def __init__(self, xml_data, h_type_implies_unix_fd=True):
|
||||
self._parser = xml.parsers.expat.ParserCreate()
|
||||
self._parser.CommentHandler = self.handle_comment
|
||||
self._parser.CharacterDataHandler = self.handle_char_data
|
||||
self._parser.StartElementHandler = self.handle_start_element
|
||||
self._parser.EndElementHandler = self.handle_end_element
|
||||
|
||||
self.parsed_interfaces = []
|
||||
self._cur_object = None
|
||||
|
||||
self.state = DBusXMLParser.STATE_TOP
|
||||
self.state_stack = []
|
||||
self._cur_object = None
|
||||
self._cur_object_stack = []
|
||||
|
||||
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"
|
||||
|
||||
def handle_comment(self, data):
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BEGIN
|
||||
lines = data.split("\n")
|
||||
symbol = ""
|
||||
body = ""
|
||||
in_para = False
|
||||
params = {}
|
||||
for line in lines:
|
||||
orig_line = line
|
||||
line = line.lstrip()
|
||||
if comment_state == DBusXMLParser.COMMENT_STATE_BEGIN:
|
||||
if len(line) > 0:
|
||||
colon_index = line.find(": ")
|
||||
if colon_index == -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()
|
||||
if len(rest_of_line) > 0:
|
||||
body += f"{rest_of_line}\n"
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_PARAMS
|
||||
elif comment_state == DBusXMLParser.COMMENT_STATE_PARAMS:
|
||||
if line.startswith("@"):
|
||||
colon_index = line.find(": ")
|
||||
if colon_index == -1:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BODY
|
||||
if not in_para:
|
||||
body += "\n"
|
||||
in_para = True
|
||||
body += f"{orig_line}\n"
|
||||
else:
|
||||
param = line[1:colon_index]
|
||||
docs = line[colon_index + 2 :]
|
||||
params[param] = docs
|
||||
else:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BODY
|
||||
if len(line) > 0:
|
||||
if not in_para:
|
||||
body += "\n"
|
||||
in_para = True
|
||||
body += orig_line + "\n"
|
||||
elif comment_state == DBusXMLParser.COMMENT_STATE_BODY:
|
||||
if len(line) > 0:
|
||||
if not in_para:
|
||||
in_para = True
|
||||
body += orig_line + "\n"
|
||||
else:
|
||||
if in_para:
|
||||
body += "\n"
|
||||
in_para = False
|
||||
if in_para:
|
||||
body += "\n"
|
||||
|
||||
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
|
||||
pass
|
||||
|
||||
def handle_start_element(self, name, attrs):
|
||||
old_state = self.state
|
||||
old_cur_object = self._cur_object
|
||||
if self.state == DBusXMLParser.STATE_IGNORED:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
elif self.state == DBusXMLParser.STATE_TOP:
|
||||
if name == DBusXMLParser.STATE_NODE:
|
||||
self.state = DBusXMLParser.STATE_NODE
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
elif self.state == DBusXMLParser.STATE_NODE:
|
||||
if name == DBusXMLParser.STATE_INTERFACE:
|
||||
self.state = DBusXMLParser.STATE_INTERFACE
|
||||
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"])
|
||||
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"]:
|
||||
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"]
|
||||
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()
|
||||
|
||||
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
|
||||
)
|
||||
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"])
|
||||
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"])
|
||||
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"])
|
||||
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"]:
|
||||
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()
|
||||
|
||||
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":
|
||||
self._cur_object.in_args.append(arg)
|
||||
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"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
|
||||
# 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 doc_string is not 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()
|
||||
|
||||
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"])
|
||||
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"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
|
||||
# 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 doc_string is not 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()
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_PROPERTY:
|
||||
if name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_ARG:
|
||||
if name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
anno = dbustypes.Annotation(attrs["name"], attrs["value"])
|
||||
self._cur_object.annotations.append(anno)
|
||||
self._cur_object = anno
|
||||
else:
|
||||
self.state = DBusXMLParser.STATE_IGNORED
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_ANNOTATION:
|
||||
if name == DBusXMLParser.STATE_ANNOTATION:
|
||||
self.state = DBusXMLParser.STATE_ANNOTATION
|
||||
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
|
||||
)
|
||||
)
|
||||
|
||||
self.state_stack.append(old_state)
|
||||
self._cur_object_stack.append(old_cur_object)
|
||||
|
||||
def handle_end_element(self, name):
|
||||
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
|
||||
165
gio/gdbus-2.0/codegen/utils.py
Normal file
165
gio/gdbus-2.0/codegen/utils.py
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
# -*- Mode: Python -*-
|
||||
|
||||
# GDBus - GLib D-Bus Library
|
||||
#
|
||||
# Copyright (C) 2008-2011 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General
|
||||
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import distutils.version
|
||||
import os
|
||||
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"
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
else:
|
||||
real_prefix = prefix
|
||||
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")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def print_warning(msg, fatal=False):
|
||||
"""Print a warning, and optionally terminate"""
|
||||
if fatal:
|
||||
color = Color.RED
|
||||
prefix = "ERROR"
|
||||
else:
|
||||
color = Color.YELLOW
|
||||
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")
|
||||
|
||||
|
||||
def strip_dots(s):
|
||||
ret = ""
|
||||
force_upper = False
|
||||
for c in s:
|
||||
if c == ".":
|
||||
force_upper = True
|
||||
else:
|
||||
if force_upper:
|
||||
ret += c.upper()
|
||||
force_upper = False
|
||||
else:
|
||||
ret += c
|
||||
return ret
|
||||
|
||||
|
||||
def dots_to_hyphens(s):
|
||||
return s.replace(".", "-")
|
||||
|
||||
|
||||
def camel_case_to_uscore(s):
|
||||
ret = ""
|
||||
insert_uscore = False
|
||||
prev_was_lower = False
|
||||
initial = True
|
||||
for c in s:
|
||||
# Keep initial underscores in camel case
|
||||
if initial and c == "_":
|
||||
ret += "_"
|
||||
continue
|
||||
initial = False
|
||||
|
||||
if c.isupper():
|
||||
if prev_was_lower:
|
||||
insert_uscore = True
|
||||
prev_was_lower = False
|
||||
else:
|
||||
prev_was_lower = True
|
||||
if insert_uscore:
|
||||
ret += "_"
|
||||
ret += c.lower()
|
||||
insert_uscore = False
|
||||
return ret
|
||||
|
||||
|
||||
def is_ugly_case(s):
|
||||
if s and s.find("_") > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def lookup_annotation(annotations, key):
|
||||
if annotations:
|
||||
for a in annotations:
|
||||
if a.key == key:
|
||||
return a.value
|
||||
return None
|
||||
|
||||
|
||||
def lookup_docs(annotations):
|
||||
s = lookup_annotation(annotations, "org.gtk.GDBus.DocString")
|
||||
if s is None:
|
||||
return ""
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def lookup_since(annotations):
|
||||
s = lookup_annotation(annotations, "org.gtk.GDBus.Since")
|
||||
if s is None:
|
||||
return ""
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def lookup_brief_docs(annotations):
|
||||
s = lookup_annotation(annotations, "org.gtk.GDBus.DocString.Short")
|
||||
if s is None:
|
||||
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"
|
||||
elif key[0]:
|
||||
v = str(key[0])
|
||||
else:
|
||||
v = "0"
|
||||
return (distutils.version.LooseVersion(v), key[1])
|
||||
Loading…
Add table
Add a link
Reference in a new issue