From a8b4ef2a22e8000435a3db9a24c63b52f1acab26 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 20 Nov 2022 11:36:06 +0100 Subject: [PATCH] Adaptation du script diagnostic.sh pour ScoDoc 9 --- sco_version.py | 2 +- scodoc.py | 17 ++++++++++++----- tools/diagnostic.sh | 16 +++------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/sco_version.py b/sco_version.py index b3cff8af..a32fca6b 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.4.4" +SCOVERSION = "9.4.5" SCONAME = "ScoDoc" diff --git a/scodoc.py b/scodoc.py index 2b00d2bf..e8839f78 100755 --- a/scodoc.py +++ b/scodoc.py @@ -358,8 +358,14 @@ def abort_if_false(ctx, param, value): Voulez-vous vraiment continuer ? """, ) +@click.option( + "-f", + "--force", + is_flag=True, + help="ignore non-existing departement", +) @click.argument("dept") -def delete_dept(dept): # delete-dept +def delete_dept(dept, force=False): # delete-dept """Delete existing departement""" from app.scodoc import notesdb as ndb from app.scodoc import sco_dept @@ -367,11 +373,12 @@ def delete_dept(dept): # delete-dept db.reflect() ndb.open_db_connection() d = models.Departement.query.filter_by(acronym=dept).first() - if d is None: + if d is None and not force: sys.stderr.write(f"Erreur: le departement {dept} n'existe pas !\n") return 2 - sco_dept.delete_dept(d.id) - db.session.commit() + elif d: + sco_dept.delete_dept(d.id) + db.session.commit() return 0 @@ -402,7 +409,7 @@ def list_depts(depts=""): # list-depts help="show database name instead of connexion string (required for " "dropdb/createdb commands)", ) -def scodoc_database(name): # list-dept +def scodoc_database(name): # scodoc-database """print the database connexion string""" uri = app.config["SQLALCHEMY_DATABASE_URI"] if name: diff --git a/tools/diagnostic.sh b/tools/diagnostic.sh index 7bce736e..0354f129 100755 --- a/tools/diagnostic.sh +++ b/tools/diagnostic.sh @@ -40,7 +40,6 @@ while getopts "anh" opt; do echo " -h cette aide" echo " -n pas d'envoi par mail" echo " -a enregistre la bases de donnees (prod)" - echo " -u enregistre la base utilisateurs" exit 0 ;; \?) @@ -68,7 +67,7 @@ fi mkdir "$TMP" # Files to copy: -FILES="/etc/hosts /etc/debian_version /etc/apt /etc/apache2 $SCODOC_DIR/VERSION $SCODOC_VAR_DIR/config" +FILES="/etc/hosts /etc/debian_version /etc/apt /etc/nginx /etc/postfix $SCODOC_DIR/sco_version.py $SCODOC_VAR_DIR/config" echo "ScoDoc diagnostic: informations about your system will be " @@ -97,10 +96,6 @@ ps auxww > "$TMP"/ps.out df -h > "$TMP"/df.out dpkg -l > "$TMP"/dpkg.lst -(cd "$SCODOC_DIR"; git status > "$TMP"/git.status) -(cd "$SCODOC_DIR"; git diff > "$TMP"/git.diff) - -(cd "$SCODOC_DIR"; git log -n 5 > "$TMP"/git.log) ls -laR "$SCODOC_DIR" > "$TMP"/ls-laR @@ -111,7 +106,7 @@ ls -laR "$SCODOC_DIR" > "$TMP"/ls-laR for db in "$SCODOC_DB_PROD" "$SCODOC_DB_DEV" do - (su postgres -c "echo '\dt' | psql $db") > "${TMP}/psql-$db).out" + (su postgres -c "echo '\dt' | psql $db") > "${TMP}/psql-$db.out" done @@ -132,17 +127,12 @@ done # Optionally save database # ------------------------------------- -# Dump database -function dump_db { - -} - if [ "${SAVE_DB}" = "1" ] then for db in "$SCODOC_DB_PROD" "$SCODOC_DB_DEV" do echo "Dumping database ${db}..." - pg_dump --create "${db}") | gzip > "${TMP}/${db}.dump.gz" + su -c "pg_dump --create ${db}" postgres | gzip > "${TMP}/${db}.dump.gz" # may add archives ? (no, probably too big) done fi