From 9dc6770fe2eb6d4f9547ecd74c58c5c839e2378d Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Wed, 13 Jul 2016 12:36:30 -0700 Subject: [PATCH] Add tool to track migration to neutron-lib Add a tool that tracks how far off a subproject is from breaking the dependency from neutron. Something fun to help us ease the pain. An example output is like the one below: You have 229 total imports You imported Neutron 78 times You imported Neutron-Lib 10 times You need to get to 100%, you are this far: 11.3600%, get on with it! Change-Id: I1a1d89a2628587e95e339524e5593191a27fe5bf --- tools/migration_report.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 tools/migration_report.sh diff --git a/tools/migration_report.sh b/tools/migration_report.sh new file mode 100755 index 000000000..bef8da14c --- /dev/null +++ b/tools/migration_report.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +function count_imports() { + local module="$1" + local path="$2" + egrep -R -w "^(import|from) $module" --exclude-dir=".*tox" $your_project | wc -l +} + + +if [ $# -eq 0 ]; then + echo "Please specify path to your project." + exit 1 +else + your_project="$1" +fi + +total_imports=$(egrep -R -w "^(import|from)" --exclude-dir=".*tox" $your_project | wc -l) +neutron_imports=$(count_imports neutron $your_project) +lib_imports=$(count_imports neutron_lib $your_project) +total_neutron_related_imports=$((neutron_imports + lib_imports)) + +echo "You have $total_imports total imports" +echo "You imported Neutron $neutron_imports times" +echo "You imported Neutron-Lib $lib_imports times" + +if [ "$lib_imports" -eq 0 ]; then + echo "Your project does not import neutron-lib once, you suck!" +fi + +goal=$(bc -l <<< "scale=4; ($lib_imports/$total_neutron_related_imports*100)") +target=$(bc <<< "$goal>50") + +if [ "$target" -eq 0 ]; then + echo "You need to get to 100%, you are this far: $goal%, get on with it!" +else + echo "You need to get to 100%, you are close: $goal%, good job!" +fi