2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-12-18 06:22:18 +00:00

fixing pre-run script

This commit is contained in:
Philip Sargent 2024-12-12 17:08:00 +00:00
parent 58c9dd7d09
commit 321f912083
4 changed files with 33 additions and 60 deletions

View File

@ -1,35 +1,36 @@
#! /bin/sh #! /bin/bash
# Do these before final testing, *not* just before pushing: # Do these before final testing, *not* just before pushing:
# Philip Sargent 2020/06/20 # Need to be in an ALREADY activated venv
# now with uv PYTHON="python"
PYTHON="uv run"
cd ..
echo "** Run inspectdb:" echo "** Run inspectdb:"
$PYTHON troggle/manage.py inspectdb > troggle-inspectdb.py $PYTHON manage.py inspectdb > troggle-inspectdb.py
# egrep -in "unable|error" troggle-inspectdb.py # egrep -in "unable|error" troggle-inspectdb.py
echo "" echo ""
# count non-blank lines of python and template HTML code # count non-blank lines of python and template HTML code
# includes all variants of settings.py files # includes all variants of settings.py files
find . -name \*.html -print0 | xargs -0 egrep -vc "#|^\s*$" | grep -v ":0$" | awk -F ":" '{ sum +=$2; print $2, $1; } END {print sum}'| sort -n > lines-of-templates.txt
find . -name \*.py -print0 | xargs -0 egrep -vc "#|^\s*$" | grep -v ":0$" | grep -v "/migrations/" |grep -v "troggle-inspectdb.py"| awk -F ":" '{ sum +=$2; print $2, $1; } END {print sum}'| sort -n > lines-of-python.txt # fix this as core/utils.py has 28,000 lines of numbers.
find . -name \*.html -print0 | xargs -0 egrep -vc "#|^\s*$" | grep -v ":0$" | grep -v ".venv" | awk -F ":" '{ sum +=$2; print $2, $1; } END {print sum}'| sort -n > lines-of-templates.txt
find . -name \*.py -print0 | xargs -0 egrep -vc "#|^\s*$" | grep -v ":0$" | grep -v ".venv" | grep -v "/migrations/" |grep -v "troggle-inspectdb.py"| awk -F ":" '{ sum +=$2; print $2, $1; } END {print sum}'| sort -n > lines-of-python.txt
echo "** Run reset-django.py - which deletes the database"
# This deletes the database so must run after generating troggle-inspectdb.py # This deletes the database so must run after generating troggle-inspectdb.py
$PYTHON troggle/reset-django.py $PYTHON reset-django.py
echo "** After cleanup deletion, remake all migrations." echo "** After cleanup deletion, remake all migrations."
$PYTHON troggle/manage.py makemigrations >/dev/null $PYTHON manage.py makemigrations >/dev/null
$PYTHON troggle/manage.py migrate $PYTHON manage.py migrate
echo "** Now running self check" echo "** Now running self check"
$PYTHON troggle/manage.py check -v 3 --deploy 2>security-warnings.txt >/dev/null $PYTHON manage.py check -v 3 --deploy 2>security-warnings.txt >/dev/null
$PYTHON troggle/manage.py check -v 3 --deploy $PYTHON manage.py check -v 3 --deploy
echo "** Now running test suite" echo "** Now running test suite"
$PYTHON troggle/manage.py test -v 1 # $PYTHON manage.py test -v 1
echo "" echo ""
echo `tail -1 lines-of-python.txt` non-comment lines of python. echo `tail -1 lines-of-python.txt` non-comment lines of python. But core/utils.py has 28,000 lines of numbers.
echo `tail -1 lines-of-templates.txt` non-comment lines of HTML templates. echo `tail -1 lines-of-templates.txt` non-comment lines of HTML templates.
echo '** If you have an error running manage.py, maybe you are not in an activated venv ?' echo '** If you have an error running manage.py, maybe you are not in an activated venv ?'

View File

@ -1,5 +1,6 @@
import os import os
import shutil import shutil
from pathlib import Path
"""Cleans all django-created files and compiled python. Used by the """Cleans all django-created files and compiled python. Used by the
pre-run.sh script which cleans and initialises everything before pre-run.sh script which cleans and initialises everything before
@ -47,7 +48,11 @@ def delete_migrations():
if folder.endswith("migrations"): if folder.endswith("migrations"):
for item in os.listdir(folder): for item in os.listdir(folder):
if not item.endswith("__init__.py"): if not item.endswith("__init__.py"):
os.remove(os.path.join(folder, item)) fullitem = Path(folder, item)
if fullitem.is_dir():
print(f"__ directory {item} in {folder} not deleted")
else:
os.remove(os.path.join(folder, item))
print("All migration files deleted.") print("All migration files deleted.")
return None return None

View File

@ -1,44 +1,10 @@
Traceback (most recent call last): System check identified some issues:
File "/home/philip/expo/troggle/manage.py", line 23, in <module>
execute_from_command_line(sys.argv) WARNINGS:
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ ?: (security.W001) You do not have 'django.middleware.security.SecurityMiddleware' in your MIDDLEWARE so the SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_REFERRER_POLICY, SECURE_CROSS_ORIGIN_OPENER_POLICY, and SECURE_SSL_REDIRECT settings will have no effect.
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line ?: (security.W009) Your SECRET_KEY has less than 50 characters, less than 5 unique characters, or it's prefixed with 'django-insecure-' indicating that it was generated automatically by Django. Please generate a long and random value, otherwise many of Django's security-critical features will be vulnerable to attack.
utility.execute() ?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.
~~~~~~~~~~~~~~~^^ ?: (security.W016) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie makes it more difficult for network traffic sniffers to steal the CSRF token.
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 416, in execute ?: (security.W018) You should not have DEBUG set to True in deployment.
django.setup()
~~~~~~~~~~~~^^ System check identified 5 issues (0 silenced).
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/apps/config.py", line 123, in create
mod = import_module(mod_path)
File "/home/philip/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/importlib/__init__.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/contrib/auth/apps.py", line 8, in <module>
from .checks import check_middleware, check_models_permissions, check_user_model
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/contrib/auth/checks.py", line 9, in <module>
from .management import _get_builtin_permissions
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/contrib/auth/management/__init__.py", line 10, in <module>
from django.contrib.contenttypes.management import create_contenttypes
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/contrib/contenttypes/management/__init__.py", line 2, in <module>
from django.db import DEFAULT_DB_ALIAS, IntegrityError, migrations, router, transaction
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/db/migrations/__init__.py", line 2, in <module>
from .operations import * # NOQA
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/db/migrations/operations/__init__.py", line 2, in <module>
from .models import (
...<15 lines>...
)
File "/home/philip/expo/troggle/.venv/lib/python3.13/site-packages/django/db/migrations/operations/models.py", line 3, in <module>
from django.db.migrations.state import ModelState
ModuleNotFoundError: No module named 'django.db.migrations.state'

1
troggle-grep.txt Normal file
View File

@ -0,0 +1 @@
(reverse-i-search)`grep': grep -nir --exclude="*.js" --exclude="*.css" --exclude="*.pyc" --exclude="*.pem" --exclude="*.sqlite" --exclude="*.html" --exclude="*.json" "FORM Logbook Edit" *