repytex/notes_tools/generate_reports_main.py

126 lines
3.5 KiB
Python

#!/usr/bin/env python
# encoding: utf-8
import logging
formatter = logging.Formatter('%(name)s :: %(levelname)s :: %(message)s')
steam_handler = logging.StreamHandler()
steam_handler.setLevel(logging.DEBUG)
steam_handler.setFormatter(formatter)
# 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
logger.setLevel(logging.INFO)
logger.addHandler(steam_handler)
import optparse
import os
from path import Path
import sys
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",
help="The evaluation name.")
parser.add_option("-t",
"--term",
action="store",
type="int",
dest="term",
help="The term number.")
parser.add_option("-p",
"--path",
action="store",
type="string",
dest="path",
default=Path("./"),
help="Path where xlsx are stored")
parser.add_option("-T",
"--template",
action="store",
type="string",
dest="template",
help="The template file")
parser.add_option("-d",
"--debug",
action="store_true",
dest="debug_level",
help="Enable debug")
parser.add_option("-l",
"--list",
action="store_true",
dest="list",
help="List classe and possible reports")
(options, args) = parser.parse_args()
if options.debug_level:
logger.setLevel(logging.DEBUG)
if options.list:
from .reports.reports_tools import print_reports
logger.info("Listing all reports in {}".format(options.path))
print_reports(options.path)
elif options.term:
if not options.classe:
logger.error("Need to pass a class with -c. See -h for help")
sys.exit()
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:
template = "tpl_reports_term.tex"
term_report(options.classe,
options.term,
options.path,
template)
elif options.eval:
if not options.classe:
logger.error("Need to pass a class with -c. See -h for help")
sys.exit()
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:
template = "tpl_reports_eval.tex"
eval_report(options.classe,
options.eval,
options.path,
template)
else:
logger.error("Not enough arguments. See -h for help")
sys.exit()
logger.info("À fini")
if __name__ == "__main__":
main()
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del