pythin Handbook Troggle Laptop

CUCC Expedition Handbook

Troggle - software development laptop

python logo

Software development machine

For troggle itself, you need a linux machine. We all use Debian or Debian-derived machines (Debian itself, Ubuntu, Xubuntu etc.) but other forms of linux may work. Running Debian or Ubuntu under WSL on Windows 10 works fine.

If you want to work on the troggle source code and be able to commit to the server git repo, your account will need to be added to the troggle project members list. Contact wookey at wookware dot org to get this set up.

This page is a work in progess. Text will be moved here from

http://expo.survex.com/repositories/troggle/.git/tree/README.txt
handbook/computing/yourlaptop.html
debian logo

Installing linux

If you don't already know how to do this, then you should probably not be attempting to work on the troggle code. But in case you are an experienced linux user who has always had someone else set up the system for them, then Ubuntu is the easiest and more forgiving to install, either directly on the computer or inside WSL. Because we are using fairly old releases of Django, you will want Ubuntu-20.04

and familiarise yourself with the directory structure on the expo server, which we will be duplicating (partly) as docmented in The Expo Server. We are not here doing a full install of all the software and scripts on the server, just the minimum to run, test and debug troggle on django.

WSL on Windows

The standard documentation for Ubuntu or debian below all works, but you should first skim the Windows expo laptop description of WSL1 and WSL2. The default is that WSL2 will be installed, but all our practical experience so far is with WSL1.

Installing python

Python is not installed by default usually, and in any case we need specific versions to be installed. For Ubuntu 20.04 the default is python3.9 but this is incompatible with standard debian Buster which is what is live on our server, so we also need python3.7 . If you are planning on helping the migration of troggle from debian Buster (v10) to Bullseye (v11) then you will also want python3.8 .

sudo apt install python3 python3-pip
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7 python3.7-venv python3.7-doc binutils binfmt-support
sudo apt install sqlite3 sqlite3-doc
sudo apt install survex
cd /usr/bin
sudo ln -s python3 python
sudo ln -s pip3 pip 

You will also definitely need sqlite3 even if you are planning to use another database. Sqlite3 is used by the test harness system.

Note that when you install survex it installs a shed load of packages that it needs.

We do not install django at this point. We will be installing django in a separate virtual environment (a 'venv'), not in the main linux system.

We need to have the folder structure that troggle expects. On your own machine you will have your own logon id, and you do not need to create an 'expo' user, but you do need to create folders where and an 'expo' user would have them. Make links there to wherever you have actually installed the repos. So if you have installed all your repos in /mnt/c/EXPO/, then you would need to do this:

cd ~
cd ..
sudo mkdir expo
cd expo
sudo ln -s /mnt/c/EXPO/expoweb expoweb
sudo ln -s /mnt/c/EXPO/troggle troggle
sudo ln -s /mnt/c/EXPO/loser loser
sudo ln -s /mnt/c/EXPO/drawings drawings
sudo ln -s /mnt/c/EXPO/expofiles expofiles
sudo ln -s /mnt/c/EXPO/expowebcache expowebcache
sudo mkdir expowebcache/3d
cd ..
ls -tlA expo

If you do not have a local copy of the 40GB /expofiles/, don't worry. Later on we can set 'EXPOFILESREMOTE = True' and your test system will use the live expofiles on expo.survex.com (read only).

Installing Django and troggle

django logo

The important point to note here is that unless you are doing something fairly trivial, or you are a git genius, it is sensible to set up a python virtual environments to hold duplicate copies of both troggle and django code. Then you will be able to check very quickly that your edited version of troggle runs with old, current and pre-release versions of python and of django; and you will more easily be able to manage problems with incompatible versions of django plugins as installing and upgrading the dependent packages is very fast.

Installing a venv

We set up a venv specifically for python 3.7 (which is the standard version on our server which is running unmodified Buster (debian v10) and django 2.2.19. See the standard python documentation on venv for python 3.7.12. You can upgrade the version of python installed within pip venv but not downgrade. So get that first venv installed right by explicitly stating the python version to create it python3.7 -m venv py37d22. Note that we are creating it as a sibling folder to /expoweb/ . Note also that up to now we have been using 'sudo ..' but for installing things inside the venv we do not use 'sudo ..':

cd ~
cd ../expo
python3.7 -m venv py37d22
cd py37d22
source bin/activate
pip list -o

The last command lists the default packages installed in the venv. This is for comparison later, after we have installed troggle, django and dependencies. You will get a warning that you have an out of date version of pipbut this is as we want: we are using a version of pip appropriate for the older version of python within the venv. troggle logo

Installing the troggle dependencies

The first time you do this on a new machine you can't complete the pip installation of django as you have not yet got the dependencies appropriate for troggle - because you have not yet cloned the troggle repo. So the first time it is easiest to just create requirements.txt yourself with a text editor. Without using git yourself, you can get the file from the website at requirements.txt. If you have already cloned all the repos, then just copy it.

cp ../troggle/requirements.txt .
where requirements.txt (note the capitalisation of the listed packages) is:
confusable-homoglyphs==3.2.0
Django==2.2
docutils==0.14
gunicorn==20.1.0
Pillow==5.4.1
pytz==2019.1
sqlparse==0.2.4
Unidecode==1.0.23
This will pick up the latest django 2.2.x available, but all the other dependencies are pinned. These dependencies are as-standard on debian Buster (10) and you will want to experiment with upgrading them for Bullseye (v11).

Once you have the file, install the listed dependencies like this:

pip install -r requirements.txt
pip list -o

Pillow is an image handling package used to make the prospecting map (currently disabled, see /prospecting_guide/).
tinymce is the wysiwyg in-browser editor (disabled pending reinstatement)

This is also documented in the updating django for troggle page where it describes upgrading and testing with later versions of django.

If you have not used pip before, read this

Installing troggle

The :troggle: repo is the python source code for troggle. This is what you will be editing. There are over 8,000 lines of python code (excluding comments and blank lines) and over 2,000 lines of HTML/django template code. This is over 600 files in over 400 folders, but only 38MB in size.

key exchange

Follow this link to register a key with the expo server to get git access if you have not already cloned the :troggle: repo.

git clone troggle

This creates a folder /troggle/ containing all the troggle code.

cd ~
cd ../expo
git clone ssh://expo@expo.survex.com/home/expo/troggle

Now we create soft links within the venv to all the repo folders and wherever you have a local copy of /expofiles/ and /expowebcache/:

cd py37d22
sudo ln -s /mnt/c/EXPO/expoweb expoweb
sudo ln -s /mnt/c/EXPO/troggle troggle
sudo ln -s /mnt/c/EXPO/loser loser
sudo ln -s /mnt/c/EXPO/drawings drawings
sudo ln -s /mnt/c/EXPO/expofiles expofiles
sudo ln -s /mnt/c/EXPO/expowebcache expowebcache

If you have not been using git on this machine until now, you will need to identify yourself before you go any further.

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

do the basic health checks

This all checks that the installation has completed properly.

django-admin
python manage.py
python manage.py check -v 3 --traceback

The first line django-admin will complain that it has not got a SETTINGS file, but that's fine. If it crashes though, you have not managed to install the software completely.

The most important is the python manage.py check. If this works, then you have installed the software correctly. Now we test whether troggle is configured correctly:

python manage.py test -v 3 --traceback

This will run the entire troggle test suite of over 70 tests (it takes only a few seconds). It will probably have a dozen or so failures which will probably be because it can't find the various bits of the rest of the website. So the next task is to edit the SETTINGS files to match your machine and folder structure. So find the appropriate copy of the localsettings in /_deploy/ and copy it into the main troggle folder:

cp _deploy/wsl/localsettingsWSL.py localsettings.py

Now edit it and insert useful values for EXPOUSERPASS [e.g. cavey:beery], EXPOADMINUSERPASS [e.g. beery:cavey], SECRET_KEY and make sure that LIBDIR refers to the actual version of python you are using (sorry, this should be automatic).

Check that FILES and EXPOFILES are set to wherever you have put /expofiles/ or set 'EXPOFILESREMOTE = False' which will use expofiles on expo.survex.com instead.

Set EMAIL_HOST and EMAIL_HOST_PASSWORD to an email account you control that can send email. Then troggle can email you when some things go wrong. This may mean having to set EMAIL_PORT and MAIL_USE_TLS too (this is not used in troggle currently). Set EXPOUSER_EMAIL and EXPOADMINUSER_EMAIL to your own email address while you are doing software development. All these will be different when troggle is deployed on the public server.

check full functionality

The test suite hardly skims the surface of what troggle does. You need to manually test all these too:
- http://localhost:8000/pathsreport
- http://localhost:8000/stats
- http://localhost:8000/people
- http://localhost:8000/expedition/2018
- http://localhost:8000/expofiles/surveyscans/2019/walletindex.html
- http://localhost:8000/survey_scans/
- http://localhost:8000/survexfile/caves/
- http://localhost:8000/expofiles/rigging_topos/264/entrance_topo_2016.pdf
- http://localhost:8000/expofiles/rigging_topos/264/entrance_topo_2016.svg
- http://localhost:8000/expofiles/rigging_topos/264/entrance_topo1_2016.jpeg
- http://localhost:8000/expofiles/training-info/Idiots guide to accessing expo git.pptx
- http://localhost:8000/1623/291/291.htm
- http://localhost:8000/caves
- ttp://localhost:8000/admin/doc/models/core.expedition/ (admin login required)
- http://localhost:8000/survexfile/204 Nearly half the code deals with importing and parsing data, so you need to test that a full data import works. Run the full data import troggle$ python databaseReset.py reset R000. It should take about 5 minutes to import everything.

Use git to commit your edits

You need to know git. Sorry, but there it is. See our git repositories and our git cheat sheet.


Go on to: Troggle architecture
Return to: Troggle programmers' guide
Troggle index: Index of all troggle documents