From 1893f8375e2d29adfa453d296166f90d567759d3 Mon Sep 17 00:00:00 2001 From: Benjamin Bohard Date: Thu, 31 Jul 2025 16:03:18 +0200 Subject: [PATCH] =?UTF-8?q?Premi=C3=A8re=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apply_patches.sh | 12 ++++++ etabs_with_individus.sh | 13 +++++++ explore_ldap.py | 18 +++++++++ find_individus.py | 67 ++++++++++++++++++++++++++++++++++ patches.d/scribe-backend.patch | 39 ++++++++++++++++++++ unapply_patches.sh | 12 ++++++ 6 files changed, 161 insertions(+) create mode 100644 apply_patches.sh create mode 100644 etabs_with_individus.sh create mode 100644 explore_ldap.py create mode 100644 find_individus.py create mode 100644 patches.d/scribe-backend.patch create mode 100644 unapply_patches.sh diff --git a/apply_patches.sh b/apply_patches.sh new file mode 100644 index 0000000..3b25b4b --- /dev/null +++ b/apply_patches.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +patches_root="$(pwd)/patches.d/" + +for patch_file in $(find $patches_root -name "*.patch") +do + pushd / + patch -p0 < $patch_file + popd +done + +exit 0 diff --git a/etabs_with_individus.sh b/etabs_with_individus.sh new file mode 100644 index 0000000..3d36d8d --- /dev/null +++ b/etabs_with_individus.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +for etab in $(python3 find_individus.py -t current_etabs) +do + ldapsearch -LLL -x -b "ou=$etab,ou=tst-colleges,ou=education,o=gouv,c=fr" uid | grep -q uid + res=$? + if [ $res -eq 0 ] + then + echo $etab + fi +done + +exit 0 diff --git a/explore_ldap.py b/explore_ldap.py new file mode 100644 index 0000000..15139df --- /dev/null +++ b/explore_ldap.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +from scribe.enseignants import LdapEnseignant +from scribe.eoleldap import Ldap +from scribe.storage import init_store +from scribe.importation import config +from scribe.storage import Enseigant + +storage = init_store(config.DB_STORE) + +connexion = Ldap() +connexion.connect() + +user = LdapEnseignant() +user.ldap_admin = connexion + +user.ldap_admin._search_one() + diff --git a/find_individus.py b/find_individus.py new file mode 100644 index 0000000..eae744e --- /dev/null +++ b/find_individus.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +import xml.etree.ElementTree as ET +from pathlib import Path +from scribe.eoleldap import get_etabs + +current_etabs = get_etabs()[1] + +root = Path('/home/adhomes/admin/perso/comptes') +repartition = {} +etabs = [] +individus = {} +for xml in root.glob('**/sts_emp*.xml'): + tree = ET.parse(xml) + tree_root = tree.getroot() + etab = tree_root.find('./PARAMETRES/UAJ').get('CODE') + etabs.append(etab) + for individu in tree_root.iter('INDIVIDU'): + id_ind = individu.get('ID') + nom_ind = individu.find('NOM_USAGE') + try: + nom_ind = nom_ind.text + except: + pass + prenom_ind = individu.find('PRENOM') + try: + prenom_ind = prenom_ind.text + except: + pass + fonction_ind = individu.find('FONCTION') + try: + fonction_ind = fonction_ind.text + except: + pass + key = id_ind + repartition.setdefault(key, []) + repartition[key].append(etab) + individus.setdefault(key, []) + individus[key].append({'nom': nom_ind, 'prenom': prenom_ind, 'fonction': fonction_ind}) + +etabs = list(set(etabs)) + +if __name__ == '__main__': + from argparse import ArgumentParser + parser = ArgumentParser() + parser.add_argument('-t', '--type') + parser.add_argument('-e', '--extended', action='store_true') + args = parser.parse_args() + + if args.type == 'individus': + if args.extended: + result = ["{}\t{}".format(individus[ind][0]['nom'], " ".join(sorted(set(e)))) for ind, e in repartition.items() if len(set(e)) > 1] + else: + result = [individus[ind][0]['nom'] for ind, e in repartition.items() if len(set(e)) > 1] + elif args.type == 'presents': + if args.extended: + result = ["{} {}\t\t{}".format(individus[ind][0]['nom'], individus[ind][0]['prenom'], " ".join(set(e))) for ind, e in repartition.items() if len(set(e).intersection(set(current_etabs))) > 1] + else: + result = [individus[ind][0]['nom'] for ind, e in repartition.items() if len(set(e).intersection(set(current_etabs))) > 1] + elif args.type == 'current_etabs': + result = current_etabs + elif args.type == 'etabs': + result = etabs + else: + result = [] + print("\n".join(sorted(result))) + diff --git a/patches.d/scribe-backend.patch b/patches.d/scribe-backend.patch new file mode 100644 index 0000000..17fe30b --- /dev/null +++ b/patches.d/scribe-backend.patch @@ -0,0 +1,39 @@ +diff --git usr/lib/python3/dist-packages/scribe/importation/writer.py usr/lib/python3/dist-packages/scribe/importation/writer.py +index 34ce0fb..e4ddfea 100644 +--- usr/lib/python3/dist-packages/scribe/importation/writer.py ++++ usr/lib/python3/dist-packages/scribe/importation/writer.py +@@ -900,10 +900,10 @@ def write_enseignant(store, connexion, etab=None, current_ead_user=config.DEFAUL + else: + login = '' + else: +- login = _enseignant_exists(enseignant, user) ++ login = _enseignant_exists(enseignant, user, etab=etab) + if login != '': + # enseignant existant +- _maj_enseignant(enseignant, user, login, etab) ++ _maj_enseignant(enseignant, user, login, etab=etab) + else: + # nouvel enseignant + if str(enseignant.nom) == '' or str(enseignant.prenom) == '': +@@ -1027,7 +1027,7 @@ def write_administratif(store, connexion, etab=None, current_ead_user=config.DEF + # personnel existe + _maj_administratif(administratif, user, login) + else: +- login = _enseignant_exists(administratif, user) ++ login = _enseignant_exists(administratif, user, etab) + if login != '': + # le personnel a été crée comme un professeur... + log.infolog("(%s a un compte enseignant)" % login) +diff --git usr/lib/python3/dist-packages/scribe/linker.py usr/lib/python3/dist-packages/scribe/linker.py +index 71fb28d..09af637 100644 +--- usr/lib/python3/dist-packages/scribe/linker.py ++++ usr/lib/python3/dist-packages/scribe/linker.py +@@ -99,7 +99,7 @@ def _responsable_exists(responsable, user): + return res['uid'][0] + return '' + +-def _enseignant_exists(enseignant, user): ++def _enseignant_exists(enseignant, user, etab=None): + """ + recherche si un enseignant existe déjà dans l'annuaire + enseignant : storage.Enseignant() diff --git a/unapply_patches.sh b/unapply_patches.sh new file mode 100644 index 0000000..09eedaf --- /dev/null +++ b/unapply_patches.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +patches_root="$(pwd)/patches.d/" + +for patch_file in $(find $patches_root -name "*.patch") +do + pushd / + patch -p0 -R < $patch_file + popd +done + +exit 0