From bd2e0ccde5064f76d0300ef2f1ff97ef5e29b941 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 17 Sep 2021 10:02:27 +0200 Subject: [PATCH] Archives: utilise dept_id et non acronyme --- app/scodoc/sco_archives.py | 15 +++++++++------ app/scodoc/sco_etape_apogee.py | 4 ++-- app/scodoc/sco_photos.py | 7 ++++--- tools/migrate_scodoc7_archives.py | 30 +++++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index f69041e9..ca73ac6c 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -29,19 +29,19 @@ Archives are plain files, stored in - /archives/ - (where is usually /opt/scodoc-data, and a departement id) + /archives/ + (where is usually /opt/scodoc-data, and a departement id (int)) Les PV de jurys et documents associés sont stockées dans un sous-repertoire de la forme /// (formsemestre_id est ici FormSemestre.id) Les documents liés à l'étudiant sont dans - /docetuds/// + /docetuds/// (etudid est ici Identite.id) Les maquettes Apogée pour l'export des notes sont dans - /apo_csv//-//.csv + /apo_csv//-//.csv Un répertoire d'archive contient des fichiers quelconques, et un fichier texte nommé _description.txt qui est une description (humaine, format libre) de l'archive. @@ -61,6 +61,7 @@ from flask import g import app.scodoc.sco_utils as scu from config import Config from app import log +from app.models import Departement from app.scodoc.TrivialFormulator import TrivialFormulator from app.scodoc.sco_exceptions import ( AccessDenied, @@ -109,7 +110,8 @@ class BaseArchiver(object): If directory does not yet exist, create it. """ self.initialize() - dept_dir = os.path.join(self.root, g.scodoc_dept) + dept = Departement.query.filter_by(acronym=g.scodoc_dept).first() + dept_dir = os.path.join(self.root, str(dept.id)) try: scu.GSL.acquire() if not os.path.isdir(dept_dir): @@ -128,7 +130,8 @@ class BaseArchiver(object): :return: list of archive oids """ self.initialize() - base = os.path.join(self.root, g.scodoc_dept) + os.path.sep + dept = Departement.query.filter_by(acronym=g.scodoc_dept).first() + base = os.path.join(self.root, str(dept.id)) + os.path.sep dirs = glob.glob(base + "*") return [os.path.split(x)[1] for x in dirs] diff --git a/app/scodoc/sco_etape_apogee.py b/app/scodoc/sco_etape_apogee.py index 5409c58e..582497e9 100644 --- a/app/scodoc/sco_etape_apogee.py +++ b/app/scodoc/sco_etape_apogee.py @@ -32,11 +32,11 @@ Voir sco_apogee_csv.py pour la structure du fichier Apogée. Stockage: utilise sco_archive.py - => /opt/scodoc/var/scodoc/archives/apo_csv/RT/2016-1/2016-07-03-16-12-19/V3ASR.csv + => /opt/scodoc/var/scodoc/archives/apo_csv//2016-1/2016-07-03-16-12-19/V3ASR.csv pour une maquette de l'année scolaire 2016, semestre 1, etape V3ASR ou bien (à partir de ScoDoc 1678) : - /opt/scodoc/var/scodoc/archives/apo_csv/RT/2016-1/2016-07-03-16-12-19/V3ASR!111.csv + /opt/scodoc/var/scodoc/archives/apo_csv//2016-1/2016-07-03-16-12-19/V3ASR!111.csv pour une maquette de l'étape V3ASR version VDI 111. La version VDI sera ignorée sauf si elle est indiquée dans l'étape du semestre. diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index b63b2afc..39dbd088 100644 --- a/app/scodoc/sco_photos.py +++ b/app/scodoc/sco_photos.py @@ -341,7 +341,7 @@ def find_new_dir(): def copy_portal_photo_to_fs(etud): """Copy the photo from portal (distant website) to local fs. - Returns rel. path or None if copy failed, with a diagnotic message + Returns rel. path or None if copy failed, with a diagnostic message """ sco_etud.format_etud_ident(etud) url = photo_portal_url(etud) @@ -353,8 +353,9 @@ def copy_portal_photo_to_fs(etud): log("copy_portal_photo_to_fs: getting %s" % url) r = requests.get(url, timeout=portal_timeout) except: - log("download failed: exception:\n%s" % traceback.format_exc()) - log("called from:\n" + "".join(traceback.format_stack())) + # log("download failed: exception:\n%s" % traceback.format_exc()) + # log("called from:\n" + "".join(traceback.format_stack())) + log("copy_portal_photo_to_fs: error.") return None, "%s: erreur chargement de %s" % (etud["nomprenom"], url) if r.status_code != 200: log("download failed") diff --git a/tools/migrate_scodoc7_archives.py b/tools/migrate_scodoc7_archives.py index 55acd842..6e7553db 100644 --- a/tools/migrate_scodoc7_archives.py +++ b/tools/migrate_scodoc7_archives.py @@ -4,6 +4,7 @@ import glob import os import shutil +import sys from app.models import Departement from app.models.formsemestre import FormSemestre @@ -25,7 +26,8 @@ def migrate_scodoc7_dept_archive(dept_name=""): migrate_docetuds(dept) # ApoCSVArchiver: - # /opt/scodoc-data/archives/apo_csv// ne bouge pas + # /opt/scodoc-data/archives/apo_csv// -> apo_csv// + migrate_apo_csv(dept) def migrate_sem_archives(dept): @@ -35,7 +37,7 @@ def migrate_sem_archives(dept): for sem in FormSemestre.query.filter_by(dept_id=dept.id): n += 1 arch_dir7 = f"/opt/scodoc-data/archives/{dept.acronym}/{sem.scodoc7_id}" - arch_dir9 = f"/opt/scodoc-data/archives/{dept.acronym}/{sem.id}" + arch_dir9 = f"/opt/scodoc-data/archives/{dept.id}/{sem.id}" if os.path.exists(arch_dir7): n_moves += 1 if not os.path.exists(arch_dir9): @@ -58,7 +60,7 @@ def migrate_docetuds(dept): arch_dir7 = ( f"/opt/scodoc-data/archives/docetuds/{dept.acronym}/{etud.scodoc7_id}" ) - arch_dir9 = f"/opt/scodoc-data/archives/docetuds/{dept.acronym}/{etud.id}" + arch_dir9 = f"/opt/scodoc-data/archives/docetuds/{dept.id}/{etud.id}" if os.path.exists(arch_dir7): n_moves += 1 if not os.path.exists(arch_dir9): @@ -70,3 +72,25 @@ def migrate_docetuds(dept): # print(f"\tmoving {arch}") shutil.move(arch, arch_dir9) # print(f"moved {n_moves}/{n} etuds") + + +def migrate_apo_csv(dept): + "/opt/scodoc-data/archives/apo_csv// -> .../apo_csv//" + arch_dir7 = f"/opt/scodoc-data/archives/apo_csv/{dept.acronym}" + arch_dir7_upper = f"/opt/scodoc-data/archives/apo_csv/{dept.acronym.upper()}" + arch_dir9 = f"/opt/scodoc-data/archives/apo_csv/{dept.id}" + if os.path.exists(arch_dir7): + if os.path.exists(arch_dir9): + print( + f"Warning: {arch_dir9} exist ! not moving {arch_dir7}", file=sys.stderr + ) + else: + shutil.move(arch_dir7, arch_dir9) + elif os.path.exists(arch_dir7_upper): + if os.path.exists(arch_dir9): + print( + f"Warning: {arch_dir9} exist ! not moving {arch_dir7_upper}", + file=sys.stderr, + ) + else: + shutil.move(arch_dir7_upper, arch_dir9)