Méthodes pour initialiser les fichiers de la formation
This commit is contained in:
parent
96e93882b2
commit
003cf96b4d
|
@ -25,24 +25,11 @@ def escape_tex(value):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Préparation du fichier maître tex")
|
|
||||||
parser.add_argument('-n', '--name', help="Nom du fichier à créer")
|
|
||||||
parser.add_argument('-a', '--author', help="Auteur de la formation")
|
|
||||||
parser.add_argument('-t', '--title', help="Titre de la formation")
|
|
||||||
parser.add_argument('-d', '--directory', help="Sous-répertoires où créer le fichier")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
jinja_loader = FileSystemLoader('./templates')
|
|
||||||
jinja_env = Environment(loader=jinja_loader,
|
|
||||||
block_start_string='((*',
|
|
||||||
block_end_string='*))',
|
|
||||||
variable_start_string='(((',
|
|
||||||
variable_end_string=')))',
|
|
||||||
comment_start_string='((=',
|
|
||||||
comment_end_string='=))',
|
|
||||||
trim_blocks=True)
|
|
||||||
jinja_env.filters['escape_tex'] = escape_tex
|
|
||||||
|
|
||||||
|
def init(args):
|
||||||
|
"""
|
||||||
|
init function
|
||||||
|
"""
|
||||||
root = '../'
|
root = '../'
|
||||||
if args.directory:
|
if args.directory:
|
||||||
root = root + re.sub(r'[\w]+/?', '../', args.directory)
|
root = root + re.sub(r'[\w]+/?', '../', args.directory)
|
||||||
|
@ -87,6 +74,62 @@ def main():
|
||||||
with open(path.join(directory, name), 'w') as rendered_file:
|
with open(path.join(directory, name), 'w') as rendered_file:
|
||||||
rendered_file.write(rendered_template.encode('utf-8'))
|
rendered_file.write(rendered_template.encode('utf-8'))
|
||||||
|
|
||||||
|
def update(args):
|
||||||
|
"""
|
||||||
|
update function
|
||||||
|
"""
|
||||||
|
re_class = re.compile(r'\\documentclass\{(?P<document_class>.*)\}')
|
||||||
|
#skbconfig_re = re.compile(r'\\skbconfig\[\s*root\s*=\s*(?P<root>.*),\s*rep\s*=\s*(?P<rep>.*),\s*pub\s*=\s*(?P<pub>.*),\s*fig\s*=\s*(?P<fig>.*),\s*sli\s*=\s*(?P<sli>.*),\s*acr\s*=\s*(?P<acr>.*),\s*bib\s*=\s*(?P<bib>.*),\s*\]\{skblocal.tex\}', re.M)
|
||||||
|
skbconfig_re = re.compile(r'\\skbconfig\[\n\s*root\s*=\s*(?P<root>.*),\n\s*rep\s*=\s*(?P<rep>.*),\n\s*pub\s*=\s*(?P<pub>.*),\n\s*fig\s*=\s*(?P<fig>.*),\n\s*sli\s*=\s*(?P<sli>.*),\n\s*acr\s*=\s*(?P<acr>.*),\n\s*bib\s*=\s*(?P<bib>.*)\n\s*\]\{skblocal.tex\}', re.M)
|
||||||
|
skbinput_re = re.compile(r'\\skbinput\[from=(?P<rep>.*)\]\{(?P<tex>.*?)\}')
|
||||||
|
with open(args.master, 'r') as master:
|
||||||
|
tex_master = master.read()
|
||||||
|
tex_class = re_class.search(tex_master)
|
||||||
|
tex_skbconfig = skbconfig_re.search(tex_master)
|
||||||
|
tex_skbinputs = skbinput_re.finditer(tex_master)
|
||||||
|
|
||||||
|
for skbinput in tex_skbinputs:
|
||||||
|
rep = path.dirname(skbinput.group('tex'))
|
||||||
|
rep = path.join(tex_skbconfig.group(skbinput.group('rep')), rep)
|
||||||
|
basename = '{0}.tex'.format(skbinput.group('tex'))
|
||||||
|
dest = path.join(rep, basename)
|
||||||
|
if not path.isfile(dest):
|
||||||
|
if not path.isdir(rep):
|
||||||
|
print rep
|
||||||
|
makedirs(rep)
|
||||||
|
template = jinja_env.get_template('slide')
|
||||||
|
env = {'title': '', 'subtitle': ''}
|
||||||
|
rendered_template = template.render(**env)
|
||||||
|
with open(dest, 'w') as rendered_file:
|
||||||
|
rendered_file.write(rendered_template.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
jinja_loader = FileSystemLoader('./templates')
|
||||||
|
jinja_env = Environment(loader=jinja_loader,
|
||||||
|
block_start_string='((*',
|
||||||
|
block_end_string='*))',
|
||||||
|
variable_start_string='(((',
|
||||||
|
variable_end_string=')))',
|
||||||
|
comment_start_string='((=',
|
||||||
|
comment_end_string='=))',
|
||||||
|
trim_blocks=True)
|
||||||
|
jinja_env.filters['escape_tex'] = escape_tex
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Préparation des fichiers tex")
|
||||||
|
subparsers = parser.add_subparsers(help='Aide des sous-commandes')
|
||||||
|
parser_init = subparsers.add_parser('init', help='Initialisation du fichier maître')
|
||||||
|
parser_init.add_argument('-n', '--name', help="Nom du fichier à créer", required=True)
|
||||||
|
parser_init.add_argument('-a', '--author', help="Auteur de la formation")
|
||||||
|
parser_init.add_argument('-t', '--title', help="Titre de la formation")
|
||||||
|
parser_init.add_argument('-d', '--directory', help="Sous-répertoires où créer le fichier", required=True)
|
||||||
|
parser_init.set_defaults(func=init)
|
||||||
|
parser_update = subparsers.add_parser('update', help='Mise à jour des fichiers inclus')
|
||||||
|
parser_update.add_argument('-m', '--master', help="Emplacement du fichier maître", required=True)
|
||||||
|
parser_update.set_defaults(func=update)
|
||||||
|
args = parser.parse_args()
|
||||||
|
args.func(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
% Corps de la formation
|
% Corps de la formation
|
||||||
%\skbinput[from=slides]{}
|
%\skbinput[from=slides]{}
|
||||||
|
|
||||||
\skbinput[]{styles/license-cc-by-sa-2.0.tex}
|
\skbinput[from=rep]{licences/(((license)))}
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue