ScoDocMM/scotests/scointeractive.sh

80 lines
2.0 KiB
Bash
Raw Permalink Normal View History

2020-12-26 00:11:55 +01:00
#!/bin/bash
# Lancement d'un python scodoc interactif
# dans l'environnement d'un département
# et avec chargement des scripts indiqués
# via from ... import *
#
# Si -r est utilisé, veiller à créer au préalable
# le département via l'interface web (Zope)
usage() {
2021-04-23 10:24:45 +02:00
echo "Usage: $0 [-h] [-r] [-x] dept [script...]"
2020-12-26 00:11:55 +01:00
echo "Lance un environnement interactif python/ScoDoc"
echo " -r: supprime et recrée le département (attention: efface la base !)"
2021-04-23 10:24:45 +02:00
echo " -x: exit après exécution des scripts, donc mode non interactif"
2020-12-26 00:11:55 +01:00
exit 1
}
set -euo pipefail
cd /opt/scodoc/Products/ScoDoc || exit 2
source config/config.sh
2020-12-26 00:11:55 +01:00
source config/utils.sh
2021-04-23 10:24:45 +02:00
RECREATE_DEPT=0
PYTHON_INTERACTIVE="-i"
2020-12-26 00:11:55 +01:00
2021-04-23 10:24:45 +02:00
while [ -n "$1" ]; do
PARAM="$1"
[ "${PARAM::1}" != "-" ] && break
case $PARAM in
-h | --help)
usage
exit 0
;;
-r)
RECREATE_DEPT=1
;;
-x)
PYTHON_INTERACTIVE=""
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
2020-12-26 00:11:55 +01:00
shift
2021-04-23 10:24:45 +02:00
done
2020-12-26 00:11:55 +01:00
DEPT="$1"
shift
2021-04-23 10:24:45 +02:00
if [ "$RECREATE_DEPT" = 1 ]
2020-12-26 00:11:55 +01:00
then
cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg
if [ -e "$cfg_pathname" ]
then
(cd config || terminate "no config directory"; ./delete_dept.sh -n "$DEPT") || terminate "error deleting dept $DEPT"
fi
2020-12-26 00:11:55 +01:00
(cd config || terminate "no config directory"; ./create_dept.sh -n "$DEPT") || terminate "error creating dept $DEPT"
2020-12-27 13:45:24 +01:00
# systemctl start scodoc
2020-12-26 00:11:55 +01:00
fi
2021-04-23 10:24:45 +02:00
cmd="from __future__ import print_function;from Zope2 import configure;configure('/opt/scodoc/etc/zope.conf');import Zope2; app=Zope2.app();from debug import *;context = go_dept(app, '""$DEPT""', verbose=False);"
2020-12-26 00:11:55 +01:00
for f in "$@"
do
cmd="${cmd}exec(open(\"${f}\").read());"
done
2021-04-23 10:24:45 +02:00
if [ -z "$PYTHON_INTERACTIVE" ]
then
/opt/zope213/bin/python -c "$cmd"
else
/opt/zope213/bin/python "$PYTHON_INTERACTIVE" -c "$cmd"
fi
2020-12-26 00:11:55 +01:00