From 86b8444c034adb206aa3617aeb3ac0e88a9070a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Tue, 10 Feb 2026 13:56:16 +0100 Subject: [PATCH] .local/bin: added new fuctions for creating `python_env` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .local/bin/functions | 42 ++++++++++++++++++++++++++++++++++++++++++ .local/bin/python_env | 20 ++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 .local/bin/functions create mode 100755 .local/bin/python_env diff --git a/.local/bin/functions b/.local/bin/functions new file mode 100755 index 0000000..44ed4d8 --- /dev/null +++ b/.local/bin/functions @@ -0,0 +1,42 @@ +################################################################################ +# +# Marcin Wozniak +# +# shellcheck disable=1091 +################################################################################ + +# Colours +RED='\033[0;31m' +GREEN='\033[0;0;32m' +NC='\033[0m' + +function timestamp() { + echo -e "${GREEN}[+]${NC} $(date +'%F %T') [INFO] $*" +} + +function err() { + echo -e "${RED}[-] $(date +'%F %T') [ERROR] $*${NC}" >&2 + exit 0 +} + +function removelogs() { + find "$DIR/logs" -mindepth 1 -mtime +365 -delete +} + +function command_start() { + timestamp "Command $* has been started." + if ! "$@"; then + err "Command $* went wrong." + # sendmailerr + fi + timestamp "Command $* has been ended." +} + +function command_exists() { + if command -v "$1" > /dev/null 2>&1; then + timestamp "Command $1 has been found" + else + err "Command $1 has been NOT found" + # sendmailerr + fi +} diff --git a/.local/bin/python_env b/.local/bin/python_env new file mode 100755 index 0000000..6ca8380 --- /dev/null +++ b/.local/bin/python_env @@ -0,0 +1,20 @@ +#!/bin/bash + +source "$HOME"/.local/bin/functions + +# Function for creating a python env +python_env(){ + + [ -z "$PYTHONVERSION" ] && err "Python version is not set" + + command_exists virtualenv + + timestamp "Creating Python environment with version $PYTHONVERSION" + rm -rf .venv .env && timestamp "Old Python environment has been removed" + virtualenv -p "$PYTHONVERSION" .venv + + .venv/bin/python -m pip install --upgrade pip + .venv/bin/pip install -r requirements.txt --break --force +} + +python_env "$@"