From 80238545f3130c0d2fc440f9782efdbfcd14dc4c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 16 Sep 2021 22:31:47 +0200 Subject: [PATCH] =?UTF-8?q?oups:=20fichiers=20oubli=C3=A9s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...065fb2d20_flag_bloquage_calcul_moyennes.py | 28 ++++++++ tools/migrate_scodoc7_archives.py | 72 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 migrations/versions/669065fb2d20_flag_bloquage_calcul_moyennes.py create mode 100644 tools/migrate_scodoc7_archives.py diff --git a/migrations/versions/669065fb2d20_flag_bloquage_calcul_moyennes.py b/migrations/versions/669065fb2d20_flag_bloquage_calcul_moyennes.py new file mode 100644 index 000000000..9479c8285 --- /dev/null +++ b/migrations/versions/669065fb2d20_flag_bloquage_calcul_moyennes.py @@ -0,0 +1,28 @@ +"""Flag bloquage calcul moyennes + +Revision ID: 669065fb2d20 +Revises: a217bf588f4c +Create Date: 2021-09-16 22:04:11.624632 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '669065fb2d20' +down_revision = 'a217bf588f4c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('notes_formsemestre', sa.Column('block_moyennes', sa.Boolean(), server_default='false', nullable=False)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('notes_formsemestre', 'block_moyennes') + # ### end Alembic commands ### diff --git a/tools/migrate_scodoc7_archives.py b/tools/migrate_scodoc7_archives.py new file mode 100644 index 000000000..55acd8421 --- /dev/null +++ b/tools/migrate_scodoc7_archives.py @@ -0,0 +1,72 @@ +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +import glob +import os +import shutil + +from app.models import Departement +from app.models.formsemestre import FormSemestre +from app.models.etudiants import Identite + + +def migrate_scodoc7_dept_archive(dept_name=""): + if dept_name: + depts = Departement.query.filter_by(acronym=dept_name) + else: + depts = Departement.query + for dept in depts: + print(f"Migrating {dept.acronym} archives...") + # SemsArchiver + # /opt/scodoc-data/archives// -> formsemestre_id + migrate_sem_archives(dept) + + # EtudsArchiver: + migrate_docetuds(dept) + + # ApoCSVArchiver: + # /opt/scodoc-data/archives/apo_csv// ne bouge pas + + +def migrate_sem_archives(dept): + "/opt/scodoc-data/archives// -> formsemestre_id" + n = 0 + n_moves = 0 + 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}" + if os.path.exists(arch_dir7): + n_moves += 1 + if not os.path.exists(arch_dir9): + # print(f"renaming {arch_dir7} to {arch_dir9}") + shutil.move(arch_dir7, arch_dir9) + else: + # print(f"merging {arch_dir7} with {arch_dir9}") + for arch in glob.glob(f"{arch_dir7}/*"): + # print(f"\tmoving {arch}") + shutil.move(arch, arch_dir9) + # print(f"moved {n_moves}/{n} sems") + + +def migrate_docetuds(dept): + "/opt/scodoc-data/archives/docetuds/// -> etudid" + n = 0 + n_moves = 0 + for etud in Identite.query.filter_by(dept_id=dept.id): + n += 1 + 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}" + if os.path.exists(arch_dir7): + n_moves += 1 + if not os.path.exists(arch_dir9): + # print(f"renaming {arch_dir7} to {arch_dir9}") + shutil.move(arch_dir7, arch_dir9) + else: + # print(f"merging {arch_dir7} with {arch_dir9}") + for arch in glob.glob(f"{arch_dir7}/*"): + # print(f"\tmoving {arch}") + shutil.move(arch, arch_dir9) + # print(f"moved {n_moves}/{n} etuds")