#!/bin/bash

export TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN=command-not-found

if [[ ${1} == "" ]]; then
    echo $"Usage ${0} python_module"
    exit 1
fi

if [[ "$(which scout)" == "" ]]; then
    exit 2
fi

module_name=$(echo ${1} | sed 's/No module named //')

modules=$(/usr/bin/scout -f csv python ${module_name} | sed '1,2d' | cut -d ';' -f 2 | tr -d '"' | uniq)

modules_cnt=$(echo ${modules} | wc -w)

echo -e "\n"
case ${modules_cnt} in
    0)
    echo $"No package was found by scout"
    ;;
    1)
    echo $"The ${module_name} is in the package ${modules}. You can install it by:"
    echo "sudo zypper install ${modules}"
    ;;
    *)
    echo $"The selected module was found in one of several packages:"
    echo "${modules}"
    tr=$"one_of_the_packages"
    echo "sudo zypper install <$tr>"
    ;;
esac
