Merge pull request #36 from tuvistavie/update-pyenv

Add logic to update pyenv every hour
This commit is contained in:
Daniel Perez 2018-07-14 11:45:28 +09:00 committed by GitHub
commit 05749c0f1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/pyenv /pyenv
/pyenv_last_update

View file

@ -2,7 +2,7 @@
set -e set -e
source "$(dirname "$0")"/utils.sh source "$(dirname "$0")/utils.sh"
install_python() { install_python() {
local install_type=$1 local install_type=$1
@ -14,6 +14,7 @@ install_python() {
echoerr "For a list of available versions, see \`asdf list-all python\`." echoerr "For a list of available versions, see \`asdf list-all python\`."
exit 1 exit 1
fi fi
install_or_update_python_build
echo "python-build $version $install_path" echo "python-build $version $install_path"
$(python_build_path) "$version" "$install_path" $(python_build_path) "$version" "$install_path"

View file

@ -3,8 +3,7 @@
source "$(dirname "$0")/utils.sh" source "$(dirname "$0")/utils.sh"
list_all() { list_all() {
ensure_python_build_installed install_or_update_python_build
$(python_build_path) --definitions | tr '\n' ' ' $(python_build_path) --definitions | tr '\n' ' '
} }

View file

@ -18,6 +18,38 @@ python_build_path() {
echo "$(pyenv_path)/plugins/python-build/bin/python-build" echo "$(pyenv_path)/plugins/python-build/bin/python-build"
} }
update_python_build() {
cd "$(pyenv_path)" && git fetch && git reset --hard origin/master > /dev/null 2>&1
}
pyenv_path() { pyenv_path() {
echo "$(dirname $(dirname $0))/pyenv" echo "$(dirname $(dirname $0))/pyenv"
} }
pyenv_update_timestamp_path() {
echo "$(dirname $(dirname "$0"))/pyenv_last_update"
}
pyenv_should_update() {
update_timeout=3600
update_timestamp_path=$(pyenv_update_timestamp_path)
if [ ! -f "$update_timestamp_path" ]; then
return 0
fi
last_update=$(cat "$update_timestamp_path")
current_timestamp=$(date +%s)
invalidated_at=$(($last_update + $update_timeout))
[ $invalidated_at -lt $current_timestamp ]
}
install_or_update_python_build() {
if [ ! -f "$(python_build_path)" ]; then
download_python_build
elif pyenv_should_update; then
update_python_build
date +%s > "$(pyenv_update_timestamp_path)"
fi
}