Restruct files, prepare for next feature
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[program:poo_recorder_backend]
|
[program:home_automation_backend]
|
||||||
environment=PYTHONUNBUFFERED=1
|
environment=PYTHONUNBUFFERED=1
|
||||||
command=
|
command=
|
||||||
directory=
|
directory=
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
# Argument parsing
|
# Argument parsing
|
||||||
if [[ $# -ne 1 ]]; then
|
if [[ $# -ne 1 ]]; then
|
||||||
echo "Usage: $0 [--install|--uninstall|--help]"
|
echo "Usage: $0 [--install|--uninstall|--help]"
|
||||||
echo " --install Install the poo recorder"
|
echo " --install Install the automation backend"
|
||||||
echo " --uninstall Uninstall the poo recorder"
|
echo " --uninstall Uninstall the automation backend"
|
||||||
echo " --update Update the installation"
|
echo " --update Update the installation"
|
||||||
echo " --help Show this help message"
|
echo " --help Show this help message"
|
||||||
exit 0
|
exit 0
|
||||||
@@ -22,9 +22,10 @@ case $key in
|
|||||||
UPDATE=true
|
UPDATE=true
|
||||||
;;
|
;;
|
||||||
--help)
|
--help)
|
||||||
echo "Usage: $0 [--install|--uninstall|--help]"
|
echo "Usage: $0 [--install|--uninstall|--update|--help]"
|
||||||
echo " --install Install the poo recorder"
|
echo " --install Install the automation backend"
|
||||||
echo " --uninstall Uninstall the poo recorder"
|
echo " --uninstall Uninstall the automation backend"
|
||||||
|
echo " --update Update the installation"
|
||||||
echo " --help Show this help message"
|
echo " --help Show this help message"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
@@ -34,68 +35,69 @@ case $key in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
TARGET_DIR="$HOME/.local/poo-recorder"
|
TARGET_DIR="$HOME/.local/home-automation-backend"
|
||||||
|
SUPERVISOR_CFG_NAME="home_automation_backend"
|
||||||
|
SUPERVISOR_CFG="$SUPERVISOR_CFG_NAME.conf"
|
||||||
BASEDIR=$(dirname "$0")
|
BASEDIR=$(dirname "$0")
|
||||||
|
|
||||||
# Install or uninstall based on arguments
|
# Install or uninstall based on arguments
|
||||||
install_poo_recorder() {
|
install_backend() {
|
||||||
# Installation code here
|
# Installation code here
|
||||||
echo "Installing..."
|
echo "Installing..."
|
||||||
|
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install python3 python3-venv supervisor
|
sudo apt install python3 python3-venv supervisor
|
||||||
|
|
||||||
sudo supervisorctl stop poo_recorder_backend
|
sudo supervisorctl stop $SUPERVISOR_CFG_NAME
|
||||||
|
|
||||||
mkdir -p $TARGET_DIR
|
mkdir -p $TARGET_DIR
|
||||||
|
|
||||||
rm -rf $BASEDIR/../recorder/__pycache__
|
rm -rf `find $BASEDIR/../src -type d -name __pycache__`
|
||||||
cp -r $BASEDIR/../recorder $BASEDIR/../requirements.txt $TARGET_DIR
|
cp -r $BASEDIR/../src $BASEDIR/../requirements.txt $TARGET_DIR
|
||||||
|
|
||||||
python3 -m venv "$TARGET_DIR/venv"
|
python3 -m venv "$TARGET_DIR/venv"
|
||||||
|
|
||||||
$TARGET_DIR/venv/bin/pip install -r $TARGET_DIR/requirements.txt
|
$TARGET_DIR/venv/bin/pip install -r $TARGET_DIR/requirements.txt
|
||||||
|
|
||||||
cp $BASEDIR/poo_recorder_template.conf $BASEDIR/poo_recorder.conf
|
cp $BASEDIR/"$SUPERVISOR_CFG_NAME"_template.conf $BASEDIR/$SUPERVISOR_CFG
|
||||||
|
|
||||||
sed -i "s+command=+command=$TARGET_DIR/venv/bin/fastapi run $TARGET_DIR/recorder/main.py --port 8881+g" $BASEDIR/poo_recorder.conf
|
sed -i "s+command=+command=$TARGET_DIR/venv/bin/fastapi run $TARGET_DIR/src/main.py --port 8881+g" $BASEDIR/$SUPERVISOR_CFG
|
||||||
sed -i "s+directory=+directory=$TARGET_DIR+g" $BASEDIR/poo_recorder.conf
|
sed -i "s+directory=+directory=$TARGET_DIR+g" $BASEDIR/$SUPERVISOR_CFG
|
||||||
sed -i "s+user=+user=$USER+g" $BASEDIR/poo_recorder.conf
|
sed -i "s+user=+user=$USER+g" $BASEDIR/$SUPERVISOR_CFG
|
||||||
sed -i "s+group=+group=$USER+g" $BASEDIR/poo_recorder.conf
|
sed -i "s+group=+group=$USER+g" $BASEDIR/$SUPERVISOR_CFG
|
||||||
|
|
||||||
sudo mv $BASEDIR/poo_recorder.conf /etc/supervisor/conf.d/poo_recorder.conf
|
sudo mv $BASEDIR/$SUPERVISOR_CFG /etc/supervisor/conf.d/$SUPERVISOR_CFG
|
||||||
|
|
||||||
sudo supervisorctl reread
|
sudo supervisorctl reread
|
||||||
sudo supervisorctl update
|
sudo supervisorctl update
|
||||||
sudo supervisorctl start poo_recorder_backend
|
sudo supervisorctl start $SUPERVISOR_CFG_NAME
|
||||||
|
|
||||||
echo "Installation complete."
|
echo "Installation complete."
|
||||||
}
|
}
|
||||||
uninstall_poo_recorder() {
|
uninstall_backend() {
|
||||||
# Uninstallation code here
|
# Uninstallation code here
|
||||||
echo "Uninstalling..."
|
echo "Uninstalling..."
|
||||||
|
|
||||||
sudo supervisorctl stop poo_recorder_backend
|
sudo supervisorctl stop $SUPERVISOR_CFG_NAME
|
||||||
|
|
||||||
sudo supervisorctl remove poo_recorder_backend
|
sudo supervisorctl remove $SUPERVISOR_CFG_NAME
|
||||||
|
|
||||||
sudo rm /etc/supervisor/conf.d/poo_recorder.conf
|
sudo rm /etc/supervisor/conf.d/$SUPERVISOR_CFG
|
||||||
|
|
||||||
rm -rf $TARGET_DIR
|
rm -rf $TARGET_DIR
|
||||||
|
|
||||||
echo "Uninstallation complete."
|
echo "Uninstallation complete."
|
||||||
}
|
}
|
||||||
update_poo_recorder() {
|
update_backend() {
|
||||||
uninstall_poo_recorder
|
uninstall_backend
|
||||||
install_poo_recorder
|
install_backend
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $INSTALL ]]; then
|
if [[ $INSTALL ]]; then
|
||||||
install_poo_recorder
|
install_backend
|
||||||
elif [[ $UNINSTALL ]]; then
|
elif [[ $UNINSTALL ]]; then
|
||||||
uninstall_poo_recorder
|
uninstall_backend
|
||||||
elif [[ $UPDATE ]]; then
|
elif [[ $UPDATE ]]; then
|
||||||
update_poo_recorder
|
update_backend
|
||||||
else
|
else
|
||||||
echo "Invalid argument: $key"
|
echo "Invalid argument: $key"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
0
src/cloud_util/__init__.py
Normal file
0
src/cloud_util/__init__.py
Normal file
7
src/config.py
Normal file
7
src/config.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
NOTION_TOKEN = os.getenv("NOTION_TOKEN")
|
||||||
@@ -2,7 +2,7 @@ from contextlib import asynccontextmanager
|
|||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from recorder.poo import PooRecorder
|
from src.recorder.poo import PooRecorder
|
||||||
|
|
||||||
recorder = PooRecorder()
|
recorder = PooRecorder()
|
||||||
|
|
||||||
0
src/recorder/__init__.py
Normal file
0
src/recorder/__init__.py
Normal file
@@ -1,14 +1,13 @@
|
|||||||
import os
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
from notion_client import AsyncClient as Client
|
from notion_client import AsyncClient as Client
|
||||||
|
|
||||||
|
from src.config import NOTION_TOKEN
|
||||||
|
|
||||||
|
|
||||||
class NotionClient:
|
class NotionClient:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
load_dotenv()
|
self._notion = Client(auth=NOTION_TOKEN)
|
||||||
self._notion = Client(auth=os.environ["NOTION_TOKEN"])
|
|
||||||
self._page_id = "3cf594afd0754497ba0a93b94912b897"
|
self._page_id = "3cf594afd0754497ba0a93b94912b897"
|
||||||
self._table_id = "9828b56c53de46c794673fe1d01ad522"
|
self._table_id = "9828b56c53de46c794673fe1d01ad522"
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from fastapi_mqtt import FastMQTT, MQTTConfig
|
from fastapi_mqtt import FastMQTT, MQTTConfig
|
||||||
|
|
||||||
from recorder.notion_handle import NotionClient
|
from src.recorder.notion_handle import NotionClient
|
||||||
|
|
||||||
|
|
||||||
class PooRecorder:
|
class PooRecorder:
|
||||||
@@ -60,7 +60,7 @@ class PooRecorder:
|
|||||||
"device": {
|
"device": {
|
||||||
"name": "Dog Poop Recorder",
|
"name": "Dog Poop Recorder",
|
||||||
"model": "poop-recorder-backend",
|
"model": "poop-recorder-backend",
|
||||||
"sw_version": "1.0",
|
"sw_version": "1.1",
|
||||||
"identifiers": ["poo_recorder"],
|
"identifiers": ["poo_recorder"],
|
||||||
"manufacturer": "Studio TJ",
|
"manufacturer": "Studio TJ",
|
||||||
},
|
},
|
||||||
Reference in New Issue
Block a user