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
9 # FIXME: right now it uses pygst and scans on its own;
10 # we really should use inspect/*.xml instead since the result of
11 # gst-xmlinspect.py is commited by the docs maintainer, who can be
12 # expected to have pygst, but this step should be done for every docs build,
15 # read in inspect/*.xml
16 # for every tmpl/element-(name).xml: mangle with details from element
24 def __init__(self, filename):
25 self.filename = filename
31 Read and parse the sections from the given file.
33 lines = open(self.filename).readlines()
34 matcher = re.compile("<!-- ##### SECTION (\S+) ##### -->\n")
38 match = matcher.search(line)
40 id = match.expand("\\1")
41 self._sectionids.append(id)
42 self._sections[id] = []
46 "WARNING: line before a SECTION header: %s" % line)
48 self._sections[id].append(line)
50 def get_section(self, id):
52 Get the content from the given section.
54 return self._sections[id]
56 def set_section(self, id, content):
58 Replace the given section id with the given content.
60 self._sections[id] = content
64 Return the output of the current template in the tmpl/*.sgml format.
67 for id in self._sectionids:
68 lines.append("<!-- ##### SECTION %s ##### -->\n" % id)
69 for line in self._sections[id]:
74 def write(self, backup=False):
76 Write out the template file again, backing up the previous one.
79 target = self.filename + ".mangle.bak"
80 os.rename(self.filename, target)
82 handle = open(self.filename, "w")
83 handle.write(self.output())
86 import xml.dom.minidom
88 def get_elements(file):
90 doc = xml.dom.minidom.parse(file)
93 for e in doc.childNodes:
94 if e.nodeType == e.ELEMENT_NODE and e.localName == 'plugin':
101 for e in elem.childNodes:
102 if e.nodeType == e.ELEMENT_NODE and e.localName == 'elements':
110 for e in elem.childNodes:
111 if e.nodeType == e.ELEMENT_NODE and e.localName == 'element':
115 for e2 in e.childNodes:
116 if e2.nodeType == e2.ELEMENT_NODE and e2.localName == 'name':
117 name = e2.childNodes[0].nodeValue.encode("UTF-8")
118 elif e2.nodeType == e2.ELEMENT_NODE and e2.localName == 'description':
120 description = e2.childNodes[0].nodeValue.encode("UTF-8")
122 description = 'No description'
124 if name != None and description != None:
125 elements[name] = {'description': description}
130 if not len(sys.argv) == 3:
131 sys.stderr.write('Please specify the inspect/ dir and the tmpl/ dir')
134 inspectdir = sys.argv[1]
135 tmpldir = sys.argv[2]
137 # parse all .xml files; build map of element name -> short desc
138 #for file in glob.glob("inspect/plugin-*.xml"):
140 for file in glob.glob("%s/plugin-*.xml" % inspectdir):
141 elements.update(get_elements(file))
143 for file in glob.glob("%s/element-*.sgml" % tmpldir):
144 base = os.path.basename(file)
145 element = base[len("element-"):-len(".sgml")]
148 if element in elements.keys():
149 description = elements[element]['description']
150 tmpl.set_section("Short_Description", "%s\n\n" % description)
152 # put in an include if not yet there
153 line = '<include xmlns="http://www.w3.org/2003/XInclude" href="' + \
154 'element-' + element + '-details.xml">' + \
155 '<fallback xmlns="http://www.w3.org/2003/XInclude" />' + \
157 section = tmpl.get_section("Long_Description")
158 if not section[0] == line:
159 section.insert(0, line)
160 tmpl.set_section("Long_Description", section)