From: Thomas Vander Stichele Date: Mon, 15 Aug 2005 16:14:38 +0000 (+0000) Subject: adding a script to mangle tmpl/*.sgml and insert short/long descs for elements X-Git-Tag: RELEASE-0_8_11~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28e778474e1d40dfb47bbcec0db31dfb9b90db37;p=platform%2Fupstream%2Fgst-common.git adding a script to mangle tmpl/*.sgml and insert short/long descs for elements Original commit message from CVS: adding a script to mangle tmpl/*.sgml and insert short/long descs for elements --- diff --git a/Makefile.am b/Makefile.am index 3b6adf6..656a7aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/gtk-doc-plugins.mak b/gtk-doc-plugins.mak index a483605..abb077e 100644 --- a/gtk-doc-plugins.mak +++ b/gtk-doc-plugins.mak @@ -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 index 0000000..916f214 --- /dev/null +++ b/mangle-tmpl.py @@ -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("\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("\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", + '\n\n\n\n') + tmpl.write() + +main()