blob: 9152a005490c2564d96b103421f965ee9a759e22 [file] [log] [blame]
# Copyright (c) 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Process wayland specifications.
Various functions for converting/processing/understanding wayland protocols.
"""
from __future__ import absolute_import
import argparse
import sys
import xml.etree.ElementTree as xml
import gv_diagram
def strip_protocol(protocol):
for desc in protocol.findall('description'):
protocol.remove(desc)
for copy in protocol.findall('copyright'):
protocol.remove(copy)
if 'summary' in protocol.attrib:
protocol.attrib.pop('summary')
for c in protocol.getchildren():
strip_protocol(c)
return protocol
def dump_protocol(protocol):
xml.dump(protocol)
def read_protocol(path):
return xml.parse(path).getroot()
def main(argv):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-s', '--spec',
help='path(s) to the wayland specification(s)',
nargs='+', required=True)
parser.add_argument('-t', '--type',
help='Output different types of graph',
choices=['interfaces', 'deps'], required=True)
parser.add_argument('-x', '--extra',
help='add extra detail to the normal printout',
action='store_true')
parsed = parser.parse_args(argv[1:])
protocols = [strip_protocol(read_protocol(path)) for path in parsed.spec]
extra = parsed.extra
if parsed.type == 'deps':
drawer = gv_diagram.DepsPrinter(extra)
else:
drawer = gv_diagram.InterfacesPrinter(extra)
drawer.draw(protocols)
if __name__ == '__main__':
main(sys.argv)