From 5ee5d653d5005a90fd1b73710506acb290b99bd5 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 31 May 2013 20:39:49 +0900 Subject: [PATCH] create project --- .gitignore | 2 ++ LICENSE | 20 ++++++++++++++++ README.md | 52 ++++++++++++++++++++++++++++++++++++++++++ bin/pyenv-update | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100755 bin/pyenv-update diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f67ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swo +*.swp diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b70c6cf --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2013 Yamashita, Yuu + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9136c39 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# pyenv-update + +pyenv-update is a [pyenv](https://github.com/yyuu/pyenv) plugin +that provides a `pyenv update` command to update pyenv and its plugins. + +This plugin was inspired from [rbenv-update](https://github.com/rkh/rbenv-update). + +## Installation + +### Installing as a pyenv plugin + +Installing pyenv-update as a pyenv plugin will give you access to the +`pyenv update` command. + + $ git clone git://github.com/yyuu/pyenv-update.git ~/.pyenv/plugins/pyenv-update + +## Usage + +To update pyenv and plugins (including pyenv-update itself), just type `pyenv update`. + + $ pyenv update + +## Version History + +#### 20130531 + + * Initial public release. + +### License + +(The MIT License) + +* Copyright (c) 2013 Yamashita, Yuu + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/bin/pyenv-update b/bin/pyenv-update new file mode 100755 index 0000000..25f5303 --- /dev/null +++ b/bin/pyenv-update @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +set -e +[ -n "$PYENV_DEBUG" ] && set -x + +if [ -z "$PYENV_ROOT" ]; then + PYENV_ROOT="${HOME}/.pyenv" +fi + +verify_repo_origin() { + local repo="$1" + ( cd "${repo}" && git remote show origin 1>/dev/null 2>&1 ) || return 1 +} + +verify_repo_master() { + local repo="$1" + local name="$(cd "${repo}" && git name-rev --name-only HEAD 2>/dev/null)" + [[ "${name}" == "master" ]] || return 1 +} + +verify_repo_clean() { + local repo="$1" + if ( cd "${repo}" | git status --short ) | grep -q -v '^[!?][!?]'; then + return 1 + else + return 0 + fi +} + +verify_repo() { + local repo="$1" + if ! verify_repo_origin "${repo}"; then + echo "pyenv: ${repo} does not have origin." 1>&2 + return 1 + fi + if ! verify_repo_master "${repo}"; then + echo "pyenv: ${repo} is not on master branch." 1>&2 + return 1 + fi + if ! verify_repo_clean "${repo}"; then + echo "pyenv: ${repo} is not clean" 1>&2 + return 1 + fi +} + +update_repo() { + local repo="$1" + if ! verify_repo "${repo}"; then + return 1 + fi + ( cd "${repo}" && git pull origin master ) +} + +for repo in "${PYENV_ROOT}" "${PYENV_ROOT}/plugins/"*; do + if [ -d "${repo}/.git" ]; then + echo "Updating ${repo}..." 1>&2 + update_repo "${repo}" || exit 1 + fi +done