-
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathremove_code_extensions.blender.org.sh
More file actions
82 lines (67 loc) · 2.17 KB
/
remove_code_extensions.blender.org.sh
File metadata and controls
82 lines (67 loc) · 2.17 KB
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
#!/usr/bin/env bash
# require: bash version >= 4
# usage example: bash remove_code_extensions.blender.org.sh src output
set -eEu
function usage() {
echo "Usage: bash remove_code_extensions.blender.org.sh <source-directory> <output-directory>"
}
if [ $# -ne 2 ]; then
usage
exit 1
fi
SOURCE_DIR=${1}
OUTPUT_DIR=${2}
TMP_DIR=$(mktemp -d)
REMOVE_FILES=(
"screencast_keys/utils/addon_updater.py"
"screencast_keys/c_structure/.*.py"
)
mkdir -p "${OUTPUT_DIR}"
delete_block_start_regex="[^\S]*#[^\S]*extensions.blender.org: Delete block start"
delete_block_end_regex="[^\S]*#[^\S]*extensions.blender.org: Delete block end"
delete_line_regex="[^\S]*#[^\S]*extensions.blender.org: Delete line"
# shellcheck disable=SC2044
for file in $(find "${SOURCE_DIR}" -name "*.py" -or -name "*.glsl" -or -name "*.toml"); do
in_dir_path=$(dirname "${file}")
tmp_dir_path="${TMP_DIR}/${in_dir_path}"
mkdir -p "${tmp_dir_path}"
remove_file=0
for f in "${REMOVE_FILES[@]}"; do
if [[ "${file}" =~ $f ]]; then
remove_file=1
fi
done
if [ ${remove_file} -eq 1 ]; then
echo "${file} is removed."
continue
fi
enable_delete=0
tmp_file_path="${TMP_DIR}/${file}"
while IFS= read -r line || [ -n "${line}" ]; do
# Delete by line.
if [[ "${line}" =~ $delete_line_regex ]]; then
continue
fi
# Delete by block.
if [[ "${line}" =~ $delete_block_start_regex ]]; then
enable_delete=1
continue
elif [[ "${line}" =~ $delete_block_end_regex ]]; then
enable_delete=0
continue
fi
if [[ ${enable_delete} -eq 1 ]]; then
continue
fi
echo "${line}" >> "${tmp_file_path}"
done < "${file}"
echo "Remove code in ${file} >> ${tmp_file_path}"
done
# shellcheck disable=SC2044
for file in $(find "${TMP_DIR}" -name "*.py" -name "*.py" -or -name "*.glsl" -or -name "*.toml"); do
out_file_path=${file/${TMP_DIR}/${OUTPUT_DIR}}
out_dir_path=$(dirname "${out_file_path}")
mkdir -p "${out_dir_path}"
cp "${file}" "${out_file_path}"
echo "Copy file ${file} -> ${out_file_path}"
done