Adaptation du script diagnostic.sh pour ScoDoc 9

This commit is contained in:
Emmanuel Viennet 2022-11-20 11:36:06 +01:00
parent c119f58659
commit a8b4ef2a22
3 changed files with 16 additions and 19 deletions

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.4.4"
SCOVERSION = "9.4.5"
SCONAME = "ScoDoc"

View File

@ -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:

View File

@ -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