repytex/notes_tools/generate_reports_main.py

126 lines
3.5 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
2017-03-07 10:23:45 +00:00
formatter = logging.Formatter('%(name)s :: %(levelname)s :: %(message)s')
2016-11-14 04:42:50 +00:00
steam_handler = logging.StreamHandler()
steam_handler.setLevel(logging.DEBUG)
steam_handler.setFormatter(formatter)
2017-03-07 10:23:45 +00:00
# création de l'objet logger qui va nous servir à écrire dans les logs
logger = logging.getLogger("notes_tools")
# on met le niveau du logger à DEBUG, comme ça il écrit tout
2017-03-07 11:07:39 +00:00
logger.setLevel(logging.INFO)
2016-11-14 04:42:50 +00:00
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")
2017-01-03 18:21:40 +00:00
parser.add_option("-l",
"--list",
action="store_true",
dest="list",
2017-03-07 10:08:50 +00:00
help="List classe and possible reports")
2016-11-14 04:42:50 +00:00
2016-11-13 15:54:11 +00:00
(options, args) = parser.parse_args()
2016-11-14 04:42:50 +00:00
if options.debug_level:
logger.setLevel(logging.DEBUG)
2017-01-03 18:21:40 +00:00
if options.list:
2017-03-07 10:08:50 +00:00
from .reports.reports_tools import print_reports
logger.info("Listing all reports in {}".format(options.path))
print_reports(options.path)
2017-01-03 18:21:40 +00:00
elif options.term:
if not options.classe:
logger.error("Need to pass a class with -c. See -h for help")
sys.exit()
2017-03-07 10:08:50 +00:00
logger.info("Creating term {} report".format(options.term))
from .reports.term_reports import term_report
if options.template:
logger.info("Not default template: {}".format(options.template))
template = options.template
else:
2017-03-07 10:08:50 +00:00
template = "tpl_reports_term.tex"
2017-03-07 10:08:50 +00:00
term_report(options.classe,
options.term,
options.path,
template)
elif options.eval:
2017-01-03 18:21:40 +00:00
if not options.classe:
logger.error("Need to pass a class with -c. See -h for help")
sys.exit()
2017-03-07 10:08:50 +00:00
logger.info("Creating {} report".format(options.eval))
from .reports.eval_reports import eval_report
if options.template:
logger.info("Not default template: {}".format(options.template))
template = options.template
else:
2017-03-07 10:08:50 +00:00
template = "tpl_reports_eval.tex"
2017-03-07 10:08:50 +00:00
eval_report(options.classe,
options.eval,
options.path,
template)
else:
2017-01-03 18:21:40 +00:00
logger.error("Not enough arguments. 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