Skip to content

Commit 240fb8e

Browse files
committed
Added --clean option to function-python-setup.sh.
1 parent 379976a commit 240fb8e

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

scripts/function-python-setup.sh

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ display_usage() {
5050

5151
FX_NAME_PARAM=''
5252
ALL='false'
53+
CLEAN='false'
5354
while [[ $# -gt 0 ]]; do
5455
key="$1"
5556

@@ -67,6 +68,10 @@ while [[ $# -gt 0 ]]; do
6768
shift # past argument
6869
shift # past value
6970
;;
71+
--clean)
72+
CLEAN="true"
73+
shift
74+
;;
7075
*) # unknown option
7176
shift # past argument
7277
;;
@@ -138,23 +143,46 @@ create_symbolic_links() {
138143

139144
for folder in $folders; do
140145
src_folder="$root_folder/$folder"
141-
relative_path=$(python3 -c "import os.path; print(os.path.relpath('$src_folder', '$dst_folder'))")
142-
echo "INFO: Linking $relative_path to $dst_folder"
143-
(cd $dst_folder && ln -s $relative_path)
146+
if [[ "$dst_folder" != "$src_folder"* ]]; then
147+
relative_path=$(python3 -c "import os.path; print(os.path.relpath(\"$src_folder\", \"$dst_folder\"))")
148+
echo "INFO: Linking $relative_path to $dst_folder"
149+
(cd $dst_folder && ln -s $relative_path)
150+
else
151+
echo "INFO: $dst_folder is a descendant of $src_folder, skipping"
152+
fi
144153
done
145154
}
146155

156+
clean_shared_folders() {
157+
function_name=$1
158+
# Remove ending / if any
159+
function_name=${function_name%/}
160+
echo "INFO: Cleaning shared folders for function $function_name"
161+
rm "$FUNCTIONS_PATH/$function_name/src/shared/"* > /dev/null 2>&1
162+
rmdir "$FUNCTIONS_PATH/$function_name/src/shared" > /dev/null 2>&1
163+
rm "$FUNCTIONS_PATH/$function_name/src/test_shared/"* > /dev/null 2>&1
164+
rmdir "$FUNCTIONS_PATH/$function_name/src/test_shared" > /dev/null 2>&1
165+
}
166+
147167
if [ "$ALL" = "true" ]; then
148168
# get all the functions in the functions-python folder that contain a function_config.json file
149169
for function in $(find "$FUNCTIONS_PATH" -maxdepth 2 -name "function_config.json"); do
150170
function_name=$(echo "$function" | rev | cut -d '/' -f 2 | rev)
151-
setup_function $function_name
171+
if [ "$CLEAN" = "true" ]; then
172+
clean_shared_folders $function_name
173+
else
174+
setup_function $function_name
175+
fi
152176
done
153177
else
154178
if [ -z "$FX_NAME_PARAM" ]; then
155179
printf "\nERROR: function name not provided"
156180
display_usage
157181
exit 1
158182
fi
159-
setup_function $FX_NAME_PARAM
183+
if [ "$CLEAN" = "true" ]; then
184+
clean_shared_folders $FX_NAME_PARAM
185+
else
186+
setup_function $FX_NAME_PARAM
187+
fi
160188
fi

0 commit comments

Comments
 (0)