~ubuntu-branches/debian/sid/transmageddon/sid

« back to all changes in this revision

Viewing changes to common/gst-xmlinspect.py

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-10-14 08:28:43 UTC
  • Revision ID: james.westby@ubuntu.com-20091014082843-uxbyrcqydc13zrim
Tags: upstream-0.14
ImportĀ upstreamĀ versionĀ 0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python -*-
 
2
# vi:si:et:sw=4:sts=4:ts=4
 
3
 
 
4
"""
 
5
examine all plugins and elements and output xml documentation for them
 
6
used as part of the plugin documentation build
 
7
"""
 
8
 
 
9
import sys
 
10
import os
 
11
import pygst
 
12
pygst.require('0.10')
 
13
import gst
 
14
 
 
15
INDENT_SIZE = 2
 
16
 
 
17
# all templates
 
18
 
 
19
PAD_TEMPLATE = """<caps>
 
20
  <name>%(name)s</name>
 
21
  <direction>%(direction)s</direction>
 
22
  <presence>%(presence)s</presence>
 
23
  <details>%(details)s</details>
 
24
</caps>"""
 
25
 
 
26
ELEMENT_TEMPLATE = """<element>
 
27
  <name>%(name)s</name>
 
28
  <longname>%(longname)s</longname>
 
29
  <class>%(class)s</class>
 
30
  <description>%(description)s</description>
 
31
  <author>%(author)s</author>
 
32
  <pads>
 
33
%(pads)s
 
34
  </pads>
 
35
</element>"""
 
36
 
 
37
PLUGIN_TEMPLATE = """<plugin>
 
38
  <name>%(name)s</name>
 
39
  <description>%(description)s</description>
 
40
  <filename>%(filename)s</filename>
 
41
  <basename>%(basename)s</basename>
 
42
  <version>%(version)s</version>
 
43
  <license>%(license)s</license>
 
44
  <source>%(source)s</source>
 
45
  <package>%(package)s</package>
 
46
  <origin>%(origin)s</origin>
 
47
  <elements>
 
48
%(elements)s
 
49
  </elements>
 
50
</plugin>"""
 
51
 
 
52
def xmlencode(line):
 
53
    """
 
54
    Replace &, <, and >
 
55
    """
 
56
    line = "&amp;".join(line.split("&"))
 
57
    line = "&lt;".join(line.split("<"))
 
58
    line = "&gt;".join(line.split(">"))
 
59
    return line
 
60
 
 
61
def get_offset(indent):
 
62
    return " " * INDENT_SIZE * indent
 
63
 
 
64
def output_pad_template(pt, indent=0):
 
65
    print  "PAD TEMPLATE", pt.name_template
 
66
    paddir = ("unknown","source","sink")
 
67
    padpres = ("always","sometimes","request")
 
68
    
 
69
    d = {
 
70
      'name':        xmlencode(pt.name_template),
 
71
      'direction':   xmlencode(paddir[pt.direction]),
 
72
      'presence':    xmlencode(padpres[pt.presence]),
 
73
      'details':     xmlencode(pt.static_caps.string),
 
74
    }
 
75
    block = PAD_TEMPLATE % d
 
76
 
 
77
    offset = get_offset(indent)
 
78
    return offset + ("\n" + offset).join(block.split("\n"))
 
79
    
 
80
def output_element_factory(elf, indent=0):
 
81
    print  "ELEMENT", elf.get_name()
 
82
 
 
83
    padsoutput = []
 
84
    padtemplates = elf.get_static_pad_templates()
 
85
    for padtemplate in padtemplates:
 
86
        padsoutput.append(output_pad_template(padtemplate, indent))
 
87
 
 
88
    d = {
 
89
        'name':        xmlencode(elf.get_name()),
 
90
        'longname':    xmlencode(elf.get_longname()),
 
91
        'class':       xmlencode(elf.get_klass()),
 
92
        'description': xmlencode(elf.get_description()),
 
93
        'author':      xmlencode(elf.get_author()),
 
94
        'pads': "\n".join(padsoutput),
 
95
    }
 
96
    block = ELEMENT_TEMPLATE % d
 
97
 
 
98
    offset = get_offset(indent)
 
99
    return offset + ("\n" + offset).join(block.split("\n"))
 
100
 
 
101
def output_plugin(plugin, indent=0):
 
102
    print "PLUGIN", plugin.get_name()
 
103
    version = plugin.get_version()
 
104
    
 
105
    elements = {}
 
106
    gst.debug('getting features for plugin %s' % plugin.get_name())
 
107
    registry = gst.registry_get_default()
 
108
    features = registry.get_feature_list_by_plugin(plugin.get_name())
 
109
    gst.debug('plugin %s has %d features' % (plugin.get_name(), len(features)))
 
110
    for feature in features:
 
111
        if isinstance(feature, gst.ElementFactory):
 
112
            elements[feature.get_name()] = feature
 
113
    #gst.debug("got features")
 
114
        
 
115
    elementsoutput = []
 
116
    keys = elements.keys()
 
117
    keys.sort()
 
118
    for name in keys:
 
119
        feature = elements[name]
 
120
        elementsoutput.append(output_element_factory(feature, indent + 2))
 
121
 
 
122
    filename = plugin.get_filename()
 
123
    basename = filename
 
124
    if basename:
 
125
        basename = os.path.basename(basename)
 
126
    d = {
 
127
        'name':        xmlencode(plugin.get_name()),
 
128
        'description': xmlencode(plugin.get_description()),
 
129
        'filename':    filename,
 
130
        'basename':    basename,
 
131
        'version':     version,
 
132
        'license':     xmlencode(plugin.get_license()),
 
133
        'source':      xmlencode(plugin.get_source()),
 
134
        'package':     xmlencode(plugin.get_package()),
 
135
        'origin':      xmlencode(plugin.get_origin()),
 
136
        'elements': "\n".join(elementsoutput),
 
137
    }
 
138
    block = PLUGIN_TEMPLATE % d
 
139
    
 
140
    offset = get_offset(indent)
 
141
    return offset + ("\n" + offset).join(block.split("\n"))
 
142
 
 
143
def main():
 
144
    if len(sys.argv) == 1:
 
145
        sys.stderr.write("Please specify a source module to inspect")
 
146
        sys.exit(1)
 
147
    source = sys.argv[1]
 
148
 
 
149
    if len(sys.argv) > 2:
 
150
        os.chdir(sys.argv[2])
 
151
 
 
152
    registry = gst.registry_get_default()
 
153
    all = registry.get_plugin_list()
 
154
    for plugin in all:
 
155
        gst.debug("inspecting plugin %s from source %s" % (
 
156
            plugin.get_name(), plugin.get_source()))
 
157
        # this skips gstcoreelements, with bin and pipeline
 
158
        if plugin.get_filename() is None:
 
159
            continue
 
160
        if plugin.get_source() != source:
 
161
            continue
 
162
 
 
163
        filename = "plugin-%s.xml" % plugin.get_name()
 
164
        handle = open(filename, "w")
 
165
        handle.write(output_plugin(plugin))
 
166
        handle.close()
 
167
 
 
168
main()