diff options
-rw-r--r-- | _deploy/wsl/localsettingsWSL.py | 28 | ||||
-rw-r--r-- | _deploy/wsl/requirements-p11d42.txt | 2 | ||||
-rw-r--r-- | deprecations.txt | 2 | ||||
-rw-r--r-- | requirements-p11d42.txt | 21 | ||||
-rw-r--r-- | venv-trog-d4.sh | 184 |
5 files changed, 218 insertions, 19 deletions
diff --git a/_deploy/wsl/localsettingsWSL.py b/_deploy/wsl/localsettingsWSL.py index 2824125..60d1c56 100644 --- a/_deploy/wsl/localsettingsWSL.py +++ b/_deploy/wsl/localsettingsWSL.py @@ -47,7 +47,6 @@ PV = "python" + str(sys.version_info.major) + "." + str(sys.version_info.minor) REPOS_ROOT_PATH = Path(__file__).parent.parent LIBDIR = REPOS_ROOT_PATH / "lib" / PV - TROGGLE_PATH = Path(__file__).parent TEMPLATE_PATH = TROGGLE_PATH / "templates" MEDIA_ROOT = TROGGLE_PATH / "media" @@ -56,19 +55,16 @@ JSLIB_ROOT = TROGGLE_PATH / "media" / "jslib" # used for CaveViewer JS utility EXPOFILES = REPOS_ROOT_PATH / "expofiles" SCANS_ROOT = EXPOFILES / "surveyscans" -# PHOTOS_ROOT = EXPOFILES / 'photos' PHOTOS_ROOT = Path("/mnt/d/EXPO/PHOTOS") PHOTOS_YEAR = "2023" - NOTABLECAVESHREFS = ["290", "291", "264", "258", "204", "359", "76", "107"] -# PYTHON_PATH = os.fspath(PYTHON_PATH) + PYTHON_PATH = REPOS_ROOT_PATH / "troggle" LOGFILE = PYTHON_PATH / "troggle.log" SQLITEDB = PYTHON_PATH / "troggle.sqlite" KMZ_ICONS_PATH = PYTHON_PATH / "kmz_icons" - # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). MEDIA_URL = "/site-media/" @@ -82,6 +78,7 @@ URL_ROOT = "/" MEDIA_URL = Path(URL_ROOT, "/site_media/") PHOTOS_URL = Path(URL_ROOT, "/photos/") + STATIC_URL = Path(URL_ROOT, "/static/") # used by Django admin pages. Do not delete. JSLIB_URL = Path(URL_ROOT, "/javascript/") # used for CaveViewer JS utility @@ -99,8 +96,8 @@ SURVEXPORT = "survexport" # for parsing .3d files and producing .pos files DBSQLITE = { "default": { "ENGINE": "django.db.backends.sqlite3", # 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - #'NAME' : 'troggle.sqlite', "NAME": str(SQLITEDB), + # 'NAME' : ':memory:', "USER": "expo", # Not used with sqlite3. "PASSWORD": "sekrit", # Not used with sqlite3. "HOST": "", # Set to empty string for localhost. Not used with sqlite3. @@ -136,19 +133,19 @@ TEMPLATES = [ "debug": "DEBUG", "context_processors": [ # django.template.context_processors.csrf, # is always enabled and cannot be removed, sets csrf_token - "django.contrib.auth.context_processors.auth", # knowledge of logged-on user & permissions - "core.context.troggle_context", # in core/troggle.py - only used in expedition.html + "django.contrib.auth.context_processors.auth", # knowledge of logged-on user & permissions + "core.context.troggle_context", # in core/troggle.py - only used in expedition.html "django.template.context_processors.debug", "django.template.context_processors.i18n", "django.template.context_processors.media", # includes a variable MEDIA_URL - "django.template.context_processors.static", # includes a variable STATIC_URL used by admin pages + "django.template.context_processors.static", # includes a variable STATIC_URL used by admin pages "django.template.context_processors.tz", - "django.template.context_processors.request", # must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin navigation sidebar. + "django.template.context_processors.request", # must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin navigation sidebar. "django.contrib.messages.context_processors.messages", ], "loaders": [ - "django.template.loaders.filesystem.Loader", # default lcation is troggle/templates/ - "django.template.loaders.app_directories.Loader", # needed for admin 'app' + "django.template.loaders.filesystem.Loader", # default lcation is troggle/templates/ + "django.template.loaders.app_directories.Loader", # needed for admin 'app' ], }, }, @@ -167,7 +164,6 @@ DEFAULT_FROM_EMAIL = "django-test@klebos.net" SURVEX_DATA = REPOS_ROOT_PATH / "loser" DRAWINGS_DATA = REPOS_ROOT_PATH / "drawings" - EXPOWEB = REPOS_ROOT_PATH / "expoweb" CAVEDESCRIPTIONS = EXPOWEB / "cave_data" ENTRANCEDESCRIPTIONS = EXPOWEB / "entrance_data" @@ -177,12 +173,10 @@ EXPOWEB_URL = "" sys.path.append(str(REPOS_ROOT_PATH)) sys.path.append(str(PYTHON_PATH)) +#TINY_MCE_MEDIA_ROOT = STATIC_ROOT + '/tiny_mce/' # not needed while TinyMCE not installed +#TINY_MCE_MEDIA_URL = STATIC_URL + '/tiny_mce/' # not needed while TinyMCE not installed # Sanitise these to be strings as Django seems to be particularly sensitive to crashing if they aren't -# and we have not made the change to pathlib Path type in the other localsettings-* variants yet. -CAVEDESCRIPTIONS = os.fspath(CAVEDESCRIPTIONS) -ENTRANCEDESCRIPTIONS = os.fspath(ENTRANCEDESCRIPTIONS) - STATIC_URL = str(STATIC_URL) + "/" MEDIA_URL = str(MEDIA_URL) + "/" diff --git a/_deploy/wsl/requirements-p11d42.txt b/_deploy/wsl/requirements-p11d42.txt index 5f5eed7..7d1992c 100644 --- a/_deploy/wsl/requirements-p11d42.txt +++ b/_deploy/wsl/requirements-p11d42.txt @@ -18,4 +18,4 @@ ruff==0.0.245 soupsieve==2.5 sqlparse==0.4.0 Unidecode==1.3.0 -piexif==1.1 +piexif diff --git a/deprecations.txt b/deprecations.txt index 638aa68..26bd153 100644 --- a/deprecations.txt +++ b/deprecations.txt @@ -1,2 +1,2 @@ -/home/philip/p11d4/lib/python3.11/site-packages/django/conf/__init__.py:267: RemovedInDjango50Warning: The USE_L10N setting is deprecated. Starting with Django 5.0, localized formatting of data will always be enabled. For example Django will display numbers and dates using the format of the current locale. +/home/philip/p11d42/lib/python3.11/site-packages/django/conf/__init__.py:267: RemovedInDjango50Warning: The USE_L10N setting is deprecated. Starting with Django 5.0, localized formatting of data will always be enabled. For example Django will display numbers and dates using the format of the current locale. warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning) diff --git a/requirements-p11d42.txt b/requirements-p11d42.txt new file mode 100644 index 0000000..aa64d29 --- /dev/null +++ b/requirements-p11d42.txt @@ -0,0 +1,21 @@ +asgiref==3.6.0 +beautifulsoup4==4.12.0 +black==23.1.0 +chardet==5.1.0 +click==8.1.0 +coverage==7.1.0 +deptry==0.12.0 +Django==4.2 +docutils==0.19 +isort==5.12.0 +mypy-extensions==1.0.0 +packaging==23.0 +pathspec==0.11.0 +piexif==1.1.3 +Pillow==9.4.0 +platformdirs==3.0.0 +pytz==2022.7 +ruff==0.0.245 +soupsieve==2.5 +sqlparse==0.4.0 +Unidecode==1.3.0 diff --git a/venv-trog-d4.sh b/venv-trog-d4.sh new file mode 100644 index 0000000..97e99b7 --- /dev/null +++ b/venv-trog-d4.sh @@ -0,0 +1,184 @@ +#!/bin/bash +# footled lots to make this work with python 3.10 & 3.11 and WSL1 and WSL2 on Ubuntu 22.04 +# Run this in a terminal in the troggle directory: 'bash venv-trog.sh' +echo '-- Run this in a terminal in the real troggle directory: "bash venv-trog.sh"' + +# Expects an Ubuntu 22.04 (or 20.04) relatively clean install. +# If you have not already installed these on your clean Ubuntu install DO THIS FIRST +# use the script os-trog.sh + +# If you are using Debian, then stick with the default version of python +# If you are using Ubuntu, then it is easy to use a later version of python, e.g. 3.11 + +# NOW we set up troggle +PYTHON=python3.11 +VENAME=p11d42 # python3.x and django 4.2 +echo "** You are logged in as `id -u -n`" +echo "The 50MB pip cache will be in /home/`id -u -n`/.cache/" +echo "The 150MB venv will created in /home/`id -u -n`/$VENAME/" +TROGDIR=$(cd $(dirname $0) && pwd) +echo "-- Troggle folder (this script location): ${TROGDIR}" + +REQUIRE=requirements-$VENAME.txt + +if [ -d $REQUIRE ]; then + echo "-- No ${REQUIRE} found. You should be in the /troggle/ folder. Copy it from your most recent installation." + exit 1 +fi +echo ## Using $REQUIRE : +cat $REQUIRE +echo ## + + +$PYTHON --version + +# NOTE that when using a later or earlier verison of python, you MUST also +# use the allowed version of Pillow, see https://pillow.readthedocs.io/en/latest/installation.html + +# NOW set up link from expo user folder +# needed for WSL2 +echo Creating links from Linux filesystem user +# These links only need making once, for many venv +cd ~ + +if [ ! -d $VENAME ]; then + echo "## Creating venv $VENAME. (If this fails with a pip error, you need to ensure you have python3.11-venv installed and/or use a Ubuntu window)" + $PYTHON -m venv $VENAME +else + echo "## /$VENAME/ already exists ! Delete it first." + exit 1 +fi + + # Activate the virtual env and see what the default packages are +echo "### Activating $VENAME" + +cd $VENAME +echo "-- now in: ${PWD}" +ls -tlarg +source bin/activate +echo $VIRTUAL_ENV +if [ -d ~/$VENAME/bin ]; then + echo "### Activating." +else + echo "## ~/$VENAME/bin does not exist. FAILed to create venv properly." + exit 1 +fi + # update local version of pip, more recent than OS version + # debian bullseye installs pip 20.3.4 which barfs, we want >22.0.3 + + # update local version of setuptools, more recent than OS version, needed for packages without wheels + +echo "### installing later version of pip inside $VENAME" +$PYTHON -m pip install --upgrade pip +$PYTHON -m pip install --upgrade setuptools + +PIP=pip + +$PIP list > original-pip.list +$PIP freeze >original.txt + +# we are in /home/$USER/$VENAME/ +ln -s ${TROGDIR} troggle +ln -s ${TROGDIR}/../expoweb expoweb +ln -s ${TROGDIR}/../loser loser +ln -s ${TROGDIR}/../drawings drawings +#ln -s ${TROGDIR}/../expofiles expofiles + +# fudge for philip's machine +if [ ! -d /mnt/d/EXPO ]; then + sudo mkdir /mnt/d + sudo mount -t drvfs D: /mnt/d +fi + +if [ -d ${TROGDIR}/../expofiles ]; then + ln -s ${TROGDIR}/../expofiles expofiles +else + ln -s /mnt/d/EXPO/expofiles expofiles +fi + +echo "### Setting file permissions.. may take a while.." +git config --global --add safe.directory '*' +sudo chmod -R 777 * + +echo "### links to expoweb, troggle etc. complete:" +ls -tla +echo "###" +echo "### now installing ${TROGDIR}/${REQUIRE}" +echo "###" +cat ${TROGDIR}/${REQUIRE} + +# NOW THERE IS A PERMISSIONS FAILURE THAT DIDN'T HAPPEN BEFORE +# seen on wsl2 as well as wsl1 +# which ALSO ruins EXISTING permissions ! +# Guessing it is to do with pip not liking non-standard py 3.11 installation on Ubuntu 22.04 + +read -p "Press any key to resume ..." +$PIP install -r ${TROGDIR}/${REQUIRE} +echo "### install from ${TROGDIR}/${REQUIRE} completed." +echo '### ' + +$PIP install --pre django + +$PIP freeze > $REQUIRE +# so that we can track requirements more easily with git +# because we do not install these with pip, but they are listed by the freeze command +# Now find out what we actually installed by subtracting the stuff venv installed anyway +sort original.txt > 1 +sort $REQUIRE >2 +comm -3 1 2 --check-order | awk '{ print $1}'>fresh-$REQUIRE +rm 1 +rm 2 + +# cp $REQUIRE requirements-$VENAME.txt +cp $REQUIRE troggle/$REQUIRE + +$PIP list > installed-pip.list +$PIP list -o > installed-pip-o.list + +REQ=installation-record +mkdir $REQ + +mv original.txt $REQ +mv $REQUIRE $REQ +mv original-pip.list $REQ +mv installed-pip.list $REQ +mv installed-pip-o.list $REQ +cp fresh-$REQUIRE ../$REQUIRE +mv fresh-$REQUIRE $REQ +cp troggle/`basename "$0"` $REQ + + +$PYTHON --version +python --version +echo "Django version:`django-admin --version`" + +echo "### Now do + '[sudo service mysql start]' + '[sudo service mariadb restart]' + '[sudo mysql_secure_installation]' + 'cd ~/$VENAME' + 'source bin/activate' + 'cd troggle' + 'django-admin' + 'python manage.py check' +## this tests if you have set up ssh correcting. Refer to documentation https://expo.survex.com/handbook/computing/keyexchange.html +## you need to follow the Linux instructions. + 'ssh expo@expo.survex.com' + +## the next tests will fail unless ~/expofiles is set correctly to a folder on your machine +## the tests may ALSO fail because of ssh and permissions errors + +## So you will need to run +$sudo chown -Rhv philip:philip ~/$VENAME (if your username is philip) +# and then REBOOT (or at least, exit WSL and terminate and restart WSL) +# because this chmod only takes effect then. + + 'python manage.py test -v 2' + './pre-run.sh' (runs the tests again) + + 'python databaseReset.py reset $VENAME' + 'python manage.py runserver 0.0.0.0:8000 (and allow access when the firewall window pops up)' + " +# if [ ! -d /mnt/d/expofiles ]; then + # echo '### No valid expofiles directory on /mnt/d . Fix this before any tests will work.' +# fi
\ No newline at end of file |