Let's try this again.

This commit is contained in:
Daniel Dayley 2021-07-25 18:27:31 -06:00
parent 2e461efb59
commit ba273d6152

View File

@ -31,7 +31,7 @@ sed_i() {
__missing_sed && return 1; __missing_sed && return 1;
if [[ "$OS" == "macOS" ]]; then if [[ "$OS" == "macOS" ]]; then
if [[ $(type gsed 2>/dev/null) != "" ]]; then if [[ $(type gsed 2>/dev/null) != "" ]]; then
gsed -i $@; gsed -i "$@";
else else
sed -i '' $@; sed -i '' $@;
fi; fi;
@ -43,27 +43,36 @@ sed_i() {
# Project creation # Project creation
new_python_tool() { new_python_tool() {
# Download and rename the template repo
__missing_reqs 'sed git find grep sort mv' && return 1 __missing_reqs 'sed git find grep sort mv' && return 1
if [[ $(pwd) == *"python-tool"* ]]; then if [[ $(pwd) == *"cooltool"* ]]; then
echo "This script should not be run within the python-tool directory. Please move it to a neutral location to run." && return 1 echo "This script should not be run within the cooltool directory. Please move it to a neutral location to run." && return 1
fi fi
NAME="$1" NAME="$1"
if [[ $(echo "$1" | sed 's#^[a-z0-9\-]*$##' ) == "$NAME" ]]; then if [[ $(echo "$1" | sed 's#^[a-z0-9\-]*$##' ) == "$NAME" ]]; then
echo "Tool name '""$NAME""' is invalid." && return 1 echo "Tool name '""$NAME""' is invalid." && return 1
fi fi
if [ ! -d ./python-tool ]; then if [ ! -d ./cooltool ]; then
echo "Downloading template..." echo "Downloading template..."
git clone 'https://github.com/Cronocide/python-tool.git' git clone 'https://github.com/Cronocide/cooltool.git'
fi fi
echo "Renaming project..." echo "Renaming project..."
# Rather novel approach from https://stackoverflow.com/a/53734138 # Rather novel approach from https://stackoverflow.com/a/53734138
find ./ -depth -name '*python-tool*' | while IFS= read -r i; do mv $i ${i%python-tool*}$NAME${i##*python-tool}; done find ./ -depth -name '*cooltool*' | while IFS= read -r i; do mv $i ${i%cooltool*}$NAME${i##*cooltool}; done
# "I'm assuming you have no spaces in the project name because you're not an idiot." # "I'm assuming you have no spaces in the project name because you're not an idiot."
for i in $(grep -r 'python-tool' ./"$NAME" | grep -v '.git' | cut -d \: -f 1 | sort -u); do for i in $(grep -r 'cooltool' ./"$NAME" | grep -v '.git' | cut -d \: -f 1 | sort -u); do
sed_i "s#python-tool#$NAME#g" "$i" sed_i "s#cooltool#$NAME#g" "$i"
done done
mv ./"$NAME"/com.cronocide."$NAME".plist ./"$NAME"/com."$USER"."$NAME".plist mv ./"$NAME"/com.cronocide."$NAME".plist ./"$NAME"/com."$USER"."$NAME".plist
echo "Configuring project..." echo "Configuring project..."
# Describe the project
echo "Describe the project: "
read DESCRIPTION
sed_i "s/## ->.*//g" ./"$NAME"/README.md
sed_i "s/## Description/## $DESCRIPTION/g" ./"$NAME"/README.md
sed_i "s/\(.*\)description='',/\1description='$DESCRIPTION',/g" ./"$NAME"/setup.py
# Configure package as a module? # Configure package as a module?
while [[ "$PYTHON_MODULE" != 'y' && "$PYTHON_MODULE" != "n" ]]; do while [[ "$PYTHON_MODULE" != 'y' && "$PYTHON_MODULE" != "n" ]]; do
echo "Set up project as a module? (in addition to a singular executable script) (y/n)" echo "Set up project as a module? (in addition to a singular executable script) (y/n)"
@ -72,7 +81,9 @@ new_python_tool() {
if [ "$PYTHON_MODULE" == 'y' ]; then if [ "$PYTHON_MODULE" == 'y' ]; then
mkdir ./"$NAME"/"$NAME" mkdir ./"$NAME"/"$NAME"
touch ./"$NAME"/"$NAME"/__init__.py touch ./"$NAME"/"$NAME"/__init__.py
touch ./"$NAME"/"$NAME"/"$NAME".py
fi fi
# Configure package to install as a persistent service? # Configure package to install as a persistent service?
while [[ "$SERVICE_FILE" != 'y' && "$SERVICE_FILE" != "n" ]]; do while [[ "$SERVICE_FILE" != 'y' && "$SERVICE_FILE" != "n" ]]; do
echo "Install a persistent service file? (y/n)" echo "Install a persistent service file? (y/n)"
@ -94,23 +105,36 @@ new_python_tool() {
else else
# Remove the custom setup scripts # Remove the custom setup scripts
sed_i 's#cmdclass=.*##g' ./"$NAME"/setup.py sed_i 's#cmdclass=.*##g' ./"$NAME"/setup.py
rm ./"$NAME"/com.cronocide."$NAME".plist rm ./"$NAME"/com."$USER"."$NAME".plist
rm ./"$NAME"/"$NAME".service rm ./"$NAME"/"$NAME".service
rm ./"$NAME"/setup.sh
fi fi
# Configure package to load plugins from plugins directory? # Configure package to load plugins from plugins directory?
while [[ "$USE_PLUGINS" != 'y' && "$USE_PLUGINS" != "n" ]]; do while [[ "$USE_PLUGINS" != 'y' && "$USE_PLUGINS" != "n" ]]; do
echo "Configure package to load plugins? (y/n)" echo "Configure package to load plugins? (y/n)"
read USE_PLUGINS read USE_PLUGINS
done done
if [ "$USE_PLUGINS" == 'y' ]; then if [ "$USE_PLUGINS" == 'y' ]; then
echo "You've made Thomas Hatch proud." # You've made Thomas Hatch proud.
! [ -d ./"$NAME"/"$NAME" ] && mkdir ./"$NAME"/"$NAME" ! [ -d ./"$NAME"/"$NAME" ] && mkdir ./"$NAME"/"$NAME"
mkdir ./"$NAME"/"$NAME"/plugins mkdir ./"$NAME"/"$NAME"/plugins
else : else :
sed_i 's#.*plugins.*##g' ./"$NAME"/setup.py sed_i 's#.*plugins.*##g' ./"$NAME"/setup.py
fi fi
# Configure package to install a default configuration file? # Configure package to install a default configuration file?
while [[ "$INSTALL_CONFIG" != 'y' && "$INSTALL_CONFIG" != "n" ]]; do
echo "Configure package to load plugins? (y/n)"
read INSTALL_CONFIG
done
if [ "$INSTALL_CONFIG" == 'y' ]; then
sed_i "s#INSTALL=\"\(.*\)\"#INSTALL=\"\1config \"#g" ./"$NAME"/setup.sh
fi
# Remove setup.sh if our tool doesn't need it to install.
if [ "$SERVICE_FILE" != 'y' && "$INSTALL_CONFIG" != 'y' ]; then
rm ./"$NAME"/setup.sh
fi
# Initialize the git repo # Initialize the git repo
rm -rf ./"$NAME"/.git rm -rf ./"$NAME"/.git
@ -119,12 +143,15 @@ new_python_tool() {
# Next steps # Next steps
echo "Next steps:" echo "Next steps:"
echo " 1. Modify your bin/$NAME file to load your project libraries (if applicable)" echo " 1. Modify your bin/$NAME file to load your project libraries (if applicable)"
echo " 2. Add your git remote to the repo" echo " 2. Add a remote to the git repo"
echo " 3. Include the correct dependencies in setup.py" echo " 3. Add the correct dependencies in setup.py"
echo " 4. Update the execution and logging parameters in your service files (if applicable)" echo " 4. Update the execution and logging parameters in your service files (if applicable)"
echo " 5. Write the software" echo " 5. Write the software"
echo " 6. ..."
echo " 7. Profit"
# Delete self from project_file # Delete self from project_file
[ -f /"$NAME"/new_python_tool.sh ] && echo "Removing project setup script..." && rm ./"$NAME"/new_python_tool.sh [ -f ./"$NAME"/new_python_tool.sh ] && echo "Removing project setup script..." && rm ./"$NAME"/new_python_tool.sh
echo "Python tool $NAME is ready to start." echo "Python tool $NAME is ready to start."
} }