/
oriono
/
taskman
Обзор
Документация
Войти
/
oriono
/
taskman
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
Makefile
399 строк
11 KB
abo
i18n: add two-stage translation via Russian
17 июн 2026, 21:23
17 июн 2026, 21:23
776194e
Код
Авторство
О чём код?
MANAGE := poetry run python manage.py # install dependenciess, collect static, run migrations, create superuser build: ./build.sh # run local server dev: $(MANAGE) runserver 8001 # run production server PORT ?= 8001 start: poetry run gunicorn -w 4 -b localhost:$(PORT) task_manager.wsgi:application # linting lint: poetry run flake8 # run tests test: $(MANAGE) test # create & show test-coverage for project in github cov: poetry run coverage run --source='task_manager' manage.py test && poetry run coverage xml # show all files with they test-coverage in % test-cov: poetry run coverage run --source='task_manager' manage.py test && poetry run coverage report --show-missing # local migrations migrations: $(MANAGE) makemigrations # run local migrate migrate: $(MANAGE) migrate # collect static files (local development) collectstatic: $(MANAGE) collectstatic --noinput # when you want to operate with local DB shell: $(MANAGE) shell # add all strings to translate to task_manager/locale/ru/LC_MESSAGES/django.po messages: cd task_manager && django-admin makemessages -a # make all added translates is compiled compile: cd task_manager && django-admin compilemessages # Automatically translate empty/fuzzy entries (skips ru by default) .PHONY: translate translate: SKIP_LANGS=ru poetry run python scripts/translate_po.py # Translate all languages including ru (EN -> all) .PHONY: translate-all translate-all: poetry run python scripts/translate_po.py # Step 1: Translate only Russian (EN -> RU) .PHONY: translate-ru translate-ru: TARGET_LANG=ru poetry run python scripts/translate_po.py # Step 2: Translate az/ky/tg from verified Russian (RU -> AZ/KY/TG) .PHONY: translate-from-ru translate-from-ru: FROM_RU=1 poetry run python scripts/translate_po.py # Full i18n cycle: extract + compile (translate runs separately) .PHONY: i18n i18n: messages compile # Preview what would be translated without making API requests .PHONY: translate-dry translate-dry: DRY_RUN=1 poetry run python scripts/translate_po.py # Show untranslated strings with line numbers (ru only) .PHONY: translate-dry-ru translate-dry-ru: poetry run python scripts/translate_po.py list-ru # ======================================== DC := docker compose --env-file .env.docker POSTGRES_USER := $(shell $(DC) exec db printenv POSTGRES_USER) POSTGRES_DB := $(shell $(DC) exec db printenv POSTGRES_DB) # Production server settings PROD_HOST := taskman-prod PROD_DIR := ~/taskman # Staging server settings STAGE_HOST := taskman-stage STAGE_DIR := ~/taskman # start all services in background up: $(DC) up -d # stop all services down: $(DC) down # stop and remove containers, networks, volumes down-clean: $(DC) down -v --remove-orphans # restart all services restart: $(DC) restart # build images d-build: $(DC) build # build images without cache build-no-cache: $(DC) build --no-cache # rebuild and start rebuild: $(DC) down && $(DC) build && $(DC) up -d # view logs of all services logs: $(DC) logs -f # view Django logs logs-web: $(DC) logs -f django-web # view database logs logs-db: $(DC) logs -f db # Service status status: $(DC) ps # ======================================== # Commands for working inside containers # ======================================== # enter Django container d-bash: $(DC) exec django-web bash # enter Django shell d-shell: $(DC) exec django-web python manage.py shell # enter database container db-shell: $(DC) exec db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) # enter database container via bash db-bash: $(DC) exec db bash # ======================================== # Django commands via Docker # ======================================== # create migrations d-migrations: $(DC) exec django-web python manage.py makemigrations # apply migrations d-migrate: $(DC) exec django-web python manage.py migrate # create superuser d-createsu: $(DC) exec django-web python manage.py createsuperuser # collect static files d-collect: $(DC) exec django-web python manage.py collectstatic --no-input # create translations d-messages: $(DC) exec django-web python manage.py makemessages -a # compile translations d-compile: $(DC) exec django-web python manage.py compilemessages # ======================================== # Database commands # ======================================== # create local database backup (compressed) d-backup: @mkdir -p backups $(DC) exec -T db pg_dump -U $(POSTGRES_USER) -d $(POSTGRES_DB) | gzip > backups/backup_$$(date +%Y%m%d_%H%M%S).sql.gz # Restore database from compressed backup (WARNING: Drops current DB data!) # Usage: make d-restore FILE=backup_name.sql.gz d-restore: @if [ -z "$(FILE)" ]; then \ echo "Error: Please specify the file name (e.g., make d-restore FILE=uploaded_backup.sql.gz)"; \ exit 1; \ fi @echo "⚠️ WARNING: This will DROP the current database and restore from backups/$(FILE)!" @read -p "Press ENTER to continue or Ctrl+C to abort..." dummy @echo "Cleaning up current database..." $(DC) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" @echo "Restoring data..." gzip -dc backups/$(FILE) | $(DC) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) @echo "✅ Database restored successfully!" # reset database and reapply migrations d-reset-db: $(DC) down docker volume rm $$(docker volume ls -q | grep postgres_data) || true $(DC) up -d db sleep 10 $(DC) up -d django-web $(DC) exec django-web python manage.py migrate $(DC) exec django-web python manage.py createsuperuser # ======================================== # Backup synchronization (Server <-> Local) # ======================================== # Download the latest backups from the production and staging server d-pull-backup: @echo "Looking for the latest backup on the server..." @mkdir -p backups scp $(PROD_HOST):$$(ssh $(PROD_HOST) "ls -t $(PROD_DIR)/backups/backup_*.sql.gz | head -n 1") ./backups/latest_prod.sql.gz scp $(STAGE_HOST):$$(ssh $(STAGE_HOST) "ls -t $(STAGE_DIR)/backups/backup_*.sql.gz | head -n 1") ./backups/latest_stage.sql.gz @echo "✅ Backups successfully downloaded to backups/latest_prod.sql.gz and backups/latest_stage.sql.gz" # Upload a local backup to the production server (use: make d-push-backup FILE=backup_name.sql.gz) d-push-backup: @if [ -z "$(FILE)" ]; then \ echo "Error: Please specify the file name (e.g., make d-push-backup FILE=backup_2024.sql.gz)"; \ exit 1; \ fi @echo "Uploading backups/$(FILE) to the server..." scp backups/$(FILE) $(PROD_HOST):$(PROD_DIR)/backups/uploaded_backup.sql.gz @echo "✅ File successfully uploaded to the server as uploaded_backup.sql.gz" # ======================================== # Development commands # ======================================== # full cycle: build, start, migrate, static, clean up, check deploy: mkdir -p staticfiles mkdir -p backups $(DC) build $(DC) up -d sleep 5 $(DC) exec django-web python manage.py migrate $(DC) exec django-web python manage.py collectstatic --no-input --clear @echo "=== Make rights on static files for Nginx ===" chmod -R o+rX staticfiles/ @echo "=== Restart Django to reload staticfiles manifest ===" $(DC) restart django-web sleep 5 @echo "=== Clear Docker-cache ===" docker system prune -f @echo "=== Check ===" $(DC) ps @echo "" @curl -sf -o /dev/null -w "HTTP Status: %{http_code}\n" http://127.0.0.1:8001/ || echo "WARNING: App not responding!" @echo "" @echo "=== Deploy complete at $$(date) ===" # full redeploy use when: docker-compose.yml changes, DB image updates, or container state issues # stops all containers, rebuilds images without cache, recreates from scratch redeploy: mkdir -p staticfiles mkdir -p backups $(DC) down $(DC) build --no-cache $(DC) up -d sleep 15 $(DC) exec django-web python manage.py migrate $(DC) exec django-web python manage.py collectstatic --no-input --clear chmod -R o+rX staticfiles/ $(DC) restart django-web sleep 5 docker image prune -f docker builder prune -f $(DC) ps @echo "=== Full redeploy complete ===" # quick start for development d-dev: $(DC) up -d sleep 10 $(DC) exec django-web python manage.py migrate # clean unused Docker objects d-clean: docker system prune -f docker volume prune -f # full cleanup (CAUTION - removes ALL unused Docker objects) d-clean-all: docker system prune -a -f --volumes # ======================================== # Information commands # ======================================== # show Docker disk usage d-space: docker system df # show all containers (including stopped) ps-all: docker ps -a # show Docker images images: docker images # show Docker volumes volumes: docker volume ls # ======================================== # Server commands # ======================================== # show server-notes (nginx, fail2ban etc.) server-notes: cat ~/server-notes.md # help for Docker and non-Docker commands help: @echo "Available non-Docker commands:" @echo " build - Install dependencies, collect static, migrations, superuser" @echo " dev - Run local server" @echo " start - Run production server" @echo " lint - Code style check with flake8" @echo " test - Run tests" @echo " cov - Create test coverage report" @echo " test-cov - Show test coverage in %" @echo " migrations - Create migrations" @echo " migrate - Apply migrations" @echo " collectstatic - Collect static files" @echo " shell - Enter Django shell" @echo " messages - Create translation files" @echo " compile - Compile translations" @echo " server-notes - Show server-notes (nginx, fail2ban etc.)" @echo "" @echo "Main Docker commands:" @echo " up - Start services" @echo " down - Stop services" @echo " restart - Restart services" @echo " d-build - Build images" @echo " rebuild - Rebuild and start" @echo " logs - View logs" @echo " d-bash - Enter Django container" @echo " db-shell - Enter database" @echo " d-migrate - Apply migrations" @echo " d-backup - Create database backup" @echo " deploy - Full deployment" @echo " redeploy - Full redeployment" @echo " d-clean - Clean Docker objects" @echo "" @echo "Additional Docker commands:" @echo " down-clean - Stop and remove containers, networks, volumes" @echo " build-no-cache - Build images without cache" @echo " logs-web - View Django logs" @echo " logs-db - View database logs" @echo " status - Service status" @echo " d-shell - Enter Django shell" @echo " db-bash - Enter database container via bash" @echo " d-migrations - Create migrations" @echo " d-createsu - Create superuser" @echo " d-collect - Collect static files" @echo " d-messages - Create translations" @echo " d-compile - Compile translations" @echo " d-restore - Restore database from backup" @echo " d-reset-db - Reset and recreate database" @echo " d-dev - Quick start for development" @echo " d-clean-all - Full Docker cleanup (WARNING!)" @echo " d-space - View Docker disk usage" @echo " ps-all - View all containers" @echo " images - View Docker images" @echo " volumes - View Docker volumes"