From 6ee34a3ee625ac0c36a46982fafe5e4df38e94b0 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Tue, 12 Mar 2024 07:23:54 +0100 Subject: [PATCH] adaptions for ansible: init_venv + config template to jinja2 --- config_example/{config.py => config.j2} | 8 ++++---- init_venv | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) rename config_example/{config.py => config.j2} (74%) diff --git a/config_example/config.py b/config_example/config.j2 similarity index 74% rename from config_example/config.py rename to config_example/config.j2 index 2c8c39d..9c9c0d3 100644 --- a/config_example/config.py +++ b/config_example/config.j2 @@ -5,10 +5,10 @@ import report __BASEPATH__ = os.path.abspath(os.path.dirname(__file__)) -MQTT_SERVER = "" -MQTT_USER = "" -MQTT_PASS = "" -MQTT_TOPIC = "" +MQTT_SERVER = "{{ smart_sat_ambientinfo_hostname }}" +MQTT_USER = "{{ smart_sat_ambientinfo_username }}" +MQTT_PASS = "{{ smart_sat_ambientinfo_password }}" +MQTT_TOPIC = "{{ smart_sat_ambientinfo_topic }}" DAT_PATH_DHT = None # os.path.join(__BASEPATH__, 'dat', 'dht') DAT_PATH_BMP = None # os.path.join(__BASEPATH__, 'dat', 'bmp') diff --git a/init_venv b/init_venv index 428ff04..83622c4 100755 --- a/init_venv +++ b/init_venv @@ -2,7 +2,23 @@ # BASEPATH=`realpath $(dirname $0)` -python3 -m venv $BASEPATH/venv -$BASEPATH/venv/bin/pip install --upgrade pip -find $BASEPATH -name requirements.txt | xargs -L 1 $BASEPATH/venv/bin/pip install -r -$BASEPATH/venv/bin/pip list --outdated --format=json | jq -r '.[] | .name'|xargs -n1 $BASEPATH/venv/bin/pip install -U +# +# Create venv +# +if [[ ! -e $BASEPATH/venv ]]; then + python3 -m venv $BASEPATH/venv > /dev/null 2>&1 + # $BASEPATH/venv/bin/pip install --upgrade pip + find $BASEPATH -name requirements.txt | xargs -L 1 $BASEPATH/venv/bin/pip install -r > /dev/null 2>&1 + echo "venv changed" +fi +# +# Update venv modules +# +for req_mod in $($BASEPATH/venv/bin/pip list --format=json | jq -r '.[] | .name'); do + $BASEPATH/venv/bin/pip install -U $req_mod | grep install > /dev/null 2>&1 + if [[ "$?" -eq "0" ]]; then + echo $req_mod changed + fi + +done +#|xargs -n1 $BASEPATH/venv/bin/pip install -U