Bopytex/DS_gene.py

73 lines
2.2 KiB
Python
Raw Normal View History

2013-09-27 18:09:38 +00:00
#!/usr/bin/env python
# encoding: utf-8
import jinja2, random, os
2013-09-27 20:21:46 +00:00
import sys
import optparse
2014-08-29 13:29:57 +00:00
from path import path
from pymath.random_expression import RdExpression
texenv = jinja2.Environment(
block_start_string = '\Block{',
# Gros WTF!! Si on le met en maj ça ne marche pas alors que c'est en maj dans le template...
block_end_string = '}',
variable_start_string = '\Var{',
variable_end_string = '}',
loader = jinja2.FileSystemLoader(os.path.abspath('.'))
2013-09-27 20:21:46 +00:00
)
def main(options):
#template = report_renderer.get_template(options.template)
template = texenv.get_template(options.template)
2013-09-27 20:21:46 +00:00
2014-08-29 13:29:57 +00:00
# Saving place
cwd = path("./").abspath()
template_file = path(options.template)
2014-01-19 20:37:46 +00:00
2013-09-27 20:21:46 +00:00
if options.output:
2014-08-29 13:29:57 +00:00
output = path(options.output)
2013-09-27 20:21:46 +00:00
else:
2014-08-29 13:29:57 +00:00
# Template should be named tpl_... tpl will replace by the number/name of the version
output = path(template_file.dirname()) / path(template_file.name[3:])
if output.dirname != "":
output.dirname().cd()
output = output.name
2013-09-27 20:21:46 +00:00
for subj in range(options.num_subj):
subj = subj+1
2014-08-29 13:29:57 +00:00
dest = path(str(subj) + output)
2013-09-27 20:21:46 +00:00
with open( dest, 'w') as f:
2014-08-29 13:29:57 +00:00
f.write(template.render( RdExpression = RdExpression , infos = {"subj" : subj}))
#os.system("pdflatex " + dest)
2013-10-18 11:48:43 +00:00
#if not options.dirty:
# os.system("rm *.aux *.log")
2013-09-27 20:21:46 +00:00
2014-08-29 13:29:57 +00:00
cwd.cd()
2014-01-19 20:37:46 +00:00
2013-09-27 20:21:46 +00:00
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option("-t","--tempalte",action="store",type="string",dest="template", help="File with template")
2014-08-29 13:29:57 +00:00
parser.add_option("-o","--output",action="store",type="string",dest="output",help="Base name for output )")
parser.add_option("-n","--number_subjects", action="store",type="int", dest="num_subj", default = 1, help="The number of subjects to make")
2013-10-18 11:48:43 +00:00
parser.add_option("-d","--dirty", action="store_true", dest="dirty", help="Do not clean after compilation")
2013-09-27 20:21:46 +00:00
(options, args) = parser.parse_args()
if not options.template:
print("I need a template!")
sys.exit(0)
main(options)
2013-09-27 18:09:38 +00:00
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del