From 8ec0171ca0ff2eac1f71fca31db4a9ad4d48a750 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 3 Apr 2024 19:02:40 +0200 Subject: [PATCH] =?UTF-8?q?Script=20pr=C3=A9paration=20d=C3=A9mos:=20renom?= =?UTF-8?q?mage=20de=20tous=20les=20=C3=A9tudiants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/fakeportal/demo_reset_noms.py | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/tools/fakeportal/demo_reset_noms.py b/tools/fakeportal/demo_reset_noms.py index db7f9fb2b..9dc0ba17c 100755 --- a/tools/fakeportal/demo_reset_noms.py +++ b/tools/fakeportal/demo_reset_noms.py @@ -3,7 +3,8 @@ """Outils pour environnements de démo. -Change aléatoirement les identites (nip, civilite, nom, prenom) des étudiants d'un semestre. +Change aléatoirement les identites (nip, civilite, nom, prenom) des étudiants. +Un semestre ou tous si non spécifié. Le NIP est choisi aléatoirement (nombre entier à 8 chiffres). Les noms et prénoms sont issus des fichiers noms.txt, prenoms-h.txt, prenoms-f.txt @@ -19,37 +20,39 @@ from gen_nomprenoms import nomprenom def usage(): - print(f"Usage: {sys.argv[0]} dbname formsemestre_id") + print(f"Usage: {sys.argv[0]} dbname [formsemestre_id]") sys.exit(1) -if len(sys.argv) != 3: +if len(sys.argv) not in (2, 3): usage() dbname = sys.argv[1] -formsemestre_id = sys.argv[2] +formsemestre_id = sys.argv[2] if len(sys.argv) > 2 else None DBCNXSTRING = f"dbname={dbname}" # Liste des etudiants inscrits à ce semestre cnx = psycopg2.connect(DBCNXSTRING) cursor = cnx.cursor() -cursor.execute( - "select count(*) from notes_formsemestre where id=%(formsemestre_id)s", - {"formsemestre_id": formsemestre_id}, -) -nsem = cursor.fetchone()[0] -if nsem != 1: - print(f"{nsem} formsemestre matching {formsemestre_id} in {dbname}") - sys.exit(2) - -cursor.execute( - """select i.id - from identite i, notes_formsemestre_inscription ins - where i.id=ins.etudid and ins.formsemestre_id=%(formsemestre_id)s - """, - {"formsemestre_id": formsemestre_id}, -) +if formsemestre_id is None: + cursor.execute("SELECT i.id from identite i") +else: + cursor.execute( + "select count(*) from notes_formsemestre where id=%(formsemestre_id)s", + {"formsemestre_id": formsemestre_id}, + ) + nsem = cursor.fetchone()[0] + if nsem != 1: + print(f"{nsem} formsemestre matching {formsemestre_id} in {dbname}") + sys.exit(2) + cursor.execute( + """select i.id + from identite i, notes_formsemestre_inscription ins + where i.id=ins.etudid and ins.formsemestre_id=%(formsemestre_id)s + """, + {"formsemestre_id": formsemestre_id}, + ) wcursor = cnx.cursor() n = 0