~ubuntu-branches/ubuntu/trusty/pitivi/trusty

« back to all changes in this revision

Viewing changes to common/gst-xmlinspect.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-02-04 14:42:30 UTC
  • Revision ID: james.westby@ubuntu.com-20060204144230-9ihvyas6lhgn81k1
Tags: upstream-0.9.9.2
ImportĀ upstreamĀ versionĀ 0.9.9.2

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
ELEMENT_TEMPLATE = """<element>
 
19
  <name>%(name)s</name>
 
20
  <longname>%(longname)s</longname>
 
21
  <class>%(class)s</class>
 
22
  <description>%(description)s</description>
 
23
  <author>%(author)s</author>
 
24
</element>"""
 
25
 
 
26
PLUGIN_TEMPLATE = """<plugin>
 
27
  <name>%(name)s</name>
 
28
  <description>%(description)s</description>
 
29
  <filename>%(filename)s</filename>
 
30
  <basename>%(basename)s</basename>
 
31
  <version>%(version)s</version>
 
32
  <license>%(license)s</license>
 
33
  <source>%(source)s</source>
 
34
  <package>%(package)s</package>
 
35
  <origin>%(origin)s</origin>
 
36
  <elements>
 
37
%(elements)s
 
38
  </elements>
 
39
</plugin>"""
 
40
 
 
41
def xmlencode(line):
 
42
    """
 
43
    Replace &, <, and >
 
44
    """
 
45
    line = "&amp;".join(line.split("&"))
 
46
    line = "&lt;".join(line.split("<"))
 
47
    line = "&gt;".join(line.split(">"))
 
48
    return line
 
49
 
 
50
def get_offset(indent):
 
51
    return " " * INDENT_SIZE * indent
 
52
 
 
53
def output_element_factory(elf, indent=0):
 
54
    print  "ELEMENT", elf.get_name()
 
55
    d = {
 
56
        'name':        xmlencode(elf.get_name()),
 
57
        'longname':    xmlencode(elf.get_longname()),
 
58
        'class':       xmlencode(elf.get_klass()),
 
59
        'description': xmlencode(elf.get_description()),
 
60
        'author':      xmlencode(elf.get_author()),
 
61
    }
 
62
    block = ELEMENT_TEMPLATE % d
 
63
    
 
64
    offset = get_offset(indent)
 
65
    return offset + ("\n" + offset).join(block.split("\n"))
 
66
 
 
67
def output_plugin(plugin, indent=0):
 
68
    print "PLUGIN", plugin.get_name()
 
69
    version = plugin.get_version()
 
70
    
 
71
    elements = {}
 
72
    gst.debug('getting features for plugin %s' % plugin.get_name())
 
73
    registry = gst.registry_get_default()
 
74
    features = registry.get_feature_list_by_plugin(plugin.get_name())
 
75
    gst.debug('plugin %s has %d features' % (plugin.get_name(), len(features)))
 
76
    for feature in features:
 
77
        if isinstance(feature, gst.ElementFactory):
 
78
            elements[feature.get_name()] = feature
 
79
    #gst.debug("got features")
 
80
        
 
81
    elementsoutput = []
 
82
    keys = elements.keys()
 
83
    keys.sort()
 
84
    for name in keys:
 
85
        feature = elements[name]
 
86
        elementsoutput.append(output_element_factory(feature, indent + 2))
 
87
 
 
88
    filename = plugin.get_filename()
 
89
    basename = filename
 
90
    if basename:
 
91
        basename = os.path.basename(basename)
 
92
    d = {
 
93
        'name':        xmlencode(plugin.get_name()),
 
94
        'description': xmlencode(plugin.get_description()),
 
95
        'filename':    filename,
 
96
        'basename':    basename,
 
97
        'version':     version,
 
98
        'license':     xmlencode(plugin.get_license()),
 
99
        'source':      xmlencode(plugin.get_source()),
 
100
        'package':     xmlencode(plugin.get_package()),
 
101
        'origin':      xmlencode(plugin.get_origin()),
 
102
        'elements': "\n".join(elementsoutput),
 
103
    }
 
104
    block = PLUGIN_TEMPLATE % d
 
105
    
 
106
    offset = get_offset(indent)
 
107
    return offset + ("\n" + offset).join(block.split("\n"))
 
108
 
 
109
def main():
 
110
    if len(sys.argv) == 1:
 
111
        sys.stderr.write("Please specify a source module to inspect")
 
112
        sys.exit(1)
 
113
    source = sys.argv[1]
 
114
 
 
115
    if len(sys.argv) > 2:
 
116
        os.chdir(sys.argv[2])
 
117
 
 
118
    registry = gst.registry_get_default()
 
119
    all = registry.get_plugin_list()
 
120
    for plugin in all:
 
121
        gst.debug("inspecting plugin %s from source %s" % (
 
122
            plugin.get_name(), plugin.get_source()))
 
123
        # this skips gstcoreelements, with bin and pipeline
 
124
        if plugin.get_filename() is None:
 
125
            continue
 
126
        if plugin.get_source() != source:
 
127
            continue
 
128
 
 
129
        filename = "plugin-%s.xml" % plugin.get_name()
 
130
        handle = open(filename, "w")
 
131
        handle.write(output_plugin(plugin))
 
132
        handle.close()
 
133
 
 
134
main()