Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Options en ligne de commande #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions ageg.py

This file was deleted.

41 changes: 41 additions & 0 deletions ageg/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
File renamed without changes.
8 changes: 8 additions & 0 deletions config1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fichiers:
executif: exec.csv
options:
avec_admin_annuels: false
informations:
admin:
nom: Tommy Savaria
email: [email protected]
3 changes: 3 additions & 0 deletions config2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fichiers:
admin_saisonniers: admin_s.csv
admin_annuels: admin_a.csv
46 changes: 46 additions & 0 deletions elections.py
Original file line number Diff line number Diff line change
@@ -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)

6 changes: 1 addition & 5 deletions finissante.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
black==19.3b0
pylint==2.3.1
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Mako==1.0.8
pandas==0.24.2
pandas==0.24.2
PyYaml==5.1