From 1741e75f72202a2abf0c0d3908cd086275f56c3a Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 24 Sep 2021 20:35:50 +0200 Subject: [PATCH 1/4] formation_delete sans REQUESt --- app/scodoc/sco_edit_formation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index 0726bee00..360814d83 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -47,7 +47,7 @@ from app.scodoc import sco_formsemestre from app.scodoc import sco_news -def formation_delete(formation_id=None, dialog_confirmed=False, REQUEST=None): +def formation_delete(formation_id=None, dialog_confirmed=False): """Delete a formation""" F = sco_formations.formation_list(args={"formation_id": formation_id}) if not F: From 81df68b4912a321c43ea91aed873fde383e24cf5 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 25 Sep 2021 09:07:05 +0200 Subject: [PATCH 2/4] fix suffix processing --- app/scodoc/sco_archives_etud.py | 1 - app/scodoc/sco_groups_view.py | 2 +- app/scodoc/sco_prepajury.py | 2 +- app/scodoc/sco_recapcomplet.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/scodoc/sco_archives_etud.py b/app/scodoc/sco_archives_etud.py index 0ea44268c..f9a70f2d4 100644 --- a/app/scodoc/sco_archives_etud.py +++ b/app/scodoc/sco_archives_etud.py @@ -272,7 +272,6 @@ def etudarchive_generate_excel_sample(group_id=None, REQUEST=None): suffix=scu.XLSX_SUFFIX, mime=scu.XLSX_MIMETYPE, ) - # return sco_excel.send_excel_file(REQUEST, data, "ImportFichiersEtudiants" + scu.XLSX_SUFFIX) def etudarchive_import_files_form(group_id, REQUEST=None): diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index f4a4d9ebf..ebab7ec66 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -786,7 +786,7 @@ def groups_table( L = [dicttakestr(m, keys) for m in groups_infos.members] title = "etudiants_%s" % groups_infos.groups_filename xls = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title) - filename = title + scu.XLSX_SUFFIX + filename = title return scu.send_file(xls, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE) else: raise ValueError("unsupported format") diff --git a/app/scodoc/sco_prepajury.py b/app/scodoc/sco_prepajury.py index 4cee94092..084e311c7 100644 --- a/app/scodoc/sco_prepajury.py +++ b/app/scodoc/sco_prepajury.py @@ -328,7 +328,7 @@ def feuille_preparation_jury(formsemestre_id, REQUEST): xls = ws.generate() return scu.send_file( xls, - f"PrepaJury{sn}{scu.XLSX_SUFFIX}", + f"PrepaJury{sn}", scu.XLSX_SUFFIX, mime=scu.XLSX_MIMETYPE, ) diff --git a/app/scodoc/sco_recapcomplet.py b/app/scodoc/sco_recapcomplet.py index 9780821ef..b788702f2 100644 --- a/app/scodoc/sco_recapcomplet.py +++ b/app/scodoc/sco_recapcomplet.py @@ -231,7 +231,7 @@ def do_formsemestre_recapcomplet( return data elif format == "csv": return scu.send_file(data, filename=filename, mime=scu.CSV_MIMETYPE) - elif format[:3] == "xls" or format[:3] == "xlsx": + elif format[:3] == "xls" or format[:4] == "xlsx": return scu.send_file(data, filename=filename, mime=scu.XLSX_MIMETYPE) elif format == "json": js = json.dumps(data, indent=1, cls=scu.ScoDocJSONEncoder) From cb03cc962c88ee402f72efc0d5d70c33639ed11f Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 25 Sep 2021 09:13:39 +0200 Subject: [PATCH 3/4] Scripts save/restore --- app/scodoc/sco_utils.py | 2 +- tools/restore_scodoc9_data.sh | 87 +++++++++++++++++++++++++++++++++++ tools/save_scodoc9_data.sh | 51 ++++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 tools/restore_scodoc9_data.sh create mode 100644 tools/save_scodoc9_data.sh diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 6efdd7d49..63e638787 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -229,7 +229,7 @@ SCODOC_CFG_DIR = os.path.join(Config.SCODOC_VAR_DIR, "config") SCODOC_VERSION_DIR = os.path.join(SCODOC_CFG_DIR, "version") # ----- Repertoire tmp : /opt/scodoc-data/tmp SCO_TMP_DIR = os.path.join(Config.SCODOC_VAR_DIR, "tmp") -if not os.path.exists(SCO_TMP_DIR): +if not os.path.exists(SCO_TMP_DIR) and os.path.exists(Config.SCODOC_VAR_DIR): os.mkdir(SCO_TMP_DIR, 0o755) # ----- Les logos: /opt/scodoc-data/config/logos SCODOC_LOGOS_DIR = os.path.join(SCODOC_CFG_DIR, "logos") diff --git a/tools/restore_scodoc9_data.sh b/tools/restore_scodoc9_data.sh new file mode 100644 index 000000000..5bcc3566a --- /dev/null +++ b/tools/restore_scodoc9_data.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# +# ScoDoc: restore data (saved by save_scodoc9_data) into current install +# +# Utile pour migrer ScoDoc 9 d'un serveur a un autre +# A executer en tant que root sur le nouveau serveur +# +# E. Viennet, Sept 2021 +# +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "$SCRIPT_DIR/config.sh" +source "$SCRIPT_DIR/utils.sh" + +# Ce script doit tourner comme "root" +check_uid_root "$0" + + +# Usage +if [ ! $# -eq 2 ] +then + echo "Usage: $0 archive dbname" + echo "Exemple: $0 /tmp/mon-scodoc.tgz SCODOC" + exit 1 +fi + +SRC=$1 +DBNAME=$2 + + +# Safety check +echo "Ce script va remplacer les donnees de votre installation ScoDoc par celles" +echo "enregistrees dans le fichier fourni." +echo "Ce fichier doit avoir ete cree par le script save_scodoc9_data.sh." +echo +echo "Attention: TOUTES LES DONNEES DE CE SCODOC SERONT REMPLACEES !" +echo "Notamment, tous les utilisateurs et departements existants seront effaces !" +echo +echo "La base SQL $DBNAME sera effacée et remplacée !!!" +echo +echo -n "Voulez vous poursuivre cette operation ? (y/n) [n]" +read -r ans +if [ ! "$(norm_ans "$ans")" = 'Y' ] +then + echo "Annulation" + exit 1 +fi + +# -- Stop ScoDoc +echo "Arrêt de scodoc9..." +systemctl stop scodoc9 + +# Clear caches +echo "Purge des caches..." +su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask clear-cache)" "$SCODOC_USER" || die "Erreur purge cache scodoc9" + +# Déplace scodoc-data s'il existe +if [ -e "$SCODOC_VAR_DIR" ] +then + echo "$SCODOC_VAR_DIR existe: le renomme en .old" + mv "$SCODOC_VAR_DIR" "$SCODOC_VAR_DIR".old || die "Erreur renommage scodoc-data" +fi + +# -- Ouverture archive +echo "Ouverture archive $SRC..." +(cd $(dirname "$SCODOC_VAR_DIR"); tar xfz "$SRC") || die "Error opening archive" + +# -- Ckeck/fix owner +echo "Vérification du propriétaire..." +chown -R "${SCODOC_USER}:${SCODOC_GROUP}" "${SCODOC_VAR_DIR}" || die "Error chowning ${SCODOC_VAR_DIR}" + +# --- La base SQL: nommée $(db_name).dump +nb=$(su -c "psql -l" "$SCODOC_USER" | awk '{print $1}' | grep -c -e '^'"$DBNAME"'$') +if [ "$nb" -gt 0 ] +then + echo "Suppression de la base $DBNAME..." + su -c "dropdb $DBNAME" "$SCODOC_USER" || die "Erreur destruction db" +fi +su -c "createdb $DBNAME" "$SCODOC_USER" || die "Erreur destruction db" + +echo "Chargement de la base SQL..." +su -c "pg_restore -d $DBNAME ${SCODOC_VAR_DIR}/SCODOC.dump" "$SCODOC_USER" || die "Erreur chargement de la base SQL" + +# -- Start ScoDoc +systemctl start scodoc9 + +echo "Terminé." diff --git a/tools/save_scodoc9_data.sh b/tools/save_scodoc9_data.sh new file mode 100644 index 000000000..faaa75e0b --- /dev/null +++ b/tools/save_scodoc9_data.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# +# ScoDoc: save all user data (database, configs, images, archives...) in separate directory +# +# Utile pour migrer ScoDoc version 9 (et plus) d'un serveur a un autre +# Executer en tant que scodoc sur le serveur d'origine. +# Utiliser - pour sortir sur la sortie standard (eg pipe dans ssh...) +# +# E. Viennet, Sept 2011, Aug 2020, Aug 21 +# + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "$SCRIPT_DIR/config.sh" +source "$SCRIPT_DIR/utils.sh" + +if [ "$(id -nu)" != "$SCODOC_USER" ] +then + echo "$0: script must be runned as user $SCODOC_USER" + exit 1 +fi + +echo "Ce script est utile pour transférer toutes les données d'un serveur ScoDoc 9" +echo "à un autre ScoDoc 9." +echo "Il est vivement recommandé de mettre à jour votre ScoDoc avant." +echo "" +echo -n "Voulez-vous poursuivre cette sauvegarde ? (y/n) [n]" +read -r ans +if [ ! "$(norm_ans "$ans")" = 'Y' ] +then + echo "Annulation" + exit 1 +fi + +# Destination +if [ ! $# -eq 1 ] +then + echo "Usage: $0 destination_file" + echo "(- sort sur stdout)" + echo "Exemple: $0 /tmp/mon-scodoc.tgz" + exit 1 +fi +DEST=$1 +db_name="$SCODOC_DB_PROD" # SCODOC + +# dump dans /opt/scodoc-data/SCODOC.dump +pg_dump --format=custom --file="$SCODOC_VAR_DIR/$db_name.dump" "$db_name" || die "Error dumping database" + +# tar scodoc-data vers le fichier indiqué ou stdout +(cd $(dirname "$SCODOC_VAR_DIR"); tar cfz "$DEST" $(basename "$SCODOC_VAR_DIR")) || die "Error archiving data" + From f1660e12e118a0de49919e3e995eec57413d1ba3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 25 Sep 2021 09:13:56 +0200 Subject: [PATCH 4/4] version --- sco_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sco_version.py b/sco_version.py index 659247449..260c56958 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.0.36" +SCOVERSION = "9.0.37" SCONAME = "ScoDoc"