]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
Parses opencv.bib, generates bibliography section
authorjamesb <jamesb@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Thu, 25 Mar 2010 01:39:49 +0000 (01:39 +0000)
committerjamesb <jamesb@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Thu, 25 Mar 2010 01:39:49 +0000 (01:39 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@2904 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/doc/latex2sphinx/latex.py
opencv/doc/opencv.bib

index 7fd129504e342bbf6f63e1a31efe976d3e60ef90..702a88ca7b5975ba0103fe5c7982d670f5c5e1e8 100644 (file)
@@ -6,6 +6,23 @@ import cPickle as pickle
 import pyparsing as pp
 import StringIO
 from qfile import QOpen
+from string import Template
+
+# useful things for pyparsing
+def returnList(x):
+    def listify(s, loc, toks):
+        return [toks]
+    x.setParseAction(listify)
+    return x
+def returnTuple(x):
+    def listify(s, loc, toks):
+        return [tuple(toks)]
+    x.setParseAction(listify)
+    return x
+def CommaList(word):
+    return returnList(pp.Optional(word + pp.ZeroOrMore(pp.Suppress(',') + word)))
+def sl(s):
+    return pp.Suppress(pp.Literal(s))
 
 import pythonapi
 
@@ -106,7 +123,7 @@ class SphinxWriter:
         self.f_section = QOpen(os.path.join(self.language, filename + '.rst'), 'wt')
         self.f = self.f_section
         self.indent = 0
-        title = str(c.params[0])
+        title = self.render(c.params[0].str)
         print >>self, title
         print >>self, '=' * len(title)
         print >>self
@@ -247,15 +264,6 @@ class SphinxWriter:
         self.function_props['defpy'] = s
 
         pp.ParserElement.setDefaultWhitespaceChars(" \n\t")
-        def returnList(x):
-            def listify(s, loc, toks):
-                return [toks]
-            x.setParseAction(listify)
-            return x
-        def CommaList(word):
-            return returnList(pp.Optional(word + pp.ZeroOrMore(pp.Suppress(',') + word)))
-        def sl(s):
-            return pp.Suppress(pp.Literal(s))
 
         ident = pp.Word(pp.alphanums + "_.+-")
         ident_or_tuple = ident | (sl('(') + CommaList(ident) + sl(')'))
@@ -575,6 +583,7 @@ class SphinxWriter:
         for f in sorted(set(python_api) - self.covered):
             print >>self.errors, '    ', f
 
+        print >>self.f_index, "    bibliography"
         print >>self.f_index, """
 
 Indices and tables
@@ -584,6 +593,39 @@ Indices and tables
 * :ref:`search`
 """
 
+# Quick and dirty bibtex parser
+
+def parseBib(filename, language):
+    pp.ParserElement.setDefaultWhitespaceChars(" \n\t")
+    entry = returnList(pp.Word('@', pp.alphanums) + sl('{') +
+        pp.Word(pp.alphanums + "_") + sl(',') +
+        CommaList(returnTuple(pp.Word(pp.alphanums) + sl('=') + pp.QuotedString('{', endQuoteChar = '}'))) +
+        pp.Suppress(pp.Optional(',')) +
+        sl('}'))
+    r = (pp.ZeroOrMore(entry) | pp.Suppress('#' + pp.ZeroOrMore(pp.CharsNotIn('\n'))) + pp.StringEnd()).parseFile(filename)
+
+    bibliography = open(os.path.join(language, "bibliography.rst"), 'wt')
+    print >>bibliography, "Bibliography"
+    print >>bibliography, "============"
+    print >>bibliography
+
+    for _,e in sorted([(str(x[1]), x) for x in r]):
+        (etype, tag, attrs) = str(e[0][1:]), str(e[1]), dict([(str(a), str(b)) for (a,b) in e[2]])
+        
+        representations = {
+            'article' :         '$author, "$title". $journal $volume $number, $pages ($year)',
+            'inproceedings' :   '$author "$title", $booktitle, $year',
+            'misc' :            '$author "$title", $year',
+        }
+        if etype in representations:
+            if 0:
+                print >>bibliography, tag
+                print >>bibliography, "^" * len(tag)
+                print >>bibliography
+
+            print >>bibliography, ".. [%s] %s" % (tag, Template(representations[etype]).safe_substitute(attrs))
+            print >>bibliography
+
 if 1:
     sources = ['../' + f for f in os.listdir('..') if f.endswith('.tex')]
     if distutils.dep_util.newer_group(["latexparser.py"] + sources, "pickled"):
@@ -651,6 +693,7 @@ Contents:
 """ % {'c': 'C', 'cpp': 'C++', 'py': 'Python'}[language]
         sr.doL(doc)
         sr.close()
+        parseBib('../opencv.bib', language)
         tags.update(sr.get_tags())
     open('TAGS', 'w').write("\n".join(sorted(tags.values())) + "\n")
 
index 634c549d6e8f7c5d99bd7b7bee6c34eff739b071..7ded50aa6639a989e8b8ea791b3d814d7a857c8b 100644 (file)
     author = {D. Arthur and S. Vassilvitskii},
     year = {2007},
     pages = {1027--1035}
-},
+}
 
 @inproceedings{muja_flann_2009,
   author    = {Marius Muja and David G. Lowe},