| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# This file generate the inheritance graphs (.dot and .pdf file) from the .bib file examples. |
| 4 |
# To do it, its create temporary .tex file, calling a specific .bib file (as https://github.com/plk/biber/issues/110 was rejected). |
| 5 |
# It is licensed on GPL 3 licenses. |
| 6 |
# https://www.gnu.org/licenses/gpl-3.0.fr.html |
| 7 |
# Copyright : Maïeul Rouquette 2016-… |
| 8 |
|
| 9 |
import os |
| 10 |
|
| 11 |
|
| 12 |
# specific preamble for some file |
| 13 |
specific_preamble = { |
| 14 |
"example-bookineditor-BookineditorFromEditor":"\\toggletrue{BookineditorFromEditor}\n" |
| 15 |
} |
| 16 |
|
| 17 |
#List all the files on the current directory |
| 18 |
directory_files = os.listdir(".") |
| 19 |
|
| 20 |
|
| 21 |
#Loop on them, and for the .bib file, generate the .tex, .dot and .pdf file |
| 22 |
for file_name in directory_files: |
| 23 |
basename, ext = os.path.splitext(file_name) |
| 24 |
|
| 25 |
if ext != '.bib':#only the .bib file |
| 26 |
continue |
| 27 |
|
| 28 |
# write the .tex file content |
| 29 |
tex_file_name = basename + ".tex" |
| 30 |
tex_file_content = "\documentclass{article}\n\ |
| 31 |
\\usepackage[bibstyle=morenames]{biblatex}\n" |
| 32 |
|
| 33 |
if basename in specific_preamble: |
| 34 |
tex_file_content = tex_file_content + specific_preamble[basename] |
| 35 |
|
| 36 |
tex_file_content = tex_file_content + "\\bibliography{" + file_name + "}\n\ |
| 37 |
\\begin{document}\n\ |
| 38 |
\\nocite{*}\n\ |
| 39 |
\end{document}" |
| 40 |
tex_file_file = open(tex_file_name, "w") |
| 41 |
tex_file_file.write(tex_file_content) |
| 42 |
tex_file_file.close() |
| 43 |
|
| 44 |
# generate the .bcf, .dot and .pdf file |
| 45 |
os.system("pdflatex " + basename) |
| 46 |
os.system("biber -output-format=dot --dot-include=crossref,field " + basename) |
| 47 |
os.system("dot -Tpdf " + basename + ".dot " + "-o " + basename + ".pdf") |
| 48 |
|
| 49 |
# delete the temporary files, to avoid distributing it and to have cleaner folder |
| 50 |
for ext in ["aux","bcf","blg","log","run.xml","tex"]: |
| 51 |
os.remove(basename+"."+ext) |