diff --git a/ageg.py b/ageg.py deleted file mode 100644 index d6e86ff..0000000 --- a/ageg.py +++ /dev/null @@ -1,43 +0,0 @@ -from math import isnan -import os - -from mako.template import Template -from mako.lookup import TemplateLookup - -from pandas import read_csv - -from ageg.admin import generer_sousquestion_admin, generer_options_admin -from ageg.exec import generer_questions_exec - -from models.answer import Answer -from models.group import Group -from models.question import Question - -if os.path.isfile('example/admin.csv') and os.path.isfile('example/executif.csv'): - print("JOB START ! Starting generation for ageg !") - groupe_exec = Group(id=0, name="Comité exécutif", description="Pour cette section, seulement une personne peut-être élue par poste. Veuillez placer les candidatures en ordre de préférence, du haut vers le bas.") - groupe_admin = Group(id=1, name="Conseil d'administration", description="Vote de confiance pour les postes saisonniers au conseil d'administration de l'AGEG.") - groups = [groupe_exec, groupe_admin] - - questions = generer_questions_exec(groupe_exec.gid) - question_admin = Question(id=100, code="CASA19", gid=groupe_admin.gid, title="Qui voulez-vous comme administrateurs saisonniers de l'AGEG?", type='F') - question_admin.add_answer(Answer(qid=question_admin.qid, value="Oui", code="A1", order=1)) - question_admin.add_answer(Answer(qid=question_admin.qid, value="Non", code="A2", order=2)) - - sousquestions_admin = generer_sousquestion_admin(question_admin) - options_admin = generer_options_admin() - - for option in options_admin: - question_admin.add_option(option) - - questions.append(question_admin) - mylookup = TemplateLookup(directories=['.'], input_encoding="utf-8", output_encoding="utf-8") - mytemplate = Template(filename='templates/base.mako', lookup=mylookup, input_encoding="utf-8", output_encoding="utf-8") - - survey = mytemplate.render(groups=groups,questions=questions, subquestions=sousquestions_admin, withAttributes=False) - - survey_file = open("result/ageg-survey.lss", "w+b") - survey_file.write(survey) - survey_file.close() - - print("JOB DONE ! You can find your result in result/ageg-survey.lss") \ No newline at end of file diff --git a/ageg/__init__.py b/ageg/__init__.py index e69de29..2117ade 100644 --- a/ageg/__init__.py +++ b/ageg/__init__.py @@ -0,0 +1,41 @@ +from math import isnan +import os + +from mako.template import Template +from mako.lookup import TemplateLookup + +from pandas import read_csv + +from .admin import generer_sousquestion_admin, generer_options_admin +from .executif import generer_questions_exec + +from models.answer import Answer +from models.group import Group +from models.question import Question + +def generer_questionnaire(configuration): + if os.path.isfile(configuration.fichiers.admin_saisonniers) and os.path.isfile(configuration.fichiers.executif): + groupe_exec = Group(id=0, name="Comité exécutif", description="Pour cette section, seulement une personne peut-être élue par poste. Veuillez placer les candidatures en ordre de préférence, du haut vers le bas.") + groupe_admin = Group(id=1, name="Conseil d'administration", description="Vote de confiance pour les postes saisonniers au conseil d'administration de l'AGEG.") + groups = [groupe_exec, groupe_admin] + + questions = generer_questions_exec(groupe_exec.gid) + question_admin = Question(id=100, code="CASA19", gid=groupe_admin.gid, title="Qui voulez-vous comme administrateurs saisonniers de l'AGEG?", type='F') + question_admin.add_answer(Answer(qid=question_admin.qid, value="Oui", code="A1", order=1)) + question_admin.add_answer(Answer(qid=question_admin.qid, value="Non", code="A2", order=2)) + + sousquestions_admin = generer_sousquestion_admin(question_admin) + options_admin = generer_options_admin() + + for option in options_admin: + question_admin.add_option(option) + + questions.append(question_admin) + mylookup = TemplateLookup(directories=['.'], input_encoding="utf-8", output_encoding="utf-8") + mytemplate = Template(filename='templates/base.mako', lookup=mylookup, input_encoding="utf-8", output_encoding="utf-8") + + survey = mytemplate.render(groups=groups,questions=questions, subquestions=sousquestions_admin, withAttributes=False) + + survey_file = open("result/ageg-survey.lss", "w+b") + survey_file.write(survey) + survey_file.close() \ No newline at end of file diff --git a/ageg/exec.py b/ageg/executif.py similarity index 100% rename from ageg/exec.py rename to ageg/executif.py diff --git a/config1.yaml b/config1.yaml new file mode 100644 index 0000000..c00f8a7 --- /dev/null +++ b/config1.yaml @@ -0,0 +1,8 @@ +fichiers: + executif: exec.csv +options: + avec_admin_annuels: false +informations: + admin: + nom: Tommy Savaria + email: elections@ageg.ca \ No newline at end of file diff --git a/config2.yaml b/config2.yaml new file mode 100644 index 0000000..daa4f6d --- /dev/null +++ b/config2.yaml @@ -0,0 +1,3 @@ +fichiers: + admin_saisonniers: admin_s.csv + admin_annuels: admin_a.csv \ No newline at end of file diff --git a/elections.py b/elections.py new file mode 100644 index 0000000..9ad239e --- /dev/null +++ b/elections.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +from yaml import safe_load +from argparse import ArgumentParser + +import ageg +import finissante + +def merge(source, destination): + for key, value in source.items(): + if isinstance(value, dict): + # get node or create one + node = destination.setdefault(key, {}) + merge(value, node) + else: + destination[key] = value + + return destination + + +parser = ArgumentParser() +parser.add_argument("type", choices=["ageg", "finissante"]) +parser.add_argument("-c", "--config", action="append") +parser.add_argument("-D", "--define", action="append") +args = parser.parse_args() + +configuration = {} + +for filename in args.config: + with open(filename, "r") as f: + configuration = merge(safe_load(f), configuration) + +for key in args.define: + splits = key.split("=") + path = splits[0].split(".") + node = configuration + for path_segment in path[:-1]: + if path_segment not in node: + node[path_segment] = {} + + node = node[path_segment] + + node[path[-1]] = splits[1] + +if args.type == "ageg": + ageg.generer_questionnaire(configuration) + diff --git a/finissante.py b/finissante.py index c8ce4aa..f5b8673 100644 --- a/finissante.py +++ b/finissante.py @@ -13,8 +13,6 @@ from models.question import Question if os.path.isfile('example/Candidatures.csv'): - print("JOB START ! Starting generation for finissante !") - postes = [ "Présidence", "Vice-Présidence", @@ -122,6 +120,4 @@ def zeroPad(value): survey_file = open("result/finissante-survey.lss", "w+b") survey_file.write(survey) - survey_file.close() - - print("JOB DONE ! You can find your result in result/finissante-survey.lss") + survey_file.close() \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..351c4be --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +black==19.3b0 +pylint==2.3.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 39fe586..fc04c78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Mako==1.0.8 -pandas==0.24.2 \ No newline at end of file +pandas==0.24.2 +PyYaml==5.1 \ No newline at end of file