mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
Avoid using - (hyphen) in gdbus-codegen directory name
It's an invalid character in Python module names and prevents us from being able to import it. https://bugzilla.gnome.org/show_bug.cgi?id=650763
This commit is contained in:
committed by
Colin Walters
parent
33831bda24
commit
0eaec4e59a
2
gio/gdbus-2.0/codegen/.gitignore
vendored
Normal file
2
gio/gdbus-2.0/codegen/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.pyc
|
||||
gdbus-codegen
|
30
gio/gdbus-2.0/codegen/Makefile.am
Normal file
30
gio/gdbus-2.0/codegen/Makefile.am
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
NULL =
|
||||
bin_SCRIPTS =
|
||||
CLEANFILES =
|
||||
EXTRA_DIST =
|
||||
|
||||
codegendir = $(libdir)/gdbus-2.0/codegen
|
||||
codegen_PYTHON = \
|
||||
__init__.py \
|
||||
codegen.py \
|
||||
codegen_main.py \
|
||||
codegen_docbook.py \
|
||||
config.py \
|
||||
dbustypes.py \
|
||||
parser.py \
|
||||
utils.py \
|
||||
$(NULL)
|
||||
|
||||
CLEANFILES += config.pyc
|
||||
|
||||
bin_SCRIPTS += gdbus-codegen
|
||||
CLEANFILES += gdbus-codegen
|
||||
EXTRA_DIST += gdbus-codegen.in
|
||||
|
||||
gdbus-codegen: gdbus-codegen.in Makefile
|
||||
$(AM_V_GEN) sed -e 's,@libdir\@,$(libdir),' -e 's,@PYTHON\@,$(PYTHON),' $< > $@.tmp && mv $@.tmp $@
|
||||
@chmod a+x $@
|
||||
|
||||
clean-local:
|
||||
rm -f *~
|
0
gio/gdbus-2.0/codegen/__init__.py
Normal file
0
gio/gdbus-2.0/codegen/__init__.py
Normal file
3351
gio/gdbus-2.0/codegen/codegen.py
Normal file
3351
gio/gdbus-2.0/codegen/codegen.py
Normal file
File diff suppressed because it is too large
Load Diff
325
gio/gdbus-2.0/codegen/codegen_docbook.py
Normal file
325
gio/gdbus-2.0/codegen/codegen_docbook.py
Normal file
@@ -0,0 +1,325 @@
|
||||
# -*- 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 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, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
import config
|
||||
import utils
|
||||
import dbustypes
|
||||
import parser
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
||||
class DocbookCodeGenerator:
|
||||
def __init__(self, ifaces, docbook):
|
||||
self.ifaces = ifaces
|
||||
self.docbook = docbook
|
||||
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('<para>%s</para>\n'%(self.expand(m.doc_string, True)))
|
||||
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><para>%s</para></listitem>\n'%(self.expand(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><para>%s</para></listitem>\n'%(self.expand(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('<para>%s</para>\n'%(self.expand(s.doc_string, True)))
|
||||
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><para>%s</para></listitem>\n'%(self.expand(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('<para>%s</para>\n'%(self.expand(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 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 = self.expand_member_dict.keys()
|
||||
self.expand_member_dict_keys.sort(reverse=True)
|
||||
self.expand_iface_dict_keys = self.expand_iface_dict.keys()
|
||||
self.expand_iface_dict_keys.sort(reverse=True)
|
||||
|
||||
def generate(self):
|
||||
for i in self.ifaces:
|
||||
self.out = file('%s-%s.xml'%(self.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(' <para>%s</para>\n'%(self.expand(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')
|
||||
|
200
gio/gdbus-2.0/codegen/codegen_main.py
Executable file
200
gio/gdbus-2.0/codegen/codegen_main.py
Executable file
@@ -0,0 +1,200 @@
|
||||
# -*- 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 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, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
|
||||
import config
|
||||
import utils
|
||||
import dbustypes
|
||||
import parser
|
||||
import codegen
|
||||
import codegen_docbook
|
||||
|
||||
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):
|
||||
for i in iface_list:
|
||||
if i.name == iface:
|
||||
iface_obj = i
|
||||
break
|
||||
|
||||
if iface_obj == None:
|
||||
raise RuntimeError('No interface %s'%iface)
|
||||
|
||||
target_obj = None
|
||||
|
||||
if method:
|
||||
method_obj = find_method(iface_obj, method)
|
||||
if method_obj == None:
|
||||
raise RuntimeError('No method %s on interface %s'%(method, iface))
|
||||
if arg:
|
||||
arg_obj = find_arg(method_obj.in_args, arg)
|
||||
if (arg_obj == None):
|
||||
arg_obj = find_arg(method_obj.out_args, arg)
|
||||
if (arg_obj == None):
|
||||
raise RuntimeError('No arg %s on method %s on interface %s'%(arg, method, iface))
|
||||
target_obj = arg_obj
|
||||
else:
|
||||
target_obj = method_obj
|
||||
elif signal:
|
||||
signal_obj = find_signal(iface_obj, signal)
|
||||
if signal_obj == None:
|
||||
raise RuntimeError('No signal %s on interface %s'%(signal, iface))
|
||||
if arg:
|
||||
arg_obj = find_arg(signal_obj.args, arg)
|
||||
if (arg_obj == None):
|
||||
raise RuntimeError('No arg %s on signal %s on interface %s'%(arg, signal, iface))
|
||||
target_obj = arg_obj
|
||||
else:
|
||||
target_obj = signal_obj
|
||||
elif prop:
|
||||
prop_obj = find_prop(iface_obj, prop)
|
||||
if prop_obj == None:
|
||||
raise RuntimeError('No property %s on interface %s'%(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 = optparse.OptionParser('%prog [options]')
|
||||
arg_parser.add_option('', '--xml-files', metavar='FILE', action='append',
|
||||
help='D-Bus introspection XML file')
|
||||
arg_parser.add_option('', '--interface-prefix', metavar='PREFIX', default='',
|
||||
help='String to strip from D-Bus interface names for code and docs')
|
||||
arg_parser.add_option('', '--c-namespace', metavar='NAMESPACE', default='',
|
||||
help='The namespace to use for generated C code')
|
||||
arg_parser.add_option('', '--c-generate-object-manager', action='store_true',
|
||||
help='Generate a GDBusObjectManagerClient subclass when generating C code')
|
||||
arg_parser.add_option('', '--generate-c-code', metavar='OUTFILES',
|
||||
help='Generate C code in OUTFILES.[ch]')
|
||||
arg_parser.add_option('', '--generate-docbook', metavar='OUTFILES',
|
||||
help='Generate Docbook in OUTFILES-org.Project.IFace.xml')
|
||||
arg_parser.add_option('', '--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
|
||||
help='Add annotation (may be used several times)')
|
||||
(opts, args) = arg_parser.parse_args();
|
||||
|
||||
all_ifaces = []
|
||||
for fname in args:
|
||||
f = open(fname)
|
||||
xml_data = f.read()
|
||||
f.close()
|
||||
parsed_ifaces = parser.parse_dbus_xml(xml_data)
|
||||
all_ifaces.extend(parsed_ifaces)
|
||||
|
||||
if opts.annotate != None:
|
||||
apply_annotations(all_ifaces, opts.annotate)
|
||||
|
||||
for i in parsed_ifaces:
|
||||
i.post_process(opts.interface_prefix, opts.c_namespace)
|
||||
|
||||
docbook = opts.generate_docbook
|
||||
docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces, docbook);
|
||||
if docbook:
|
||||
ret = docbook_gen.generate()
|
||||
|
||||
c_code = opts.generate_c_code
|
||||
if c_code:
|
||||
h = file(c_code + '.h', 'w')
|
||||
c = file(c_code + '.c', 'w')
|
||||
gen = codegen.CodeGenerator(all_ifaces,
|
||||
opts.c_namespace,
|
||||
opts.interface_prefix,
|
||||
opts.c_generate_object_manager,
|
||||
docbook_gen,
|
||||
h, c);
|
||||
ret = gen.generate()
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
codegen_main()
|
27
gio/gdbus-2.0/codegen/config.py.in
Normal file
27
gio/gdbus-2.0/codegen/config.py.in
Normal file
@@ -0,0 +1,27 @@
|
||||
# -*- 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 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, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
DATADIR = "@datarootdir@"
|
||||
DATADIR = DATADIR.replace(
|
||||
"${prefix}", "@prefix@")
|
||||
VERSION = "@VERSION@"
|
414
gio/gdbus-2.0/codegen/dbustypes.py
Normal file
414
gio/gdbus-2.0/codegen/dbustypes.py
Normal file
@@ -0,0 +1,414 @@
|
||||
# -*- 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 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, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import utils
|
||||
|
||||
class Annotation:
|
||||
def __init__(self, key, value):
|
||||
self.key = key
|
||||
self.value = value
|
||||
self.annotations = []
|
||||
|
||||
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, c_namespace, 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 == 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'
|
||||
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'
|
||||
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'
|
||||
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'
|
||||
|
||||
class Method:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.in_args = []
|
||||
self.out_args = []
|
||||
self.annotations = []
|
||||
self.doc_string = ''
|
||||
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.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
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, c_namespace, arg_count)
|
||||
arg_count += 1
|
||||
|
||||
for a in self.out_args:
|
||||
a.post_process(interface_prefix, c_namespace, arg_count)
|
||||
arg_count += 1
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
|
||||
self.deprecated = True
|
||||
|
||||
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, c_namespace):
|
||||
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)
|
||||
|
||||
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, c_namespace, arg_count)
|
||||
arg_count += 1
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
|
||||
self.deprecated = True
|
||||
|
||||
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:
|
||||
raise RuntimeError('Invalid access type %s'%self.access)
|
||||
self.doc_string = ''
|
||||
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.since) == 0:
|
||||
self.since = utils.lookup_since(self.annotations)
|
||||
|
||||
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('-', '_')
|
||||
if self.name_lower == 'type':
|
||||
self.name_lower = 'type_'
|
||||
self.name_hyphen = self.name_lower.replace('_', '-')
|
||||
|
||||
# recalculate arg
|
||||
self.arg.annotations = self.annotations
|
||||
self.arg.post_process(interface_prefix, c_namespace, 0)
|
||||
|
||||
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
|
||||
self.deprecated = True
|
||||
|
||||
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)
|
||||
|
||||
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 = c_namespace + name
|
||||
self.name_without_prefix = name
|
||||
self.camel_name = name_with_ns
|
||||
if len(c_namespace) > 0:
|
||||
self.ns_upper = utils.camel_case_to_uscore(c_namespace).upper() + '_'
|
||||
self.name_lower = utils.camel_case_to_uscore(c_namespace) + '_' + overridden_name.lower()
|
||||
else:
|
||||
self.ns_upper = ''
|
||||
self.name_lower = overridden_name.lower()
|
||||
self.name_upper = overridden_name.upper()
|
||||
|
||||
#raise RuntimeError('handle Ugly_Case ', 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(c_namespace + '.' + name)
|
||||
|
||||
self.camel_name = name_with_ns
|
||||
if len(c_namespace) > 0:
|
||||
self.ns_upper = utils.camel_case_to_uscore(c_namespace).upper() + '_'
|
||||
self.name_lower = utils.camel_case_to_uscore(c_namespace) + '_' + utils.camel_case_to_uscore(name)
|
||||
else:
|
||||
self.ns_upper = ''
|
||||
self.name_lower = utils.camel_case_to_uscore(name_with_ns)
|
||||
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, c_namespace)
|
||||
|
||||
for s in self.signals:
|
||||
s.post_process(interface_prefix, c_namespace)
|
||||
|
||||
for p in self.properties:
|
||||
p.post_process(interface_prefix, c_namespace)
|
33
gio/gdbus-2.0/codegen/gdbus-codegen.in
Executable file
33
gio/gdbus-2.0/codegen/gdbus-codegen.in
Executable file
@@ -0,0 +1,33 @@
|
||||
#!@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 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, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
path = os.path.join('@libdir@', 'gdbus-2.0', 'codegen')
|
||||
sys.path.insert(0, path)
|
||||
|
||||
from codegen_main import codegen_main
|
||||
|
||||
sys.exit(codegen_main())
|
290
gio/gdbus-2.0/codegen/parser.py
Normal file
290
gio/gdbus-2.0/codegen/parser.py
Normal file
@@ -0,0 +1,290 @@
|
||||
# -*- 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 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, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import dbustypes
|
||||
|
||||
import sys
|
||||
import xml.parsers.expat
|
||||
|
||||
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):
|
||||
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._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 += '<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 colon_index == -1:
|
||||
comment_state = DBusXMLParser.COMMENT_STATE_BODY
|
||||
if not in_para:
|
||||
body += '<para>'
|
||||
in_para = True
|
||||
body += 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 += '<para>'
|
||||
in_para = True
|
||||
body += orig_line + '\n'
|
||||
elif comment_state == DBusXMLParser.COMMENT_STATE_BODY:
|
||||
if len(line) > 0:
|
||||
if not in_para:
|
||||
body += '<para>'
|
||||
in_para = True
|
||||
body += orig_line + '\n'
|
||||
else:
|
||||
if in_para:
|
||||
body += '</para>'
|
||||
in_para = False
|
||||
if in_para:
|
||||
body += '</para>'
|
||||
|
||||
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 attrs.has_key('name') and self.doc_comment_last_symbol == attrs['name']:
|
||||
self._cur_object.doc_string = self.doc_comment_body
|
||||
if self.doc_comment_params.has_key('short_description'):
|
||||
short_description = self.doc_comment_params['short_description']
|
||||
self._cur_object.doc_string_brief = short_description
|
||||
if self.doc_comment_params.has_key('since'):
|
||||
self._cur_object.since = self.doc_comment_params['since']
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_INTERFACE:
|
||||
if name == DBusXMLParser.STATE_METHOD:
|
||||
self.state = DBusXMLParser.STATE_METHOD
|
||||
method = dbustypes.Method(attrs['name'])
|
||||
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 attrs.has_key('name') and self.doc_comment_last_symbol == attrs['name']:
|
||||
self._cur_object.doc_string = self.doc_comment_body
|
||||
if self.doc_comment_params.has_key('since'):
|
||||
self._cur_object.since = self.doc_comment_params['since']
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_METHOD:
|
||||
if name == DBusXMLParser.STATE_ARG:
|
||||
self.state = DBusXMLParser.STATE_ARG
|
||||
arg_name = None
|
||||
if attrs.has_key('name'):
|
||||
arg_name = attrs['name']
|
||||
arg = dbustypes.Arg(arg_name, attrs['type'])
|
||||
direction = attrs['direction']
|
||||
if direction == 'in':
|
||||
self._cur_object.in_args.append(arg)
|
||||
elif direction == 'out':
|
||||
self._cur_object.out_args.append(arg)
|
||||
else:
|
||||
raise RuntimeError('Invalid direction "%s"'%(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 attrs.has_key('name') and self.doc_comment_params.has_key(attrs['name']):
|
||||
doc_string = self.doc_comment_params[attrs['name']]
|
||||
if doc_string != None:
|
||||
self._cur_object.doc_string = doc_string
|
||||
if self.doc_comment_params.has_key('since'):
|
||||
self._cur_object.since = self.doc_comment_params['since']
|
||||
|
||||
elif self.state == DBusXMLParser.STATE_SIGNAL:
|
||||
if name == DBusXMLParser.STATE_ARG:
|
||||
self.state = DBusXMLParser.STATE_ARG
|
||||
arg_name = None
|
||||
if attrs.has_key('name'):
|
||||
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 attrs.has_key('name') and self.doc_comment_params.has_key(attrs['name']):
|
||||
doc_string = self.doc_comment_params[attrs['name']]
|
||||
if doc_string != None:
|
||||
self._cur_object.doc_string = doc_string
|
||||
if self.doc_comment_params.has_key('since'):
|
||||
self._cur_object.since = self.doc_comment_params['since']
|
||||
|
||||
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:
|
||||
raise RuntimeError('Unhandled state "%s" while entering element with name "%s"'%(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):
|
||||
parser = DBusXMLParser(xml_data)
|
||||
return parser.parsed_interfaces
|
104
gio/gdbus-2.0/codegen/utils.py
Normal file
104
gio/gdbus-2.0/codegen/utils.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# -*- 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 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, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import distutils.version
|
||||
|
||||
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
|
||||
for c in s:
|
||||
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 == None:
|
||||
return ''
|
||||
else:
|
||||
return s
|
||||
|
||||
def lookup_since(annotations):
|
||||
s = lookup_annotation(annotations, 'org.gtk.GDBus.Since')
|
||||
if s == None:
|
||||
return ''
|
||||
else:
|
||||
return s
|
||||
|
||||
def lookup_brief_docs(annotations):
|
||||
s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString.Short')
|
||||
if s == None:
|
||||
return ''
|
||||
else:
|
||||
return s
|
||||
|
||||
# I'm sure this could be a lot more elegant if I was
|
||||
# more fluent in python...
|
||||
def my_version_cmp(a, b):
|
||||
if len(a[0]) > 0 and len(b[0]) > 0:
|
||||
va = distutils.version.LooseVersion(a[0])
|
||||
vb = distutils.version.LooseVersion(b[0])
|
||||
ret = va.__cmp__(vb)
|
||||
else:
|
||||
ret = cmp(a[0], b[0])
|
||||
if ret != 0:
|
||||
return ret
|
||||
return cmp(a[1], b[1])
|
Reference in New Issue
Block a user