repytex/notes_tools/generate_bilan/__main__.py

112 lines
3.1 KiB
Python
Raw Normal View History

2016-11-13 15:54:11 +00:00
#!/usr/bin/env python
# encoding: utf-8
2016-11-14 04:42:50 +00:00
import logging
# création de l'objet logger qui va nous servir à écrire dans les logs
logger = logging.getLogger("generate_bilan")
# on met le niveau du logger à DEBUG, comme ça il écrit tout
logger.setLevel(logging.DEBUG)
2016-11-14 04:42:50 +00:00
formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s :: %(message)s')
steam_handler = logging.StreamHandler()
steam_handler.setLevel(logging.DEBUG)
steam_handler.setFormatter(formatter)
logger.addHandler(steam_handler)
2016-11-13 15:54:11 +00:00
import optparse
import os
from path import Path
2016-11-14 04:42:50 +00:00
import sys
2016-11-13 15:54:11 +00:00
def main():
parser = optparse.OptionParser()
parser.add_option("-c",
"--classe",
action="store",
type="string",
dest="classe",
help="The classe")
parser.add_option("-e",
"--evaluation",
action="store",
type="string",
dest="eval",
2016-11-13 15:54:11 +00:00
help="The evaluation name.")
parser.add_option("-t",
"--term",
action="store",
type="int",
dest="term",
help="The term number.")
2016-11-13 15:54:11 +00:00
parser.add_option("-p",
"--path",
action="store",
type="string",
dest="path",
default=Path("./"),
help="Path where xlsx are stored")
parser.add_option("-T",
2016-11-13 15:54:11 +00:00
"--template",
action="store",
type="string",
dest="template",
help="The template file")
2016-11-14 04:42:50 +00:00
parser.add_option("-d",
"--debug",
action="store_true",
dest="debug_level",
help="Enable debug")
2016-11-13 15:54:11 +00:00
(options, args) = parser.parse_args()
if not options.classe:
2016-11-14 04:42:50 +00:00
logger.error("Need to pass a class with -c. See -h for help")
sys.exit()
if options.debug_level:
logger.setLevel(logging.DEBUG)
if options.term:
logger.info("Creating term {} bilan".format(options.term))
from .term_bilan import term_bilan
if options.template:
logger.info("Not default template: {}".format(options.template))
template = options.template
else:
template = "tpl_bilan_term.tex"
term_bilan(options.classe,
options.term,
options.path,
template)
elif options.eval:
logger.info("Creating {} bilan".format(options.eval))
from .eval_bilan import eval_bilan
if options.template:
logger.info("Not default template: {}".format(options.template))
template = options.template
else:
template = "tpl_bilan_eval.tex"
eval_bilan(options.classe,
options.eval,
options.path,
template)
else:
logger.error("Need to pass a evaluation name with -e or the term number with -t. See -h for help")
sys.exit()
2016-11-13 15:54:11 +00:00
2016-11-14 04:42:50 +00:00
logger.info("À fini")
2016-11-13 15:54:11 +00:00
if __name__ == "__main__":
main()
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del