.local/bin: added new fuctions for creating python_env
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
42
.local/bin/functions
Executable file
42
.local/bin/functions
Executable file
@@ -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
|
||||||
|
}
|
||||||
20
.local/bin/python_env
Executable file
20
.local/bin/python_env
Executable file
@@ -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 "$@"
|
||||||
Reference in New Issue
Block a user