23 lines
1.2 KiB
Python
23 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Derive Qt-only marshalling annotations without changing the wire contract."""
|
|
import sys
|
|
import xml.etree.ElementTree as ET
|
|
|
|
tree = ET.parse(sys.argv[1])
|
|
types = {'a{sv}': 'QVariantMap', 'aa{sv}': 'QList<QVariantMap>'}
|
|
for interface in tree.iter('interface'):
|
|
for member in interface:
|
|
if member.tag == 'property' and member.get('type') in types:
|
|
name = 'org.qtproject.QtDBus.QtTypeName'
|
|
if not any(a.get('name') == name for a in member.findall('annotation')):
|
|
ET.SubElement(member, 'annotation', name=name, value=types[member.get('type')])
|
|
if member.tag not in ('method', 'signal'):
|
|
continue
|
|
indices = {'in': 0, 'out': 0}
|
|
for arg in member.findall('arg'):
|
|
direction = arg.get('direction', 'out' if member.tag == 'signal' else 'in')
|
|
name = f'org.qtproject.QtDBus.QtTypeName.{direction.title()}{indices[direction]}'
|
|
indices[direction] += 1
|
|
if arg.get('type') in types and not any(a.get('name') == name for a in member.findall('annotation')):
|
|
ET.SubElement(member, 'annotation', name=name, value=types[arg.get('type')])
|
|
tree.write(sys.argv[2], encoding='utf-8', xml_declaration=True)
|