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 00000000..9479c828 --- /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 00000000..55acd842 --- /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")