1
0
forked from ScoDoc/ScoDoc

migration des logos_dept scodoc7 -> scodoc9

This commit is contained in:
Jean-Marie Place 2021-11-14 10:33:37 +01:00
parent df3439351d
commit 51506c6d6f
4 changed files with 66 additions and 0 deletions

View File

@ -22,6 +22,7 @@ from app import models
from app.auth.models import User, Role, UserRole from app.auth.models import User, Role, UserRole
from app.models import ScoPreference from app.models import ScoPreference
from app.scodoc.sco_logos import make_logo_local
from app.models import Formation, UniteEns, Module from app.models import Formation, UniteEns, Module
from app.models import FormSemestre, FormsemestreInscription from app.models import FormSemestre, FormsemestreInscription
from app.models import ModuleImpl, ModuleImplInscription from app.models import ModuleImpl, ModuleImplInscription
@ -340,6 +341,14 @@ def migrate_scodoc7_dept_archives(dept: str): # migrate-scodoc7-dept-archives
tools.migrate_scodoc7_dept_archives(dept) tools.migrate_scodoc7_dept_archives(dept)
@app.cli.command()
@click.argument("dept", default="")
@with_appcontext
def migrate_scodoc7_dept_logos(dept: str = ""): # migrate-scodoc7-dept-logos
"""Post-migration: renomme les logos en fonction des id / dept de ScoDoc 9"""
tools.migrate_scodoc7_dept_logos(dept)
@app.cli.command() @app.cli.command()
@click.argument("formsemestre_id", type=click.INT) @click.argument("formsemestre_id", type=click.INT)
@click.argument("xlsfile", type=click.File("rb")) @click.argument("xlsfile", type=click.File("rb"))

View File

@ -7,3 +7,4 @@
from tools.import_scodoc7_user_db import import_scodoc7_user_db from tools.import_scodoc7_user_db import import_scodoc7_user_db
from tools.import_scodoc7_dept import import_scodoc7_dept from tools.import_scodoc7_dept import import_scodoc7_dept
from tools.migrate_scodoc7_archives import migrate_scodoc7_dept_archives from tools.migrate_scodoc7_archives import migrate_scodoc7_dept_archives
from tools.migrate_scodoc7_logos import migrate_scodoc7_dept_logos

View File

@ -274,6 +274,9 @@ done
# ----- Post-Migration: renomme archives en fonction des nouveaux ids # ----- Post-Migration: renomme archives en fonction des nouveaux ids
su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask migrate-scodoc7-dept-archives)" "$SCODOC_USER" || die "Erreur de la post-migration des archives" su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask migrate-scodoc7-dept-archives)" "$SCODOC_USER" || die "Erreur de la post-migration des archives"
# ----- Post-Migration: renomme logos en fonction des nouveaux ids
su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask migrate-scodoc7-dept-logos)" || die "Erreur de la post-migration des logos"
# --- Si migration "en place", désactive ScoDoc 7 # --- Si migration "en place", désactive ScoDoc 7
if [ "$INPLACE" == 1 ] if [ "$INPLACE" == 1 ]

View File

@ -0,0 +1,53 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
import glob
import os
import shutil
from app.models import Departement
def migrate_scodoc7_dept_logos(dept_name=""):
if dept_name:
depts = Departement.query.filter_by(acronym=dept_name)
else:
depts = Departement.query
n_dir = 0
n_moves = 0
n_depts = 0
purged_candidates = [] # directory that maybe purged at the end
for dept in depts:
logos_dir7 = f"/opt/scodoc-data/config/logos/logos_{dept.acronym}"
logos_dir9 = f"/opt/scodoc-data/config/logos/logos_{dept.id}"
if os.path.exists(logos_dir7):
print(f"Migrating {dept.acronym} logos...")
purged_candidates.append(logos_dir7)
n_depts += 1
if not os.path.exists(logos_dir9):
# print(f"renaming {logos_dir7} to {logos_dir9}")
shutil.move(logos_dir7, logos_dir9)
n_dir += 1
else:
# print(f"merging {logos_dir7} with {logos_dir9}")
for logo in glob.glob(f"{logos_dir7}/*"):
# print(f"\tmoving {logo}")
fn = os.path.split(logo)[1]
if not os.path.exists(os.path.sep.join([logos_dir9, fn])):
shutil.move(logo, logos_dir9)
n_moves += 1
n_purged = 0
for candidate in purged_candidates:
if len(os.listdir(candidate)) == 0:
os.rmdir(candidate)
n_purged += 1
print(f"{n_depts} department(s) scanned")
if n_dir:
print(f"{n_dir} directory(ies) moved")
if n_moves:
print(f"{n_moves} file(s) moved")
if n_purged:
print(f"{n_purged} scodoc7 logo dir(s) removed")
if n_dir + n_moves + n_purged == 0:
print("nothing done")
# print(f"moved {n_moves}/{n} etuds")