]>
pere.pagekite.me Git - text-free-culture-lessig.git/blob - scripts/verify-indexterm-range
3 # Verify the <indexterm> ranges of a docbook document, ensuring
4 # endofrange come after startofrange, and the IDs used by startofrange
11 filename
= 'freeculture.xml'
13 # make sure entities are looked up / available
15 # http://stackoverflow.com/questions/14731633/how-to-resolve-external-entities-with-xml-etree-like-lxml-etree
16 proc
= subprocess
.Popen(['xmllint','--noent',filename
],stdout
=subprocess
.PIPE
)
17 output
= proc
.communicate()[0]
18 doc
= ElementTree
.parse(StringIO
.StringIO(output
))
22 for it
in doc
.getroot().xpath('//indexterm'):
26 if 'class' in it
.attrib
:
27 indextermclass
= it
.attrib
['class']
28 if 'startofrange' == indextermclass
:
31 print "error: non-unique indexterm id: %s" % id
33 if 'endofrange' == indextermclass
:
34 id = it
.attrib
['startref']
36 print "error: indexterm id=\"%s\" not listed before endofrange" % id
37 print indextermclass
, id
39 if __name__
== "main":