Use path.py for path manipulations
This commit is contained in:
parent
69b28b773d
commit
b4486c91a3
33
DS_gene.py
33
DS_gene.py
@ -4,6 +4,7 @@
|
|||||||
import jinja2, random, os
|
import jinja2, random, os
|
||||||
import sys
|
import sys
|
||||||
import optparse
|
import optparse
|
||||||
|
from path import path
|
||||||
from pymath.random_expression import RdExpression
|
from pymath.random_expression import RdExpression
|
||||||
|
|
||||||
texenv = jinja2.Environment(
|
texenv = jinja2.Environment(
|
||||||
@ -19,40 +20,42 @@ def main(options):
|
|||||||
#template = report_renderer.get_template(options.template)
|
#template = report_renderer.get_template(options.template)
|
||||||
template = texenv.get_template(options.template)
|
template = texenv.get_template(options.template)
|
||||||
|
|
||||||
cwd = os.getcwd()
|
# Saving place
|
||||||
|
cwd = path("./").abspath()
|
||||||
|
|
||||||
|
template_file = path(options.template)
|
||||||
|
|
||||||
if options.output:
|
if options.output:
|
||||||
output_name = options.output
|
output = path(options.output)
|
||||||
else:
|
else:
|
||||||
tpl_base = os.path.splitext(options.template)[0]
|
# Template should be named tpl_... tpl will replace by the number/name of the version
|
||||||
output_name = tpl_base + "_"
|
output = path(template_file.dirname()) / path(template_file.name[3:])
|
||||||
|
|
||||||
output_dir = os.path.dirname(output_name)
|
if output.dirname != "":
|
||||||
if output_dir != "":
|
output.dirname().cd()
|
||||||
os.chdir(output_dir)
|
|
||||||
output_basename = os.path.basename(output_name)
|
output = output.name
|
||||||
output_tplname = output_basename.split("/")[-1]
|
|
||||||
|
|
||||||
|
|
||||||
for subj in range(options.num_subj):
|
for subj in range(options.num_subj):
|
||||||
subj = subj+1
|
subj = subj+1
|
||||||
dest = output_tplname + str(subj) + '.tex'
|
dest = path(str(subj) + output)
|
||||||
with open( dest, 'w') as f:
|
with open( dest, 'w') as f:
|
||||||
f.write(template.render(plop = str(1), RdExpression = RdExpression , infos = {"subj" : subj}))
|
f.write(template.render( RdExpression = RdExpression , infos = {"subj" : subj}))
|
||||||
#os.system("pdflatex " + dest)
|
#os.system("pdflatex " + dest)
|
||||||
|
|
||||||
#if not options.dirty:
|
#if not options.dirty:
|
||||||
# os.system("rm *.aux *.log")
|
# os.system("rm *.aux *.log")
|
||||||
|
|
||||||
os.chdir(cwd)
|
cwd.cd()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option("-t","--tempalte",action="store",type="string",dest="template", help="File with template")
|
parser.add_option("-t","--tempalte",action="store",type="string",dest="template", help="File with template")
|
||||||
parser.add_option("-o","--output",action="store",type="string",dest="output",help="Base name for output (without .tex or any extension))")
|
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 = 2, help="The number of subjects to make")
|
parser.add_option("-n","--number_subjects", action="store",type="int", dest="num_subj", default = 1, help="The number of subjects to make")
|
||||||
parser.add_option("-d","--dirty", action="store_true", dest="dirty", help="Do not clean after compilation")
|
parser.add_option("-d","--dirty", action="store_true", dest="dirty", help="Do not clean after compilation")
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
Loading…
Reference in New Issue
Block a user