forked from smart-grid-use-cases/excel2xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_all_xlsx.sh
executable file
·80 lines (74 loc) · 1.98 KB
/
process_all_xlsx.sh
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
#!/bin/sh
set -o errexit
if [ -z "$1" ]
then
OUTPUT_DIR="/github/workspace/erigrid2-test-cases"
else
OUTPUT_DIR="$1"
fi
mkdir -p ${OUTPUT_DIR}
# RUN_EXCEL2MD=$(cat << EOM
# FILE=\$0
# OUTPUT_DIR="\$1"
# PREFIX="\$2"
# DIRNAMEPREFIX=\$(dirname "\${FILE}")
# IS_TLD=\$(echo \${DIRNAMEPREFIX} | grep "/")
# if [ \$? -eq 1 ]; then
# DIRNAME=/
# else
# DIRNAME=/\${DIRNAMEPREFIX#\$PREFIX}
# fi
# mkdir -p "\${OUTPUT_DIR}/\${DIRNAME}/"
# OUTPUT_FILE_NAME="\${OUTPUT_DIR}\${DIRNAME}/index.md"
# echo "Creating markdown files: \$OUTPUT_FILE_NAME"
# python3 xlsx2md.py "\$FILE" > "\${OUTPUT_FILE_NAME}"
# IMAGES=\$(find "\${DIRNAMEPREFIX}" -iname *.png)
# for IMAGE in \$IMAGES
# do
# echo Copying image file "\$IMAGE" into "\${OUTPUT_DIR}/\${DIRNAME}"
# cp "\$IMAGE" "\${OUTPUT_DIR}/\${DIRNAME}"
# done
# EOM
# )
RUN_EXCEL2MD=$(cat << EOM
FILE=\$0
OUTPUT_DIR="\$1"
PREFIX="\$2"
DIRNAMEPREFIX=\$(dirname "\${FILE}")
IS_TLD=\$(echo \${DIRNAMEPREFIX} | grep "/")
if [ \$? -eq 1 ]; then
DIRNAME=/
else
DIRNAME=/\${DIRNAMEPREFIX#\$PREFIX}
fi
mkdir -p "\${OUTPUT_DIR}/\${DIRNAME}/"
OUTPUT_FILE_DIRNAME="\${OUTPUT_DIR}\${DIRNAME}"
python3 xlsx2md.py "\$FILE" "\${OUTPUT_FILE_DIRNAME}"
IMAGES=\$(find "\${DIRNAMEPREFIX}" -iname *.png)
for IMAGE in \$IMAGES
do
echo Copying image file "\$IMAGE" into "\${OUTPUT_FILE_DIRNAME}"
cp "\$IMAGE" "\${OUTPUT_FILE_DIRNAME}"
done
EOM
)
# process all *.xlsx files from grupoetra and create index.md
find excel-input/* -type f -name '*.xlsx' -exec sh -c "$RUN_EXCEL2MD" {} ${OUTPUT_DIR} "excel-input/" ';'
find "${OUTPUT_DIR}" -type d -exec sh -c '
DIRPATH=$0
DIRNAME=$(basename "$DIRPATH")
if [ ! -f "${DIRPATH}/index.md" ]
then
if [ ! -f "${DIRPATH}/_index.md" ]
then
echo Creating title link for directory: $DIRPATH with title: $DIRNAME
cat > "${DIRPATH}/_index.md" <<EOF
---
title: "$DIRNAME"
linkTitle: "$DIRNAME"
weight: 5
---
EOF
fi
fi
' {} ${OUTPUT_DIR} ';'