python-packages-for-cn/shared/tool/get_imports_from_co_code.sh
2024-09-09 17:20:31 -04:00

33 lines
1.1 KiB
Bash
Executable File

SCRIPT_DIR=${0%/*}
SCRIPT_DIR=${0%$base}
SCRIPT_DIR=$(dirname $0)
SCRIPT_DIR="$( realpath -e -- "$SCRIPT_DIR"; )";
CODE_DIR=$1
echo $CODE_DIR
DEST_DIR="${SCRIPT_DIR}/../packages/names/"
DEST_DIR="$( realpath -e -- "$DEST_DIR"; )";
IMPORTS_FROM_CODE="${DEST_DIR}/imports_from_co_code.txt"
FROM_IMPORTS_CODE="${DEST_DIR}/from_imports_from_co_code.txt"
ALL_IMPORTS_FROM_CODE="${DEST_DIR}/all_imports_from_co_code.txt"
#### GET ALL IMPORTED MODULES FROM SRC CODE
pushd ${CODE_DIR}
ack --nogroup "^import " | cut -d':' -f3 | cut -d' ' -f2 | cut -d' ' -f1 | sort --unique > "${IMPORTS_FROM_CODE}"
ack --nogroup "^from " | cut -d':' -f3 | cut -d' ' -f2 | cut -d' ' -f1 | sort --unique > "${FROM_IMPORTS_CODE}"
# concatenate both lists and sort
cat ${IMPORTS_FROM_CODE} ${FROM_IMPORTS_CODE} > ${ALL_IMPORTS_FROM_CODE}
popd
exit
#### GET ALL AVAILABLE PACKAGES FROM PYTHON INSTALLATION
cd /usr/lib/python3.10/ && ls -1 *.py | cut -d'.' -f1 > ${DEST_DIR}/std_modules.txt
cd /usr/lib/python3.10/distutils && ls -1 *.py | cut -d'.' -f1 > ${DEST_DIR}/distutils.txt
cat ${DEST_DIR}/std_modules.txt ${DEST_DIR}/distutils.txt > ${DEST_DIR}/system_modules.txt