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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# -*- 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 pygst
pygst.require('0.9')
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>
<source>%(source)s</source>
<package>%(package)s</package>
<origin>%(origin)s</origin>
<elements>
%(elements)s
</elements>
</plugin>"""
def xmlencode(line):
"""
Replace &, <, and >
"""
line = "&".join(line.split("&"))
line = "<".join(line.split("<"))
line = ">".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())
registry = gst.registry_get_default()
features = registry.get_feature_list_by_plugin(plugin.get_name())
gst.debug('plugin %s has %d features' % (plugin.get_name(), len(features)))
for feature in features:
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()),
'source': xmlencode(plugin.get_source()),
'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 len(sys.argv) == 1:
sys.stderr.write("Please specify a source module to inspect")
sys.exit(1)
source = sys.argv[1]
if len(sys.argv) > 2:
os.chdir(sys.argv[2])
registry = gst.registry_get_default()
all = registry.get_plugin_list()
for plugin in all:
gst.debug("inspecting plugin %s from source %s" % (
plugin.get_name(), plugin.get_source()))
# this skips gstcoreelements, with bin and pipeline
if plugin.get_filename() is None:
continue
if plugin.get_source() != source:
continue
filename = "plugin-%s.xml" % plugin.get_name()
handle = open(filename, "w")
handle.write(output_plugin(plugin))
handle.close()
main()
|