2 # vi:si:et:sw=4:sts=4:ts=4
5 use the output from gst-xmlinspect.py to mangle tmpl/*.sgml and
6 insert/overwrite Short Description and Long Description
19 def __init__(self, filename):
20 self.filename = filename
26 Read and parse the sections from the given file.
28 lines = open(self.filename).readlines()
29 matcher = re.compile("<!-- ##### SECTION (\S+) ##### -->\n")
33 match = matcher.search(line)
35 id = match.expand("\\1")
36 self._sectionids.append(id)
37 self._sections[id] = []
41 "WARNING: line before a SECTION header: %s" % line)
43 self._sections[id].append(line)
45 def get_section(self, id):
47 Get the content from the given section.
49 return self._sections[id]
51 def set_section(self, id, content):
53 Replace the given section id with the given content.
55 self._sections[id] = content
59 Return the output of the current template in the tmpl/*.sgml format.
62 for id in self._sectionids:
63 lines.append("<!-- ##### SECTION %s ##### -->\n" % id)
64 for line in self._sections[id]:
69 def write(self, backup=False):
71 Write out the template file again, backing up the previous one.
74 target = self.filename + ".mangle.bak"
75 os.rename(self.filename, target)
77 handle = open(self.filename, "w")
78 handle.write(self.output())
82 if len(sys.argv) > 1 and sys.argv[1]:
86 all = gst.registry_pool_plugin_list()
88 for feature in plugin.get_feature_list():
89 if isinstance(feature, gst.ElementFactory):
90 elements[feature.get_name()] = feature
92 for file in glob.glob("element-*.sgml"):
93 base = os.path.basename(file)
94 element = base[len("element-"):-len(".sgml")]
97 if element in elements.keys():
98 feature = elements[element]
99 description = feature.get_description()
100 tmpl.set_section("Short_Description", "%s\n\n" % description)
102 # put in an include if not yet there
103 line = '<include xmlns="http://www.w3.org/2003/XInclude" href="' + \
104 'element-' + element + '-details.xml" />\n'
105 section = tmpl.get_section("Long_Description")
106 if not section[0] == line:
107 section.insert(0, line)
108 tmpl.set_section("Long_Description", section)