Initial commit: Flask battery tracker app

- Flask + SQLAlchemy (MariaDB-compatible schema) battery tracking web app
- 40 pre-seeded batteries (Eneloop, BONAI, Energizer NiMH) across 5 devices
- Business rules: block retired assignment, brand-mix warnings, capacity checks
- Mobile-friendly Jinja2 templates with inline CSS
- waitress WSGI server via systemd user service (sbin/install-service.sh)
- SQLite → MariaDB migration script (migrate_to_mariadb.py)
- 26 passing acceptance tests (pytest + Flask test client)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 22:38:16 -05:00
commit 6ea3eae981
22 changed files with 1689 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
# sbin — Support Scripts
## install-service.sh
Generates a systemd **user-level** service file and enables it. No root required.
**Prerequisites:** The app's `.venv` must exist and have Flask installed.
```bash
bash sbin/install-service.sh
```
You will be prompted for a host (default `127.0.0.1`) and port (default `5000`).
The script writes `~/.config/systemd/user/battery-tracker.service` and enables it.
**Start the service:**
```bash
systemctl --user start battery-tracker
systemctl --user status battery-tracker
```
**View live logs:**
```bash
journalctl --user -u battery-tracker -f
```
**Make it start on login** (requires lingering to be enabled for your user):
```bash
loginctl enable-linger "$USER"
```
**Uninstall:**
```bash
systemctl --user disable --now battery-tracker
rm ~/.config/systemd/user/battery-tracker.service
systemctl --user daemon-reload
```
**Re-run to update** (e.g. if you moved the app directory):
```bash
bash sbin/install-service.sh
systemctl --user restart battery-tracker
```
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# install-service.sh
# Generates and installs a systemd user-level service for the Battery Tracker app.
# No root required — uses ~/.config/systemd/user/.
#
# Usage: bash sbin/install-service.sh
set -euo pipefail
# Resolve the app root directory from the script's own location
APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VENV_WAITRESS="$APP_DIR/.venv/bin/waitress-serve"
SERVICE_DIR="$HOME/.config/systemd/user"
SERVICE_FILE="$SERVICE_DIR/battery-tracker.service"
echo "=== Battery Tracker — systemd user service installer ==="
echo "App directory: $APP_DIR"
echo
# Sanity checks
if [[ ! -f "$VENV_WAITRESS" ]]; then
echo "ERROR: waitress-serve not found at $VENV_WAITRESS"
echo "Run: python3 -m venv .venv && .venv/bin/pip install -r requirements.txt"
exit 1
fi
if [[ ! -f "$APP_DIR/app.py" ]]; then
echo "ERROR: app.py not found in $APP_DIR"
exit 1
fi
# Prompt for port and host
read -rp "Listen host [default: 127.0.0.1]: " HOST
HOST="${HOST:-127.0.0.1}"
read -rp "Listen port [default: 5000]: " PORT
PORT="${PORT:-5000}"
echo
echo "Generating service file → $SERVICE_FILE"
mkdir -p "$SERVICE_DIR"
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=Battery Tracker Flask App
After=network.target
[Service]
Type=simple
WorkingDirectory=$APP_DIR
ExecStart=$VENV_WAITRESS --host=$HOST --port=$PORT app:app
Environment=PYTHONPATH=$APP_DIR
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
EOF
echo "Service file written."
echo
# Reload and enable
systemctl --user daemon-reload
systemctl --user enable battery-tracker
echo
echo "=== Done ==="
echo
echo "Start the service: systemctl --user start battery-tracker"
echo "Check status: systemctl --user status battery-tracker"
echo "View logs: journalctl --user -u battery-tracker -f"
echo "Stop the service: systemctl --user stop battery-tracker"
echo
echo "To uninstall:"
echo " systemctl --user disable --now battery-tracker"
echo " rm $SERVICE_FILE"
echo " systemctl --user daemon-reload"