From af047f91c57aee386f5a500817c32edccab5c55a Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 17 Aug 2025 15:53:33 +0200 Subject: [PATCH] Adaption to DEBUG application and new Makefile concept --- .venv_required | 0 Makefile | 103 +++++++++++++++++++++++++++++++++++++++ __make.d__/config.mk | 16 ++++++ ambient_info.py | 3 -- config_example/config.j2 | 6 ++- init_venv | 24 --------- requirements.txt | 2 - rpi_envsens | 2 +- 8 files changed, 124 insertions(+), 32 deletions(-) create mode 100644 .venv_required create mode 100644 Makefile create mode 100644 __make.d__/config.mk delete mode 100755 init_venv delete mode 100644 requirements.txt diff --git a/.venv_required b/.venv_required new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a2417f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,103 @@ +# git helper Makefile: Version 2.2 (2025-08-10) +default: help + +.ONESHELL: +SHELL = /usr/bin/bash +MAKEFLAGS += --no-print-directory +.SILENT: + +-include __make.d__/*.mk + +GIT_FLAG = ./.git +VENV_FLAG = ./.venv_required +VENV_FOLDER = ./venv + +localhelp: + +help: + echo "Possible common options are:" + echo " - init - Initialise the repository and all folders below with a Makefile" + echo " - giti - Get the git status of all submodules including their submodules" + echo " - update_submodules - Set all submodules to remote master" + echo " - venv_flag - Set the venev flag for the base folder. A venv will be generated" + echo " - clean - clean up" + echo " - deepclean - clean up this and all Makefiles below" + $(MAKE) localhelp + echo "You are able to create files make.d/*.mk and add local rules there. " + echo " - localinit: print_head - Will be executed as last step in the init process." + echo " - localhelp: print_head - Will be executed in th middle of the help text generation" + echo " - localclean:print_head - Will be executed before the clean rule" + +localinit: + +init: print_head + # Init git repo + if [[ -e $(GIT_FLAG) ]]; then + echo -e "\033[1;33mInitialising git submodules...\e[0m" + git submodule init + git submodule update + fi + # Init submodules + SUBDIRS=$$(find . -maxdepth 2 -mindepth 2 -name Makefile | sort) + for subdir in $$SUBDIRS; do + $(MAKE) --no-print-directory -C $$(dirname $$subdir) init + done + if [[ $$SUBDIRS ]]; then + $(MAKE) print_head + fi + # Create venv if needed + if [[ -e $(VENV_FLAG) ]]; then + if [[ ! -e $(VENV_FOLDER) ]]; then + echo -e "\033[1;33mCreating virtual env...\e[0m" + mkvenv + fi + fi + # Start local init + echo -e "\033[1;33mDoing localinit...\e[0m" + $(MAKE) localinit + +update_submodules: + git submodule foreach "git fetch && git checkout master && git pull && git submodule init && git submodule update" + +giti_this: print_head + giti + echo " Submodules:" + git submodule --quiet foreach "echo -n ' ' && giti" + +giti: + git submodule --quiet foreach "[ -e Makefile ] && make --no-print-directory giti_this || :" + +localclean: + +clean: localclean + if [[ ! -e $(VENV_FLAG) ]]; then + if [[ -d $(VENV_FOLDER) ]]; then + rm -rf $(VENV_FOLDER) + fi + fi + +cleanall: clean + for subdir in $$(find . -maxdepth 2 -mindepth 2 -name Makefile | sort); do + $(MAKE) --no-print-directory -C $$(dirname $$subdir) cleanall + done + + +venv_flag: + if [[ ! -e $(VENV_FLAG) ]]; then + touch $(VENV_FLAG) + if [[ -e $(GIT_FLAG) ]]; then + git add $(VENV_FLAG) + fi + fi + +print_head: + DIRNAME=$$(basename $$(pwd)) + DIRLENGTH=$${#DIRNAME} + echo -ne "\n\n\033[1;34m╔═" + for i in $$(seq 1 $$DIRLENGTH); do echo -n "═"; done + echo -e "═╗" + echo -e "║ $$DIRNAME ║" + echo -ne "╚═" + for i in $$(seq 1 $$DIRLENGTH); do echo -n "═"; done + echo -e "═╝\033[00m" + diff --git a/__make.d__/config.mk b/__make.d__/config.mk new file mode 100644 index 0000000..d339ca9 --- /dev/null +++ b/__make.d__/config.mk @@ -0,0 +1,16 @@ +.ONESHELL: +SHELL = /usr/bin/bash +MAKEFLAGS += --no-print-directory +.SILENT: + +devinit: + if [[ ! -e config.py ]]; then + cp config_example/config.j2 config.py + chmod 600 config.py + sed -i "/^DEBUG.*=.*/c\DEBUG = True" config.py + sed -i 's/{{ smart_sat_ambientinfo_hostname }}/localhost/' config.py + sed -i 's/"{{ smart_sat_ambientinfo_username }}"/None/' config.py + sed -i 's/"{{ smart_sat_ambientinfo_password }}"/None/' config.py + sed -i 's/{{ smart_sat_ambientinfo_topic }}/ambient_info/' config.py + fi + diff --git a/ambient_info.py b/ambient_info.py index ac3200e..96ddf22 100644 --- a/ambient_info.py +++ b/ambient_info.py @@ -1,8 +1,5 @@ import config -import logging import mqtt -import paho.mqtt.client as paho -import socket import report import time diff --git a/config_example/config.j2 b/config_example/config.j2 index b993ed5..97aa0bb 100644 --- a/config_example/config.j2 +++ b/config_example/config.j2 @@ -33,5 +33,7 @@ except ImportError: USE_PULSE_IO = True else: # DHT-PORT - DHT_22_PORT = board.D4 - + try: + DHT_22_PORT = board.D4 + except AttributeError: + DHT_22_PORT = None # This results in DEBUG-Mode diff --git a/init_venv b/init_venv deleted file mode 100755 index 9f00515..0000000 --- a/init_venv +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# -BASEPATH=`realpath $(dirname $0)` - -# -# 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 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a535607..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -adafruit-circuitpython-dht -smbus diff --git a/rpi_envsens b/rpi_envsens index 2ffcdf2..2393316 160000 --- a/rpi_envsens +++ b/rpi_envsens @@ -1 +1 @@ -Subproject commit 2ffcdf2d59b5621b46973b16130e410ba146c949 +Subproject commit 2393316bc765a3f3bab987517aa5c3e92001987b