summaryrefslogtreecommitdiff
path: root/gst-xmlinspect.py
blob: c835980e5b0afed862aa0dc01efc8eb472d707ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

"""
examine all plugins and elements and output xml documentation for them
used as part of the plugin documentation build
"""

import sys
import os
import gst

INDENT_SIZE = 2

# all templates
ELEMENT_TEMPLATE = """<element>
  <name>%(name)s</name>
  <longname>%(longname)s</longname>
  <class>%(class)s</class>
  <description>%(description)s</description>
  <author>%(author)s</author>
</element>"""

PLUGIN_TEMPLATE = """<plugin>
  <name>%(name)s</name>
  <description>%(description)s</description>
  <filename>%(filename)s</filename>
  <basename>%(basename)s</basename>
  <version>%(version)s</version>
  <license>%(license)s</license>
  <package>%(package)s</package>
  <origin>%(origin)s</origin>
  <elements>
%(elements)s
  </elements>
</plugin>"""

def xmlencode(line):
    """
    Replace &, <, and >
    """
    line = "&amp;".join(line.split("&"))
    line = "&lt;".join(line.split("<"))
    line = "&gt;".join(line.split(">"))
    return line

def get_offset(indent):
    return " " * INDENT_SIZE * indent

def output_element_factory(elf, indent=0):
    print  "ELEMENT", elf.get_name()
    d = {
        'name':        xmlencode(elf.get_name()),
        'longname':    xmlencode(elf.get_longname()),
        'class':       xmlencode(elf.get_klass()),
        'description': xmlencode(elf.get_description()),
        'author':      xmlencode(elf.get_author()),
    }
    block = ELEMENT_TEMPLATE % d
    
    offset = get_offset(indent)
    return offset + ("\n" + offset).join(block.split("\n"))

def output_plugin(plugin, indent=0):
    print "PLUGIN", plugin.get_name()
    version = plugin.get_version()
    
    elements = {}
    gst.debug('getting features for plugin %s' % plugin.get_name())
    for feature in plugin.get_feature_list():
        if isinstance(feature, gst.ElementFactory):
            elements[feature.get_name()] = feature
    gst.debug("got features")
        
    elementsoutput = []
    keys = elements.keys()
    keys.sort()
    for name in keys:
        feature = elements[name]
        elementsoutput.append(output_element_factory(feature, indent + 2))

    filename = plugin.get_filename()
    basename = filename
    if basename:
        basename = os.path.basename(basename)
    d = {
        'name':        xmlencode(plugin.get_name()),
        'description': xmlencode(plugin.get_description()),
        'filename':    filename,
        'basename':    basename,
        'version':     version,
        'license':     xmlencode(plugin.get_license()),
        'package':     xmlencode(plugin.get_package()),
        'origin':      xmlencode(plugin.get_origin()),
        'elements': "\n".join(elementsoutput),
    }
    block = PLUGIN_TEMPLATE % d
    
    offset = get_offset(indent)
    return offset + ("\n" + offset).join(block.split("\n"))

def main():
    if sys.argv[1]:
        os.chdir(sys.argv[1])

    all = gst.registry_pool_plugin_list()
    for plugin in all:
        filename = "plugin-%s.xml" % plugin.get_name()
        handle = open(filename, "w")
        handle.write(output_plugin(plugin))
        handle.close()

main()