From bb6e3d02fdee8460aed302d1d3998a7ac1913f1d Mon Sep 17 00:00:00 2001 From: bharath Date: Wed, 10 Oct 2018 23:47:22 +0530 Subject: [PATCH] Adds bash completion Change-Id: I4d427cd89e20e62d6c197e3f098cf4b1502b373b --- tools/cover.sh | 69 ++++++++++++++++++++++++++++++++++++++ tools/fast8.sh | 16 +++++++++ tools/flake8wrap.sh | 20 +++++++++++ tools/gen-config | 3 ++ tools/gyan.bash_completion | 27 +++++++++++++++ tools/gyan.zsh_completion | 29 ++++++++++++++++ tools/run_functional.sh | 29 ++++++++++++++++ 7 files changed, 193 insertions(+) create mode 100755 tools/cover.sh create mode 100644 tools/fast8.sh create mode 100755 tools/flake8wrap.sh create mode 100755 tools/gen-config create mode 100644 tools/gyan.bash_completion create mode 100644 tools/gyan.zsh_completion create mode 100755 tools/run_functional.sh diff --git a/tools/cover.sh b/tools/cover.sh new file mode 100755 index 0000000..c361805 --- /dev/null +++ b/tools/cover.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +ALLOWED_EXTRA_MISSING=0 + +show_diff () { + head -1 $1 + diff -U 0 $1 $2 | sed 1,2d +} + +if ! git diff --exit-code || ! git diff --cached --exit-code +then + echo "There are uncommitted changes!" + echo "Please clean git working directory and try again" + exit 1 +fi + +# Checkout master and save coverage report +git checkout HEAD^ + +baseline_report=$(mktemp -t gyanclient_coverageXXXXXXX) +find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*" +coverage report > $baseline_report +mv cover cover-master +cat $baseline_report +baseline_missing=$(awk 'END { print $3 }' $baseline_report) + +# Checkout back and save coverage report +git checkout - + +current_report=$(mktemp -t gyanclient_coverageXXXXXXX) +find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*" +coverage report > $current_report +current_missing=$(awk 'END { print $3 }' $current_report) + +# Show coverage details +allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING)) + +echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}" +echo "Missing lines in master : ${baseline_missing}" +echo "Missing lines in proposed change : ${current_missing}" + +if [ $allowed_missing -ge $current_missing ]; then + if [ $baseline_missing -lt $current_missing ]; then + show_diff $baseline_report $current_report + echo "We believe you can test your code with 100% coverage!" + else + echo "Thank you! You are awesome! Keep writing unit tests! :)" + fi + exit_code=0 +else + show_diff $baseline_report $current_report + echo "Please write more unit tests, we must maintain our test coverage :( " + exit_code=1 +fi + +rm $baseline_report $current_report +exit $exit_code diff --git a/tools/fast8.sh b/tools/fast8.sh new file mode 100644 index 0000000..3ee00a0 --- /dev/null +++ b/tools/fast8.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cd $(dirname "$0")/.. +CHANGED=$(git diff --name-only HEAD~1 | tr '\n' ' ') + +# Skip files that don't exist +# (have been git rm'd) +CHECK="" +for FILE in $CHANGED; do + if [ -f "$FILE" ]; then + CHECK="$CHECK $FILE" + fi +done + +diff -u --from-file /dev/null $CHECK | flake8 --diff + diff --git a/tools/flake8wrap.sh b/tools/flake8wrap.sh new file mode 100755 index 0000000..919ea67 --- /dev/null +++ b/tools/flake8wrap.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# +# A simple wrapper around flake8 which makes it possible +# to ask it to only verify files changed in the current +# git HEAD patch. +# +# Intended to be invoked via tox: +# +# tox -epep8 -- -HEAD +# + +if test "x$1" = "x-HEAD" ; then + shift + files=$(git diff --name-only HEAD~1 | tr '\n' ' ') + echo "Running flake8 on ${files}" + diff -u --from-file /dev/null ${files} | flake8 --max-complexity 10 --diff "$@" +else + echo "Running flake8 on all files" + exec flake8 --max-complexity 10 "$@" +fi diff --git a/tools/gen-config b/tools/gen-config new file mode 100755 index 0000000..eb4046d --- /dev/null +++ b/tools/gen-config @@ -0,0 +1,3 @@ +#!/bin/sh + +oslo-config-generator --config-file=tools/gyan-config-generator.conf diff --git a/tools/gyan.bash_completion b/tools/gyan.bash_completion new file mode 100644 index 0000000..ea0dda3 --- /dev/null +++ b/tools/gyan.bash_completion @@ -0,0 +1,27 @@ +_gyan_opts="" # lazy init +_gyan_flags="" # lazy init +_gyan_opts_exp="" # lazy init +_gyan() +{ + local cur prev nbc cflags + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [ "x$_gyan_opts" == "x" ] ; then + nbc="`gyan bash-completion | sed -e "s/ *-h */ /" -e "s/ *-i */ /"`" + _gyan_opts="`echo "$nbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/ */ /g"`" + _gyan_flags="`echo " $nbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/ */ /g"`" + _gyan_opts_exp="`echo "$_gyan_opts" | tr ' ' '|'`" + fi + + if [[ " ${COMP_WORDS[@]} " =~ " "($_gyan_opts_exp)" " && "$prev" != "help" ]] ; then + COMPLETION_CACHE=~/.gyanclient/*/*-cache + cflags="$_gyan_flags "$(cat $COMPLETION_CACHE 2> /dev/null | tr '\n' ' ') + COMPREPLY=($(compgen -W "${cflags}" -- ${cur})) + else + COMPREPLY=($(compgen -W "${_gyan_opts}" -- ${cur})) + fi + return 0 +} +complete -F _gyan gyan diff --git a/tools/gyan.zsh_completion b/tools/gyan.zsh_completion new file mode 100644 index 0000000..7fa2b25 --- /dev/null +++ b/tools/gyan.zsh_completion @@ -0,0 +1,29 @@ +#compdef gyan + +local -a nbc _gyan_opts _gyan_flags _gyan_opts_exp cur prev + +nbc=(${(ps: :)$(_call_program options "$service bash-completion" 2>/dev/null)}) +_gyan_opts=(${nbc:#-*}) +_gyan_flags=(${(M)nbc:#-*}) +_gyan_opt_exp=${${nbc:#-*}// /|} +cur=$words[CURRENT] +prev=$words[(( CURRENT - 1 ))] + +_checkcomp(){ + for word in $words[@]; do + if [[ -n ${_gyan_opts[(r)$word]} ]]; then + return 0 + fi + done + return 1 +} + +echo $_gyan_opts[@] |grep --color gyan +if [[ "$prev" != "help" ]] && _checkcomp; then + COMPLETION_CACHE=(~/.gyanclient/*/*-cache) + cflags=($_gyan_flags[@] ${(ps: :)$(cat $COMPLETION_CACHE 2>/dev/null)}) + compadd "$@" -d $cflags[@] +else + compadd "$@" -d $_gyan_opts[@] +fi + diff --git a/tools/run_functional.sh b/tools/run_functional.sh new file mode 100755 index 0000000..00784f9 --- /dev/null +++ b/tools/run_functional.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +FUNC_TEST_DIR=$(dirname $0)/../gyanclient/tests/functional/ +CONFIG_FILE=$FUNC_TEST_DIR/test.conf + +if [[ -n "$OS_AUTH_TOKEN" ]] && [[ -n "$GYAN_URL" ]]; then +cat <$CONFIG_FILE +[functional] +api_version = 1 +auth_strategy=noauth +os_auth_token=$OS_AUTH_TOKEN +gyan_url=$GYAN_URL +END +else +cat <$CONFIG_FILE +[functional] +api_version = 1 +os_auth_url=$OS_AUTH_URL +os_identity_api_version = $OS_IDENTITY_API_VERSION +os_username=$OS_USERNAME +os_password=$OS_PASSWORD +os_project_name=$OS_PROJECT_NAME +os_user_domain_id=$OS_USER_DOMAIN_ID +os_project_domain_id=$OS_PROJECT_DOMAIN_ID +os_service_type=container +os_endpoint_type=public +END +fi +tox -e functional -- --concurrency=1