瀏覽代碼

adaptions for ansible: init_venv + config template to jinja2

master
Dirk Alders 8 月之前
父節點
當前提交
6ee34a3ee6
共有 2 個文件被更改,包括 24 次插入8 次删除
  1. 4
    4
      config_example/config.j2
  2. 20
    4
      init_venv

config_example/config.py → config_example/config.j2 查看文件

@@ -5,10 +5,10 @@ import report
5 5
 
6 6
 __BASEPATH__ = os.path.abspath(os.path.dirname(__file__))
7 7
 
8
-MQTT_SERVER = "<mqtt_smarthome_hostname>"
9
-MQTT_USER = "<mqtt_smarthome_username>"
10
-MQTT_PASS = "<mqtt_smarthome_password>"
11
-MQTT_TOPIC = "<mqtt_ambient_info_topic>"
8
+MQTT_SERVER = "{{ smart_sat_ambientinfo_hostname }}"
9
+MQTT_USER = "{{ smart_sat_ambientinfo_username }}"
10
+MQTT_PASS = "{{ smart_sat_ambientinfo_password }}"
11
+MQTT_TOPIC = "{{ smart_sat_ambientinfo_topic }}"
12 12
 
13 13
 DAT_PATH_DHT = None     # os.path.join(__BASEPATH__, 'dat', 'dht')
14 14
 DAT_PATH_BMP = None     # os.path.join(__BASEPATH__, 'dat', 'bmp')

+ 20
- 4
init_venv 查看文件

@@ -2,7 +2,23 @@
2 2
 #
3 3
 BASEPATH=`realpath $(dirname $0)`
4 4
 
5
-python3 -m venv $BASEPATH/venv
6
-$BASEPATH/venv/bin/pip install --upgrade pip
7
-find $BASEPATH -name requirements.txt | xargs -L 1 $BASEPATH/venv/bin/pip install -r
8
-$BASEPATH/venv/bin/pip list --outdated --format=json | jq -r '.[] | .name'|xargs -n1 $BASEPATH/venv/bin/pip install -U
5
+#
6
+# Create venv
7
+#
8
+if [[ ! -e $BASEPATH/venv ]]; then
9
+    python3 -m venv $BASEPATH/venv > /dev/null 2>&1
10
+    # $BASEPATH/venv/bin/pip install --upgrade pip
11
+    find $BASEPATH -name requirements.txt | xargs -L 1 $BASEPATH/venv/bin/pip install -r > /dev/null 2>&1
12
+    echo "venv changed"
13
+fi
14
+#
15
+# Update venv modules
16
+#
17
+for req_mod in $($BASEPATH/venv/bin/pip list --format=json | jq -r '.[] | .name'); do
18
+     $BASEPATH/venv/bin/pip install -U $req_mod | grep install > /dev/null 2>&1
19
+     if [[ "$?" -eq "0" ]]; then
20
+         echo $req_mod changed
21
+     fi
22
+
23
+done
24
+#|xargs -n1 $BASEPATH/venv/bin/pip install -U

Loading…
取消
儲存