From 93394c8136a7cd2b3485da60c7a2239f66f426f5 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Thu, 19 Oct 2023 14:12:26 +0200 Subject: [PATCH] Add virtualenv, use of .env and logging --- .gitignore | 2 ++ log/.gitignore | 3 +++ requirements.txt | 3 +++ run_SEPTREFHUM.sh | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 log/.gitignore create mode 100644 requirements.txt create mode 100755 run_SEPTREFHUM.sh diff --git a/.gitignore b/.gitignore index 2a12b1d..7db8917 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.nc *.tif *.tif.aux.xml +.env +.venv mapfile/SEPTREFHUM.map diff --git a/log/.gitignore b/log/.gitignore new file mode 100644 index 0000000..e7a210e --- /dev/null +++ b/log/.gitignore @@ -0,0 +1,3 @@ +* +*/ +!.gitignore \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e8283df --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Jinja2 +netCDF4 +pytz \ No newline at end of file diff --git a/run_SEPTREFHUM.sh b/run_SEPTREFHUM.sh new file mode 100755 index 0000000..56284b1 --- /dev/null +++ b/run_SEPTREFHUM.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# First: Test that we have CDO and GDAL installed +if ! command -v cdo &> /dev/null +then + echo "ERROR: CDO could not be found. Exiting." + exit +fi + +if ! command -v gdal_merge.py &> /dev/null +then + echo "ERROR: GDAL is either not installed, or not built with Python support. Exiting." + exit +fi + +# Defines HOME_DIR +source .env + +# Paths to scripts and requirements +APP_PATH=$HOME_DIR/SEPTREFHUM +LOG_FILE=$APP_PATH/log/SEPTREFHUM.log +REQUIREMENTS=$APP_PATH/requirements.txt + +cd $APP_PATH + +# Create and activate the virtual environment +python3 -m venv .venv +. .venv/bin/activate +python3 -m pip install --upgrade pip +pip install -r $REQUIREMENTS + +# Run the model +echo "==== `date`: Running model" &>> "$LOG_FILE" +python3 $APP_PATH/SEPTREFHUM.py &>> "$LOG_FILE" +echo "==== `date`: DONE running model" &>> "$LOG_FILE" + +# Deactivate the virtual environment +deactivate -- GitLab