Commit 49e5ef08 authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

add: black pour l'autoindentation

parent 02940f10
......@@ -6,6 +6,7 @@ name = "pypi"
[packages]
ipython = "*"
colorama = "*"
black = "==18.6b4"
[dev-packages]
......
{
"_meta": {
"hash": {
"sha256": "52e5cb125718f17ed8ccbf2c7ff7f92591e1fa6fcdbfa3c6bd2cfc724e2fa01f"
"sha256": "c9b3d346ca540370c2fcde6aa189d99ba9e7a87eed44381e1cba0d65fdcb3e5e"
},
"pipfile-spec": 6,
"requires": {
......@@ -16,6 +16,20 @@
]
},
"default": {
"appdirs": {
"hashes": [
"sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92",
"sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e"
],
"version": "==1.4.3"
},
"attrs": {
"hashes": [
"sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c",
"sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"
],
"version": "==19.3.0"
},
"backcall": {
"hashes": [
"sha256:38ecd85be2c1e78f77fd91700c76e14667dc21e2713b63876c0eb901196e01e4",
......@@ -23,28 +37,43 @@
],
"version": "==0.1.0"
},
"black": {
"hashes": [
"sha256:22158b89c1a6b4eb333a1e65e791a3f8b998cf3b11ae094adb2570f31f769a44",
"sha256:4b475bbd528acce094c503a3d2dbc2d05a4075f6d0ef7d9e7514518e14cc5191"
],
"index": "pypi",
"version": "==18.6b4"
},
"click": {
"hashes": [
"sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
"sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
],
"version": "==7.0"
},
"colorama": {
"hashes": [
"sha256:463f8483208e921368c9f306094eb6f725c6ca42b0f97e313cb5d5512459feda",
"sha256:48eb22f4f8461b1df5734a074b57042430fb06e1d61bd1e11b078c0fe6d7a1f1"
"sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d",
"sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48"
],
"index": "pypi",
"version": "==0.3.9"
"version": "==0.4.1"
},
"decorator": {
"hashes": [
"sha256:2c51dff8ef3c447388fe5e4453d24a2bf128d3a4c32af3fabef1f01c6851ab82",
"sha256:c39efa13fbdeb4506c476c9b3babf6a718da943dab7811c206005a4a956c080c"
"sha256:86156361c50488b84a3f148056ea716ca587df2f0de1d34750d35c21312725de",
"sha256:f069f3a01830ca754ba5258fde2278454a0b5b79e0d7f5c13b3b97e57d4acff6"
],
"version": "==4.3.0"
"version": "==4.4.0"
},
"ipython": {
"hashes": [
"sha256:47b17ea874454a5c2eacc2732b04a750d260b01ba479323155ac8a39031f5535",
"sha256:9fed506c3772c875a3048bc134a25e6f5e997b1569b2636f6a5d891f34cbfd46"
"sha256:c4ab005921641e40a68e405e286e7a1fcc464497e14d81b6914b4fd95e5dee9b",
"sha256:dd76831f065f17bddd7eaa5c781f5ea32de5ef217592cf019e34043b56895aa1"
],
"index": "pypi",
"version": "==7.0.1"
"version": "==7.8.0"
},
"ipython-genutils": {
"hashes": [
......@@ -55,25 +84,25 @@
},
"jedi": {
"hashes": [
"sha256:0191c447165f798e6a730285f2eee783fff81b0d3df261945ecb80983b5c3ca7",
"sha256:b7493f73a2febe0dc33d51c99b474547f7f6c0b2c8fb2b21f453eef204c12148"
"sha256:786b6c3d80e2f06fd77162a07fed81b8baa22dde5d62896a790a331d6ac21a27",
"sha256:ba859c74fa3c966a22f2aeebe1b74ee27e2a462f56d3f5f7ca4a59af61bfe42e"
],
"version": "==0.13.1"
"version": "==0.15.1"
},
"parso": {
"hashes": [
"sha256:35704a43a3c113cce4de228ddb39aab374b8004f4f2407d070b6a2ca784ce8a2",
"sha256:895c63e93b94ac1e1690f5fdd40b65f07c8171e3e53cbd7793b5b96c0e0a7f24"
"sha256:63854233e1fadb5da97f2744b6b24346d2750b85965e7e399bec1620232797dc",
"sha256:666b0ee4a7a1220f65d367617f2cd3ffddff3e205f3f16a0284df30e774c2a9c"
],
"version": "==0.3.1"
"version": "==0.5.1"
},
"pexpect": {
"hashes": [
"sha256:2a8e88259839571d1251d278476f3eec5db26deb73a70be5ed5dc5435e418aba",
"sha256:3fbd41d4caf27fa4a377bfd16fef87271099463e6fa73e92a52f92dfee5d425b"
"sha256:2094eefdfcf37a1fdbfb9aa090862c1a4878e5c7e0e7e7088bdb511c558e5cd1",
"sha256:9e2c1fd0e6ee3a49b28f95d4b33bc389c89b20af6a1255906e90ff1262ce62eb"
],
"markers": "sys_platform != 'win32'",
"version": "==4.6.0"
"version": "==4.7.0"
},
"pickleshare": {
"hashes": [
......@@ -84,11 +113,11 @@
},
"prompt-toolkit": {
"hashes": [
"sha256:5eff0c9fd652384ecfe730bbcdf3658868725c6928fbf608d9338834d7a974b6",
"sha256:81da9ecf6ca6806a549697529af8ec3ac5b739c13ac14607218e650db1b53131",
"sha256:c67c1c264d8a0d9e1070e9272bacee00f76c81daab7bc4bf09ff991bd1e224a7"
"sha256:46642344ce457641f28fc9d1c9ca939b63dadf8df128b86f1b9860e59c73a5e4",
"sha256:e7f8af9e3d70f514373bf41aa51bc33af12a6db3f71461ea47fea985defb2c31",
"sha256:f15af68f66e664eaa559d4ac8a928111eebd5feda0c11738b5998045224829db"
],
"version": "==2.0.5"
"version": "==2.0.10"
},
"ptyprocess": {
"hashes": [
......@@ -99,30 +128,31 @@
},
"pygments": {
"hashes": [
"sha256:78f3f434bcc5d6ee09020f92ba487f95ba50f1e3ef83ae96b9d5ffa1bab25c5d",
"sha256:dbae1046def0efb574852fab9e90209b23f556367b5a320c0bcb871c77c3e8cc"
"sha256:71e430bc85c88a430f000ac1d9b331d2407f681d6f6aec95e8bcfbc3df5b0127",
"sha256:881c4c157e45f30af185c1ffe8d549d48ac9127433f2c380c24b84572ad66297"
],
"version": "==2.2.0"
"version": "==2.4.2"
},
"simplegeneric": {
"six": {
"hashes": [
"sha256:dc972e06094b9af5b855b3df4a646395e43d1c9d0d39ed345b7393560d0b9173"
"sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
"sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"
],
"version": "==0.8.1"
"version": "==1.12.0"
},
"six": {
"toml": {
"hashes": [
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
"sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c",
"sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e"
],
"version": "==1.11.0"
"version": "==0.10.0"
},
"traitlets": {
"hashes": [
"sha256:9c4bd2d267b7153df9152698efb1050a5d84982d3384a37b2c1f7723ba3e7835",
"sha256:c6cb5e6f57c5a9bdaa40fa71ce7b4af30298fbab9ece9815b5d995ab6217c7d9"
"sha256:70b4c6a1d9019d7b4f6846832288f86998aa3b9207c6821f3578a6a6a467fe44",
"sha256:d023ee369ddd2763310e4c3eae1ff649689440d4ae59d7485eb4cfbbe3e359f7"
],
"version": "==4.3.2"
"version": "==4.3.3"
},
"wcwidth": {
"hashes": [
......
......@@ -3,22 +3,22 @@
Cela permet de faire facillement des statistiques sur le nombre de passage
au tableau d'un groupe d'étudiants.
## En entrée
## Pour avoir l'aide
Il faut un fichier CSV contenant la liste des étudiants. Un exemple est donné
dans le fichier **samples/etudiants.csv**.
## En sortie
Un fichier binaire au format **pickle** est enregistré au même endroit que
le fichier **csv** avec l'extention **.pickle**. C'est lui qui contient
tout l'historique des passages.
```
$ pipenv run ./main.py -h
```
## Exemple d'utilisation
## Pour essayer
```
$ pipenv run ./main.py samples/etudiants.csv
```
Vous pourrez utiliser **q** pour sortir et **h** pour avoir la liste des
commandes disponibles.
Vous pourrez utiliser **q** pour sortir.
## Pour formater le code Python automatiquement
```
$ pipenv run black main.py
```
#!/usr/bin/env python
"""Permet de trouver automatiquement des volontaires :)
"""
Permet de trouver automatiquement des volontaires à partir d'un
fichier CSV :) Ce fichier CSV peut être récupéré de l'application
de gestion des absences.
Tout l'historique est conservé dans un fichier binaire au format pickle.
Chaque historique est propre à chaque fichier CSV.
Dans le minishell, voici les commandes disponibles:
- ?: affiche l'aide
......@@ -44,6 +50,7 @@ from random import randrange
import sys
import logging
import logging.handlers
LOG = logging.getLogger(os.path.splitext(os.path.basename(sys.argv[0]))[0])
......@@ -54,6 +61,7 @@ class Etudiant(object):
:param nb: nombre de passage (int)
:param dernier_passage: date du dernier passage (str)
"""
def __init__(self, nom="Nom", prenom="Prenom", nb=0, dernier_passage="?"):
self.dernier_passage = dernier_passage
self.nb = int(nb)
......@@ -72,8 +80,9 @@ class Etudiant(object):
print(f"> nouveau passage enregistrer pour: {self}")
class CustomFormatter(argparse.RawDescriptionHelpFormatter,
argparse.ArgumentDefaultsHelpFormatter):
class CustomFormatter(
argparse.RawDescriptionHelpFormatter, argparse.ArgumentDefaultsHelpFormatter
):
pass
......@@ -108,14 +117,14 @@ def progress_bar(valeur, maximum, bar_length=20):
percent = float(valeur) / maximum
except ZeroDivisionError:
percent = 0
hashes = '#' * int(round(percent * bar_length))
spaces = '_' * (bar_length - len(hashes))
return("[%s%s] % 3d%%" % (hashes, spaces, int(round(percent * 100))))
hashes = "#" * int(round(percent * bar_length))
spaces = "_" * (bar_length - len(hashes))
return "[%s%s] % 3d%%" % (hashes, spaces, int(round(percent * 100)))
def get_dashboard(history):
"A partir d'un set, on resort une chaine avec les progressbar"
msg = Fore.WHITE+"-"*50+"\n"
msg = Fore.WHITE + "-" * 50 + "\n"
total = get_total(history)
moy = get_mean(history)
for key in history:
......@@ -126,8 +135,8 @@ def get_dashboard(history):
msg += Fore.GREEN
bar = progress_bar(etudiant.nb, total)
msg += f"{bar} {etudiant.nom} {etudiant.prenom} ({etudiant.nb})\n"
msg += Fore.WHITE+"-"*50+"\n"
msg += f"Nombre de passage total: {total}"+Fore.RESET
msg += Fore.WHITE + "-" * 50 + "\n"
msg += f"Nombre de passage total: {total}" + Fore.RESET
return msg
......@@ -155,25 +164,23 @@ def setup_logging(options):
if not options.silent:
if not sys.stderr.isatty():
facility = logging.handlers.SysLogHandler.LOG_DAEMON
sh = logging.handlers.SysLogHandler(address='/dev/log',
facility=facility)
sh.setFormatter(logging.Formatter(
"{0}[{1}]: %(message)s".format(
LOG.name,
os.getpid())))
sh = logging.handlers.SysLogHandler(address="/dev/log", facility=facility)
sh.setFormatter(
logging.Formatter("{0}[{1}]: %(message)s".format(LOG.name, os.getpid()))
)
root.addHandler(sh)
else:
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter(
"%(levelname)s[%(name)s] %(message)s"))
ch.setFormatter(logging.Formatter("%(levelname)s[%(name)s] %(message)s"))
root.addHandler(ch)
def print_students(history, short):
"""Affichage des étudiants
"""
# nombre d'étudiants au total
nb = len(history)
print(Fore.WHITE+"Liste des étudiants:"+Fore.RESET)
print(Fore.WHITE + "Liste des étudiants:" + Fore.RESET)
# La liste complète des étudiants en cours
for index, key in enumerate(history.keys()):
msg = f"> #{index} {history[key]}"
......@@ -181,25 +188,30 @@ def print_students(history, short):
color = Fore.RED
else:
color = Fore.GREEN
print(color+ msg+Fore.RESET)
print(Fore.WHITE+f"Nombre d'étudiants total: {nb}"+Fore.RESET)
print(color + msg + Fore.RESET)
print(Fore.WHITE + f"Nombre d'étudiants total: {nb}" + Fore.RESET)
def parse_args(args):
"""traitement des paramètres."""
parser = argparse.ArgumentParser(
description=sys.modules[__name__].__doc__,
formatter_class=CustomFormatter)
description=sys.modules[__name__].__doc__, formatter_class=CustomFormatter
)
parser.add_argument("csv", help="la liste des étudiants")
g = parser.add_mutually_exclusive_group()
g.add_argument("--debug", "-d", action="store_true",
default=False,
help="enable debugging")
g.add_argument("--silent", "-s", action="store_true",
default=False,
help="don't log to console")
g.add_argument(
"--debug", "-d", action="store_true", default=False, help="enable debugging"
)
g.add_argument(
"--silent",
"-s",
action="store_true",
default=False,
help="don't log to console",
)
return parser.parse_args(args)
def load_csv(fichier):
"""Chargement du CSV et initialisation si besoin"""
if not os.path.isfile(fichier):
......@@ -207,7 +219,7 @@ def load_csv(fichier):
sys.exit(2)
LOG.info(f"> chargement de {fichier}")
OUT = fichier.replace('.csv', '.pickle')
OUT = fichier.replace(".csv", ".pickle")
LOG.debug(f"> fichier pickle: {OUT}")
if os.path.isfile(OUT):
LOG.info("> chagement de l'historique")
......@@ -216,15 +228,16 @@ def load_csv(fichier):
history = {}
with open(fichier) as f:
reader = csv.DictReader(f, delimiter=';')
reader = csv.DictReader(f, delimiter=";")
# data = [r for r in reader]
for r in reader:
etu = Etudiant(nom=r['nom'], prenom=r['prenom'])
etu = Etudiant(nom=r["nom"], prenom=r["prenom"])
cle = etu.get_key()
if cle not in history:
history[cle] = etu
return history
if __name__ == "__main__":
options = parse_args(sys.argv[1:])
setup_logging(options)
......@@ -232,7 +245,7 @@ if __name__ == "__main__":
short = get_shortlist(history)
nb_short = len(short)
print(Fore.WHITE+"\nAppuyer sur '?' pour l'aide."+Fore.RESET)
print(Fore.WHITE + "\nAppuyer sur '?' pour l'aide." + Fore.RESET)
volontaire_non_trouve = True
while volontaire_non_trouve:
print()
......@@ -240,11 +253,11 @@ if __name__ == "__main__":
try:
etudiant = history[short[volontaire]]
except IndexError:
print(Fore.RED+f"!! volontaire impossible: {volontaire} !!"+Fore.RESET)
print(Fore.RED + f"!! volontaire impossible: {volontaire} !!" + Fore.RESET)
else:
message = f">> prochain volontaire #{volontaire}: {etudiant}"
print(Fore.YELLOW+message+Fore.RESET)
rep = input(Fore.CYAN+"Commande ? "+Fore.RESET).lower()
print(Fore.YELLOW + message + Fore.RESET)
rep = input(Fore.CYAN + "Commande ? " + Fore.RESET).lower()
if rep == "o":
# volontaire_non_trouve = False
......@@ -260,13 +273,13 @@ if __name__ == "__main__":
try:
index = int(input(msg))
except ValueError:
print(Fore.WHITE+"!! vous devez saisir un numéro !!"+Fore.RESET)
print(Fore.WHITE + "!! vous devez saisir un numéro !!" + Fore.RESET)
else:
try:
key = list(history.keys())[index]
etudiant = history[key]
except IndexError:
print(Fore.WHITE+"!! volontaire inconnu !!"+Fore.RESET)
print(Fore.WHITE + "!! volontaire inconnu !!" + Fore.RESET)
else:
etudiant.nouveau_passage()
elif rep == "h":
......@@ -278,13 +291,13 @@ if __name__ == "__main__":
print_students(history, short)
elif rep == "s":
nb = len(short)
print(Fore.WHITE+"Liste des étudiants:"+Fore.RED)
print(Fore.WHITE + "Liste des étudiants:" + Fore.RED)
for key in short:
print(f"> {history[key]}")
print(Fore.WHITE+f"Nombre d'étudiants total: {nb}"+Fore.RESET)
print(Fore.WHITE + f"Nombre d'étudiants total: {nb}" + Fore.RESET)
elif rep == "?":
print(Fore.WHITE+"Commandes disponibles:")
print(Fore.GREEN+"...?: affiche cette aide")
print(Fore.WHITE + "Commandes disponibles:")
print(Fore.GREEN + "...?: affiche cette aide")
print("...a: ajouter un volontaire manuellement")
print("...h: hall of fame")
print("...l: liste de tous les étudiants")
......@@ -295,9 +308,9 @@ if __name__ == "__main__":
print("...s: liste des étudiants en short list")
print(Fore.RESET)
else:
print(Fore.RED+"...moi, pas compris ! Essayer de taper '?'"+Fore.RESET)
print(Fore.RED + "...moi, pas compris ! Essayer de taper '?'" + Fore.RESET)
OUT = options.csv.replace('.csv', '.pickle')
OUT = options.csv.replace(".csv", ".pickle")
LOG.info(f"> enregistrement dans {OUT}")
pickle.dump(history, open(OUT, "wb"))
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment