-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap-python
executable file
·89 lines (79 loc) · 2.19 KB
/
bootstrap-python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Configuration
###############
# Functions
###########
function show_help {
echo "Create a new python file from a template"
echo "Usage: $0 [options] [filename]"
echo "Options:"
echo -e "-h\tShow this help"
echo -e "-p\tUse the plugin framework"
}
# Ask a question, defaults to yes
function yes_no_question () {
read -r -p "$1 [Y/n] " response
response=${response,,}
if [[ "$response" =~ ^(yes|y|)$ ]]; then
return 0
else
return 1
fi
}
# Ask a question, defaults to no
function no_yes_question () {
read -r -p "$1 [Y/n] " response
response=${response,,}
if [[ "$response" =~ ^(no|n|)$ ]]; then
return 0
else
return 1
fi
}
# Useful Variables
##################
# Directory containing this script
# (no matter where it is called from)
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
script_dir="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Script
########
use_plugin_framework=false
# Read Command Line Arguments
while getopts "hp" opt; do
case "$opt" in
h)
show_help
exit 0
;;
p)
use_plugin_framework=true
;;
esac
done
# Shift the arguments so $1 refers to the script name
shift $(expr $OPTIND - 1 )
new_script_name="$1"
# Verify Parameters
if [ -z "$new_script_name" ]
then
echo -e "Path for new file:"
read new_script_name
fi
if [ "$use_plugin_framework" = true ]; then
# Copy plugin framework files
echo -e "Generating new .py file with plugin framework in $new_script_name..."
eval "cp -r $script_dir/bootstrap/python-plugins/* ."
eval "mv program.py $new_script_name"
eval "chmod +x $new_script_name"
else
# Copy Template to New File
echo -e "Generating new .py file in $new_script_name..."
eval "cp $script_dir/bootstrap/python $new_script_name"
eval "chmod +x $new_script_name"
fi