Improvements

This commit is contained in:
Zaine
2026-07-09 16:34:28 +01:00
parent d7d0054af4
commit e9e3954f31
20 changed files with 6691 additions and 6686 deletions

211
Makefile
View File

@@ -1,103 +1,108 @@
.PHONY: test author author-install author-start author-stop author-stop-legacy author-restart author-status author-logs author-health author-diagnostics clean-venv help
VENV := .venv
PY := $(VENV)/bin/python
PIP := $(VENV)/bin/pip
AUTHOR_PORT := 8765
AUTHOR_URL := http://127.0.0.1:$(AUTHOR_PORT)
AUTHOR_PAGES_CHECK := /tmp/authoring-server-pages.json
AUTHOR_SERVICE := org-web-authoring.service
AUTHOR_UNIT_SRC := systemd/user/$(AUTHOR_SERVICE)
SYSTEMD_USER_DIR := $(HOME)/.config/systemd/user
AUTHOR_UNIT_DST := $(SYSTEMD_USER_DIR)/$(AUTHOR_SERVICE)
USER_ID := $(shell id -u)
SYSTEMD_RUNTIME_DIR ?= /run/user/$(USER_ID)
SYSTEMCTL_USER := env XDG_RUNTIME_DIR=$(SYSTEMD_RUNTIME_DIR) systemctl --user
JOURNALCTL_USER := env XDG_RUNTIME_DIR=$(SYSTEMD_RUNTIME_DIR) journalctl --user
all: author-restart
test: $(VENV)
PYTHONPATH=src $(PY) -m unittest discover -s src/tests -p 'test_authoring_server.py' -v
$(VENV):
@echo "Generating virtual environment"
python3 -m venv $(VENV)
$(PIP) install -r requirements.txt
author: author-start
author-install: $(VENV)
@echo "Installing $(AUTHOR_SERVICE) for the current user..."
@mkdir -p "$(SYSTEMD_USER_DIR)"
install -m 0644 "$(AUTHOR_UNIT_SRC)" "$(AUTHOR_UNIT_DST)"
$(SYSTEMCTL_USER) daemon-reload
$(SYSTEMCTL_USER) enable "$(AUTHOR_SERVICE)"
author-start: author-install author-stop-legacy
@echo "Starting authoring UI with systemd..."
$(SYSTEMCTL_USER) start "$(AUTHOR_SERVICE)"
@$(MAKE) --no-print-directory author-health
author-stop:
@echo "Stopping authoring UI with systemd..."
$(SYSTEMCTL_USER) stop "$(AUTHOR_SERVICE)" || true
@$(MAKE) --no-print-directory author-stop-legacy
author-stop-legacy:
@echo "Stopping any legacy process on authoring port $(AUTHOR_PORT)..."
@fuser -k $(AUTHOR_PORT)/tcp >/dev/null 2>&1 || true
author-restart: author-install author-stop-legacy
@echo "Restarting authoring UI with systemd..."
$(SYSTEMCTL_USER) restart "$(AUTHOR_SERVICE)"
@$(MAKE) --no-print-directory author-health
author-health:
@echo "Waiting for authoring UI and page list to respond..."
@for i in 1 2 3 4 5 6 7 8 9 10; do \
if ! $(SYSTEMCTL_USER) is-active --quiet "$(AUTHOR_SERVICE)"; then \
echo "Authoring UI service is not active. Service status:"; \
$(SYSTEMCTL_USER) status --no-pager "$(AUTHOR_SERVICE)" || true; \
echo "Recent logs:"; \
$(JOURNALCTL_USER) -u "$(AUTHOR_SERVICE)" -n 80 --no-pager || true; \
exit 1; \
fi; \
if curl -fsS "$(AUTHOR_URL)/api/pages" -o "$(AUTHOR_PAGES_CHECK)" && $(PY) -c 'import json,sys; data=json.load(sys.stdin); sys.exit(0 if isinstance(data, list) and data else 1)' < "$(AUTHOR_PAGES_CHECK)"; then \
echo "Authoring UI is running on $(AUTHOR_URL)/"; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "Authoring UI failed to respond. Service status:"; \
$(SYSTEMCTL_USER) status --no-pager "$(AUTHOR_SERVICE)" || true; \
echo "Recent logs:"; \
$(JOURNALCTL_USER) -u "$(AUTHOR_SERVICE)" -n 80 --no-pager || true; \
exit 1
author-status:
@$(SYSTEMCTL_USER) status --no-pager "$(AUTHOR_SERVICE)" || true
@curl -fsS "$(AUTHOR_URL)/api/pages" -o "$(AUTHOR_PAGES_CHECK)" && $(PY) -c 'import json,sys; print(f"Pages: {len(json.load(sys.stdin))}")' < "$(AUTHOR_PAGES_CHECK)" || true
author-diagnostics:
@curl -fsS "$(AUTHOR_URL)/api/diagnostics" || true
author-logs:
$(JOURNALCTL_USER) -u "$(AUTHOR_SERVICE)" -n 100 --no-pager
clean-venv:
@echo "Cleaning virtual environment..."
rm -rf $(VENV)
help:
@echo "Available targets:"
@echo " make test - Run authoring server tests"
@echo " make author - Install and start the authoring UI service"
@echo " make author-install - Install and enable the authoring UI service"
@echo " make author-stop - Stop the authoring UI service"
@echo " make author-restart - Restart the authoring UI service"
@echo " make author-status - Show authoring UI service status and page count"
@echo " make author-diagnostics - Show authoring UI runtime diagnostics"
@echo " make author-logs - Show recent authoring UI service logs"
@echo " make clean-venv - Remove virtual environment"
.PHONY: test author author-install author-start author-stop author-stop-legacy author-restart author-status author-logs author-health author-diagnostics clean-venv help
VENV := .venv
PY := $(VENV)/bin/python
PIP := $(VENV)/bin/pip
AUTHOR_PORT := 8765
AUTHOR_URL := http://127.0.0.1:$(AUTHOR_PORT)
AUTHOR_PAGES_CHECK := /tmp/authoring-server-pages.json
AUTHOR_SERVICE := org-web-authoring.service
AUTHOR_UNIT_SRC := systemd/user/$(AUTHOR_SERVICE)
SYSTEMD_USER_DIR := $(HOME)/.config/systemd/user
AUTHOR_UNIT_DST := $(SYSTEMD_USER_DIR)/$(AUTHOR_SERVICE)
USER_ID := $(shell id -u)
SYSTEMD_RUNTIME_DIR ?= /run/user/$(USER_ID)
SYSTEMCTL_USER := env XDG_RUNTIME_DIR=$(SYSTEMD_RUNTIME_DIR) systemctl --user
JOURNALCTL_USER := env XDG_RUNTIME_DIR=$(SYSTEMD_RUNTIME_DIR) journalctl --user
all: author-restart
test: $(VENV)
PYTHONPATH=src $(PY) -m unittest discover -s src/tests -p 'test_authoring_server.py' -v
$(VENV):
@echo "Generating virtual environment"
python3 -m venv $(VENV)
$(PIP) install -r requirements.txt
author: author-start
author-install: $(VENV)
@echo "Installing $(AUTHOR_SERVICE) for the current user..."
@mkdir -p "$(SYSTEMD_USER_DIR)"
install -m 0644 "$(AUTHOR_UNIT_SRC)" "$(AUTHOR_UNIT_DST)"
$(SYSTEMCTL_USER) daemon-reload
$(SYSTEMCTL_USER) enable "$(AUTHOR_SERVICE)"
author-start: author-install author-stop-legacy
@echo "Starting authoring UI with systemd..."
$(SYSTEMCTL_USER) start "$(AUTHOR_SERVICE)"
@$(MAKE) --no-print-directory author-health
author-dev:
@echo "Starting authoring UI without systemd..."
$(PY) authoring_server.py
@$(MAKE) --no-print-directory author-health
author-stop:
@echo "Stopping authoring UI with systemd..."
$(SYSTEMCTL_USER) stop "$(AUTHOR_SERVICE)" || true
@$(MAKE) --no-print-directory author-stop-legacy
author-stop-legacy:
@echo "Stopping any legacy process on authoring port $(AUTHOR_PORT)..."
@fuser -k $(AUTHOR_PORT)/tcp >/dev/null 2>&1 || true
author-restart: author-install author-stop-legacy
@echo "Restarting authoring UI with systemd..."
$(SYSTEMCTL_USER) restart "$(AUTHOR_SERVICE)"
@$(MAKE) --no-print-directory author-health
author-health:
@echo "Waiting for authoring UI and page list to respond..."
@for i in 1 2 3 4 5 6 7 8 9 10; do \
if ! $(SYSTEMCTL_USER) is-active --quiet "$(AUTHOR_SERVICE)"; then \
echo "Authoring UI service is not active. Service status:"; \
$(SYSTEMCTL_USER) status --no-pager "$(AUTHOR_SERVICE)" || true; \
echo "Recent logs:"; \
$(JOURNALCTL_USER) -u "$(AUTHOR_SERVICE)" -n 80 --no-pager || true; \
exit 1; \
fi; \
if curl -fsS "$(AUTHOR_URL)/api/pages" -o "$(AUTHOR_PAGES_CHECK)" && $(PY) -c 'import json,sys; data=json.load(sys.stdin); sys.exit(0 if isinstance(data, list) and data else 1)' < "$(AUTHOR_PAGES_CHECK)"; then \
echo "Authoring UI is running on $(AUTHOR_URL)/"; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "Authoring UI failed to respond. Service status:"; \
$(SYSTEMCTL_USER) status --no-pager "$(AUTHOR_SERVICE)" || true; \
echo "Recent logs:"; \
$(JOURNALCTL_USER) -u "$(AUTHOR_SERVICE)" -n 80 --no-pager || true; \
exit 1
author-status:
@$(SYSTEMCTL_USER) status --no-pager "$(AUTHOR_SERVICE)" || true
@curl -fsS "$(AUTHOR_URL)/api/pages" -o "$(AUTHOR_PAGES_CHECK)" && $(PY) -c 'import json,sys; print(f"Pages: {len(json.load(sys.stdin))}")' < "$(AUTHOR_PAGES_CHECK)" || true
author-diagnostics:
@curl -fsS "$(AUTHOR_URL)/api/diagnostics" || true
author-logs:
$(JOURNALCTL_USER) -u "$(AUTHOR_SERVICE)" -n 100 --no-pager
clean-venv:
@echo "Cleaning virtual environment..."
rm -rf $(VENV)
help:
@echo "Available targets:"
@echo " make test - Run authoring server tests"
@echo " make author - Install and start the authoring UI service"
@echo " make author-install - Install and enable the authoring UI service"
@echo " make author-stop - Stop the authoring UI service"
@echo " make author-restart - Restart the authoring UI service"
@echo " make author-status - Show authoring UI service status and page count"
@echo " make author-diagnostics - Show authoring UI runtime diagnostics"
@echo " make author-logs - Show recent authoring UI service logs"
@echo " make clean-venv - Remove virtual environment"