Merge pull request #288 from jmherbst/remove-python-shebangs

Removing python shebangs and adding python3 virtual env to callsites
This commit is contained in:
Patrick McGuire
2022-05-24 12:13:00 -04:00
committed by GitHub
5 changed files with 73 additions and 21 deletions
+5 -2
View File
@@ -77,6 +77,9 @@ move_analyzed() {
# Uses one argument:
# - {DIRECTORY}
run_analysis() {
PYTHON_VIRTUAL_ENV="$HOME/BirdNET-Pi/birdnet/bin/python3"
DIR="$HOME/BirdNET-Pi/scripts"
sleep .5
### TESTING NEW WEEK CALCULATION
@@ -125,7 +128,7 @@ run_analysis() {
BIRDWEATHER_ID_PARAM=""
BIRDWEATHER_ID_LOG=""
fi
echo analyze.py \
echo $PYTHON_VIRTUAL_ENV "$DIR\analyze.py" \
--i "${1}/${i}" \
--o "${1}/${i}.csv" \
--lat "${LATITUDE}" \
@@ -137,7 +140,7 @@ run_analysis() {
${INCLUDEPARAM} \
${EXCLUDEPARAM} \
${BIRDWEATHER_ID_LOG}
analyze.py \
$PYTHON_VIRTUAL_ENV $DIR/analyze.py \
--i "${1}/${i}" \
--o "${1}/${i}.csv" \
--lat "${LATITUDE}" \
+4 -2
View File
@@ -9,6 +9,8 @@ config_file=$my_dir/birdnet.conf
export USER=$USER
export HOME=$HOME
export PYTHON_VIRTUAL_ENV="$HOME/BirdNET-Pi/birdnet/bin/python3"
install_depends() {
apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
@@ -66,7 +68,7 @@ Restart=always
Type=simple
RestartSec=10
User=${USER}
ExecStart=/usr/local/bin/server.py
ExecStart=$PYTHON_VIRTUAL_ENV /usr/local/bin/server.py
[Install]
WantedBy=multi-user.target
EOF
@@ -309,7 +311,7 @@ Restart=always
RestartSec=120
Type=simple
User=$USER
ExecStart=/usr/local/bin/daily_plot.py
ExecStart=$PYTHON_VIRTUAL_ENV /usr/local/bin/daily_plot.py
[Install]
WantedBy=multi-user.target
EOF
+1
View File
@@ -177,6 +177,7 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=\"".str_replace('_', '+', $comname)."\"&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"];
foreach ($flickrjson as $val) {
$iter++;
$modaltext = "https://flickr.com/photos/".$val["owner"]."/".$val["id"];
$authorlink = "https://flickr.com/people/".$val["owner"];
+45 -4
View File
@@ -2,15 +2,56 @@
# Update BirdNET-Pi's Git Repo
source /etc/birdnet/birdnet.conf
trap 'exit 1' SIGINT SIGHUP
usage() { echo "Usage: $0 [-r <remote name>] [-b <branch name>]" 1>&2; exit 1; }
# Defaults
remote="origin"
branch="main"
while getopts ":r:b:" o; do
case "${o}" in
r)
remote=${OPTARG}
git remote show $remote > /dev/null 2>&1
ret_val=$?
if [ $ret_val -ne 0 ]; then
echo "Error: remote '$remote' not found. Add the upstream remote to your repository and try again."
exit 1
fi
;;
b)
branch=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
my_dir=$HOME/BirdNET-Pi/scripts
sudo -u$USER git -C $my_dir rm privacy_server.py
sudo -u${USER} git -C $my_dir stash
sudo -u${USER} git -C $my_dir pull -f
sudo_with_user () {
set -x
sudo -u $USER "$@"
set +x
}
# Reset current HEAD to remove any local changes
sudo_with_user git reset --hard
# Fetches latest changes
sudo_with_user git fetch $remote $branch
# Switches git to specified branch
sudo_with_user git switch -C $branch --track $remote/$branch
sudo systemctl daemon-reload
sudo -u${USER} git -C $my_dir stash pop
sudo ln -sf $my_dir/* /usr/local/bin/
# The script below handles changes to the host system
+9 -4
View File
@@ -5,10 +5,7 @@ trap 'exit 1' SIGINT SIGHUP
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
my_dir=$HOME/BirdNET-Pi/scripts
if ! grep python3 <(head -n1 $my_dir/analyze.py) &>/dev/null;then
echo "Ensure all python scripts use the virtual environment"
sudo -u$USER sed -si "1 i\\#\!$HOME/BirdNET-Pi/birdnet/bin/python3" $my_dir/*.py
fi
if ! grep PRIVACY_THRESHOLD /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "PRIVACY_THRESHOLD=0" >> /etc/birdnet/birdnet.conf
git -C $HOME/BirdNET-Pi rm $my_dir/privacy_server.py
@@ -17,6 +14,14 @@ if [ -f $my_dir/privacy_server ] || [ -L /usr/local/bin/privacy_server.py ];then
rm -f $my_dir/privacy_server.py
rm -f /usr/local/bin/privacy_server.py
fi
# Adds python virtual-env to the python systemd services
if ! grep 'BirdNET-Pi/birdnet/' $HOME/BirdNET-Pi/templates/birdnet_server.service || ! grep 'BirdNET-Pi/birdnet' $HOME/BirdNET-Pi/templates/chart_viewer.service;then
sudo -E sed -i "s|ExecStart=.*|ExecStart=$HOME/BirdNET-Pi/birdnet/bin/python3 /usr/local/bin/server.py|" ~/BirdNET-Pi/templates/birdnet_server.service
sudo -E sed -i "s|ExecStart=.*|ExecStart=$HOME/BirdNET-Pi/birdnet/bin/python3 /usr/local/bin/daily_plot.py|" ~/BirdNET-Pi/templates/chart_viewer.service
sudo systemctl daemon-reload && restart_services.sh
fi
if grep privacy ~/BirdNET-Pi/templates/birdnet_server.service &>/dev/null;then
sudo -E sed -i 's/privacy_server.py/server.py/g' \
~/BirdNET-Pi/templates/birdnet_server.service