adding a script to mangle tmpl/*.sgml and insert short/long descs for elements
authorThomas Vander Stichele <thomas@apestaart.org>
Mon, 15 Aug 2005 16:14:38 +0000 (16:14 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Mon, 15 Aug 2005 16:14:38 +0000 (16:14 +0000)
Original commit message from CVS:
adding a script to mangle tmpl/*.sgml and insert short/long descs for elements

Makefile.am
gtk-doc-plugins.mak
mangle-tmpl.py [new file with mode: 0644]

index 3b6adf6..656a7aa 100644 (file)
@@ -1,3 +1,9 @@
 SUBDIRS = m4
 
-EXTRA_DIST = ChangeLog gettext.patch glib-gen.mak gtk-doc.mak release.mak gst-autogen.sh gstdoc-scangobj
+EXTRA_DIST = \
+       ChangeLog \
+       gettext.patch \
+       glib-gen.mak gtk-doc.mak release.mak \
+       gst-autogen.sh \
+       gst-xmlinspect.py mangle-tmpl.py gtk-doc-plugins.mak \
+       plugins.xsl gstdoc-scangobj
index a483605..abb077e 100644 (file)
@@ -116,6 +116,8 @@ inspect:
 inspect-build.stamp: inspect
        $(INSPECT_ENVIRONMENT) $(PYTHON) \
                $(top_srcdir)/common/gst-xmlinspect.py inspect
+       $(INSPECT_ENVIRONMENT) $(PYTHON) \
+               $(top_srcdir)/common/mangle-tmpl.py tmpl
        echo -n "timestamp" > inspect.stamp
        touch inspect-build.stamp
 
diff --git a/mangle-tmpl.py b/mangle-tmpl.py
new file mode 100644 (file)
index 0000000..916f214
--- /dev/null
@@ -0,0 +1,96 @@
+# -*- Mode: Python -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+"""
+use the output from gst-xmlinspect.py to mangle tmpl/*.sgml and
+insert/overwrite Short Description and Long Description
+"""
+
+import glob
+import re
+import sys
+import os
+import gst
+
+class Tmpl:
+    def __init__(self, filename):
+        self.filename = filename
+        self._sectionids = []
+        self._sections = {}
+
+    def read(self):
+        """
+        Read and parse the sections from the given file.
+        """
+        lines = open(self.filename).readlines()
+        matcher = re.compile("<!-- ##### SECTION (\S+) ##### -->\n")
+        id = None
+
+        for line in lines:
+            match = matcher.search(line)
+            if match:
+                id = match.expand("\\1")
+                self._sectionids.append(id)
+                self._sections[id] = []
+            else:
+                if not id:
+                    sys.stderr.write(
+                        "WARNING: line before a SECTION header: %s" % line)
+                else:
+                    self._sections[id].append(line)
+
+    def set_section(self, id, content):
+        """
+        Replace the given section id with the given content.
+        """
+        self._sections[id] = content
+
+    def output(self):
+        """
+        Return the output of the current template in the tmpl/*.sgml format.
+        """
+        lines = []
+        for id in self._sectionids:
+            lines.append("<!-- ##### SECTION %s ##### -->\n" % id)
+            for line in self._sections[id]:
+                lines.append(line)
+
+        return "".join(lines)
+
+    def write(self):
+        """
+        Write out the template file again, backing up the previous one.
+        """
+        target = self.filename + ".mangle.bak"
+        os.rename(self.filename, target)
+        handle = open(self.filename, "w")
+        handle.write(self.output())
+        handle.close()
+
+        
+def main():
+    if len(sys.argv) > 1 and sys.argv[1]:
+        os.chdir(sys.argv[1])
+
+    elements = {}
+    all = gst.registry_pool_plugin_list()
+    for plugin in all:
+        for feature in plugin.get_feature_list():
+            if isinstance(feature, gst.ElementFactory):
+                elements[feature.get_name()] = feature
+                
+    for file in glob.glob("element-*.sgml"):
+        base = os.path.basename(file)
+        element = base[len("element-"):-len(".sgml")]
+        tmpl = Tmpl(file)
+        tmpl.read()
+        if element in elements.keys():
+            feature = elements[element]
+            description = feature.get_description()
+            tmpl.set_section("Short_Description", "%s\n\n" % description)
+        tmpl.set_section("Long_Description",
+            '<include xmlns="http://www.w3.org/2003/XInclude" href="element-' +
+            element + '-details.xml" />\n<para>\n\n</para>\n')
+        tmpl.write()
+
+main()