diff options
author | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-04-16 10:29:56 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-04-16 11:04:04 +0200 |
commit | 5fb85e5dd77c245bbd1169f006f58c9811e8cf76 (patch) | |
tree | 24b6fb416eca74a30045f1a2f3aba767910c0531 | |
parent | 3e6038ea5f23d4fd22d42f5561092d4dc17d387f (diff) |
Script per generare html, pdf e odt degli esempi
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | build.py | 88 |
2 files changed, 90 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bbbf928 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +*.swp diff --git a/build.py b/build.py new file mode 100644 index 0000000..5c6ffd6 --- /dev/null +++ b/build.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python + +import argparse +import os +import shutil +import subprocess + +from docutils.core import publish_file + +def build_html(srcdir,destdir): + if not os.path.isdir(destdir): + os.makedirs(destdir) + + for fname in os.listdir(srcdir): + (basename,ext) = os.path.splitext(fname) + if ext == '.rst': + publish_file(source_path=os.path.join(srcdir,fname), + destination_path=os.path.join(destdir,basename+'.html'), + writer_name="html") + else: + shutil.copy(os.path.join(srcdir,fname),os.path.join(destdir,fname)) + +def build_latex(srcdir,destdir): + if not os.path.isdir(destdir): + os.makedirs(destdir) + + for fname in os.listdir(srcdir): + (basename,ext) = os.path.splitext(fname) + if ext == '.rst': + publish_file(source_path=os.path.join(srcdir,fname), + destination_path=os.path.join(destdir,basename+'.tex'), + writer_name="xetex", + settings_overrides={'stylesheet':'amssymb'}) + #elif ext == '.svg': + # subprocess.call(['inkscape','--export-pdf', + # os.path.join(destdir,basename+'pdf'), + # os.path.join(srcdir,fname)]) + else: + shutil.copy(os.path.join(srcdir,fname),os.path.join(destdir,fname)) + +def build_pdf(latexdir,destdir): + if not os.path.isdir(destdir): + os.makedirs(destdir) + + destdir = os.path.abspath(destdir) + + os.chdir(latexdir) + for fname in os.listdir('.'): + (basename,ext) = os.path.splitext(fname) + if ext == '.tex': + if subprocess.call(['xelatex',fname]) == 0: + subprocess.call(['xelatex',fname]) + subprocess.call(['xelatex',fname]) + shutil.copy(basename+'.pdf',destdir) + +def build_odt(srcdir,destdir): + if not os.path.isdir(destdir): + os.makedirs(destdir) + + for fname in os.listdir(srcdir): + (basename,ext) = os.path.splitext(fname) + if ext == '.rst': + try: + publish_file(source_path=os.path.join(srcdir,fname), + destination_path=os.path.join(destdir,basename+'.odt'), + writer_name="odf_odt") + except IOError: # allow it to die on PIL issues + pass + +def main(): + parser = argparse.ArgumentParser(description='building script') + parser.add_argument('-H','--html',action='store_true') + parser.add_argument('-l','--latex',action='store_true') + parser.add_argument('-p','--pdf',action='store_true') + parser.add_argument('-o','--odt',action='store_true') + args = parser.parse_args() + + if args.html: + build_html('esempi',os.path.join('build','html','esempi')) + if args.latex or args.pdf: + build_latex('esempi',os.path.join('build','latex','esempi')) + if args.pdf: + build_pdf(os.path.join('build','latex','esempi'), + os.path.join('build','pdf','esempi')) + if args.odt: + build_odt('esempi',os.path.join('build','odt','esempi')) + +if __name__ == '__main__': main() |