From 58e501afc94ceee6b2bbcd877cddc0a6052e9625 Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Tue, 25 Jun 2019 15:40:29 +1200 Subject: [PATCH] check_requirements.sh: improve output for cron usage For running this script in a cron job we want to see just the interesting output since that will be sent as an email, so make the following changes: * Silence the normal output of virtualenv and pip * Add a -q option for the script to silence progress messages Signed-off-by: Paul Eggleton --- check_requirements.sh | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/check_requirements.sh b/check_requirements.sh index b4f8cb4..8a4914c 100644 --- a/check_requirements.sh +++ b/check_requirements.sh @@ -14,27 +14,49 @@ fi set -e +if [ "$1" = "-q" ] ; then + quiet="1" +elif [ "$1" = "" ] ; then + quiet="0" +else + echo "Invalid option: $1" + exit 1 +fi + +vecho() +{ + if [ "$quiet" = "0" ] ; then + echo "$@" + fi +} + + tmpdir=`mktemp -d` -virtualenv -p python3 $tmpdir +vecho "Setting up virtual environment" +virtualenv -q -p python3 $tmpdir . $tmpdir/bin/activate -pip install -r requirements.txt +pip install -q -r requirements.txt newreqs="requirements.txt.updated" -echo "Creating $newreqs" +vecho "Creating $newreqs" pip freeze > $newreqs newreqsdiff="requirements.txt.diff" -echo "Creating $newreqsdiff" +vecho "Creating $newreqsdiff" diff -udN requirements.txt $newreqs > $newreqsdiff || true outdated="outdated.txt" -echo "Creating $outdated" +vecho "Creating $outdated" pip list --outdated > $outdated -pip install pipdeptree +pip install -q pipdeptree deptree="deptree.txt" -echo "Creating $deptree" +vecho "Creating $deptree" pipdeptree > $deptree -pip install safety +pip install -q safety safety="safety_check.txt" -echo "Running safety check (output also to $safety)" +vecho "Running safety check (output also to $safety)" safety check | tee $safety +echo +echo "Outdated components:" +echo +cat $outdated deactivate rm -rf $tmpdir