4
2
mirror of https://github.com/getbible/v2_builder.git synced 2024-05-31 21:00:48 +00:00

Tweaks the progress counter. Formats more code with the IDE.

This commit is contained in:
Llewellyn van der Merwe 2021-04-21 06:09:09 +02:00
parent 1a03831b50
commit 1a8e28b613
Signed by: Llewellyn
GPG Key ID: EFC0C720A240551C
5 changed files with 45 additions and 38 deletions

52
run.sh
View File

@ -33,8 +33,11 @@ HEADERTITLE="getBible JSON API.v2"
function main() { function main() {
# Only Hash existing scripture JSON files # Only Hash existing scripture JSON files
if (("$HASHONLY" == 1)); then if (("$HASHONLY" == 1)); then
# numbers
number=$(ls "${DIR_zip}" | wc -l)
each_count=$((98 / number))
# the hashing of all files # the hashing of all files
hashingAll hashingAll "${each_count:-1}"
# show completion message # show completion message
completedBuildMessage completedBuildMessage
exit exit
@ -43,17 +46,17 @@ function main() {
if (("$DOWNLOAD" == 1)); then if (("$DOWNLOAD" == 1)); then
getModules "${DIR_zip}" getModules "${DIR_zip}"
fi fi
# prep the Scripture Main Git Folder
prepScriptureMainGit "${DIR_api}_scripture"
# numbers # numbers
number=$(ls "${DIR_zip}" | wc -l) number=$(ls "${DIR_zip}" | wc -l)
each_count=$((98 / $number)) each_count=$((98 / number))
# prep the Scripture Main Git Folder
prepScriptureMainGit "${DIR_api}_scripture"
# Build Static JSON Files # Build Static JSON Files
setStaticJsonFiles "${DIR_api}_scripture" "${DIR_zip}" "$number" "$each_count" setStaticJsonFiles "${DIR_api}_scripture" "${DIR_zip}" "${each_count:-1}"
# Remove Empty Folder & Static Files # Remove Empty Folder & Static Files
cleanSystem "${DIR_api}_scripture" cleanSystem "${DIR_api}_scripture"
# the hashing of all files # the hashing of all files
hashingAll hashingAll "${each_count:-1}"
# finally check if we must commit and push changes # finally check if we must commit and push changes
if (("$PUSH" == 1)); then if (("$PUSH" == 1)); then
"${DIR_src}/moveToGithub.sh" "${DIR_api}" "${DIR_src}/moveToGithub.sh" "${DIR_api}"
@ -82,7 +85,7 @@ function completedBuildMessage() {
# show the progress of all tasks # show the progress of all tasks
function showProgress() { function showProgress() {
if (("$QUIET" == 0)); then if (("$QUIET" == 0)); then
# little neardy ᒡ◯ᵔ◯ᒢ # little nerdy ᒡ◯ᵔ◯ᒢ
whiptail --title "$1" --gauge "$2" 7 77 0 whiptail --title "$1" --gauge "$2" 7 77 0
else else
# looking for a better solution... ¯\_(ツ)_/¯ # looking for a better solution... ¯\_(ツ)_/¯
@ -95,8 +98,8 @@ function getModules() {
# set local values # set local values
local modules_path="$1" local modules_path="$1"
# we first delete the old modules # we first delete the old modules
rm -fr $modules_path rm -fr "${modules_path}"
mkdir -p $modules_path mkdir -p "${modules_path}"
# then we get the current modules # then we get the current modules
{ {
sleep 1 sleep 1
@ -116,18 +119,18 @@ function prepScriptureMainGit() {
# set local values # set local values
local scripture_path="$1" local scripture_path="$1"
# if git folder does not exist clone it # if git folder does not exist clone it
if [ ! -d "$scripture_path" ]; then if [ ! -d "${scripture_path}" ]; then
# create the git folder (for scripture) # create the git folder (for scripture)
mkdir -p "$scripture_path" mkdir -p "${scripture_path}"
fi fi
# reset the git folder on each run # reset the git folder on each run
if [ -d "$scripture_path/.git" ]; then if [ -d "${scripture_path}/.git" ]; then
mkdir -p "${scripture_path}Tmp" mkdir -p "${scripture_path}Tmp"
mv -f "${scripture_path}/.git" "${scripture_path}Tmp" mv -f "${scripture_path}/.git" "${scripture_path}Tmp"
mv -f "${scripture_path}/.gitignore" "${scripture_path}Tmp" mv -f "${scripture_path}/.gitignore" "${scripture_path}Tmp"
# now we remove all the old git files (so we start clean each time in the build) # now we remove all the old git files (so we start clean each time in the build)
rm -fr $scripture_path rm -fr "${scripture_path}"
mv -f "${scripture_path}Tmp" "${scripture_path}" mv -f "${scripture_path}Tmp" "${scripture_path}"
fi fi
} }
@ -137,8 +140,8 @@ function setStaticJsonFiles() {
# set local values # set local values
local scripture_path="$1" local scripture_path="$1"
local modules_path="$2" local modules_path="$2"
local counter="$3" local each="$3"
local each_count="$4" local counter=0
# build the files # build the files
{ {
sleep 1 sleep 1
@ -148,16 +151,16 @@ function setStaticJsonFiles() {
# give notice # give notice
echo -e "XXX\n${counter}\nBuilding ${filename} static json files...\nXXX" echo -e "XXX\n${counter}\nBuilding ${filename} static json files...\nXXX"
# add more # add more
next=$(($each_count + $counter)) next=$((counter + each))
# run script # run script
python3 -u "${DIR_src}/sword_to_json.py" \ python3 -u "${DIR_src}/sword_to_json.py" \
--source_file "${filename}" \ --source_file "${filename}" \
--output_path "${scripture_path}" \ --output_path "${scripture_path}" \
--counter "${counter}" --next "${next}" \ --counter "$counter" --next "$next" \
--conf_dir "${DIR_conf}" \ --conf_dir "${DIR_conf}" \
--bible_conf "${DIR_bible}" --bible_conf "${DIR_bible}"
# add more # add more
counter=$(($each_count + $counter)) counter="$next"
# give notice # give notice
echo -e "XXX\n${counter}\nDone building ${filename} static json files...\nXXX" echo -e "XXX\n${counter}\nDone building ${filename} static json files...\nXXX"
sleep 1 sleep 1
@ -179,34 +182,36 @@ function cleanSystem() {
# the hashing of all files # the hashing of all files
function hashingAll() { function hashingAll() {
# set local values
local each="$1"
# start hashing Translations # start hashing Translations
hashingMethod "${DIR_api}_scripture" \ hashingMethod "${DIR_api}_scripture" \
"hash_versions" \ "hash_versions" \
"Hash Versions" \ "Hash Versions" \
"Start Versions Hashing" \ "Start Versions Hashing" \
"Done Hashing Versions" \ "Done Hashing Versions" \
"Please wait while we hash all versions" "Please wait while we hash all versions" "$each"
# start hashing Translations Books # start hashing Translations Books
hashingMethod "${DIR_api}_scripture" \ hashingMethod "${DIR_api}_scripture" \
"hash_books" \ "hash_books" \
"Hash Books" \ "Hash Books" \
"Start Versions Books Hashing" \ "Start Versions Books Hashing" \
"Done Hashing All Versions Books" \ "Done Hashing All Versions Books" \
"Please wait while we hash all versions books" "Please wait while we hash all versions books" "$each"
# start hashing Translations Books Chapters # start hashing Translations Books Chapters
hashingMethod "${DIR_api}_scripture" \ hashingMethod "${DIR_api}_scripture" \
"hash_chapters" \ "hash_chapters" \
"Hash Chapters" \ "Hash Chapters" \
"Start Versions Books Chapters Hashing" \ "Start Versions Books Chapters Hashing" \
"Done Hashing All Versions Books Chapters" \ "Done Hashing All Versions Books Chapters" \
"Please wait while we hash all versions books chapters" "Please wait while we hash all versions books chapters" "$each"
# moving all public hash files into place # moving all public hash files into place
hashingMethod "${DIR_api}" \ hashingMethod "${DIR_api}" \
"movePublicHashFiles" \ "movePublicHashFiles" \
"Moving Public Hash" \ "Moving Public Hash" \
"Start Moving Public Hashes" \ "Start Moving Public Hashes" \
"Done Moving All Public Hashes" \ "Done Moving All Public Hashes" \
"Please wait while we move all the public hashes into place" "Please wait while we move all the public hashes into place" "$each"
} }
# hashing all files in the project # hashing all files in the project
@ -218,12 +223,13 @@ function hashingMethod() {
local w_start_ms="$4" local w_start_ms="$4"
local w_end_ms="$5" local w_end_ms="$5"
local w_initial_ms="$6" local w_initial_ms="$6"
local each="$7"
# now run the hashing # now run the hashing
{ {
sleep 1 sleep 1
echo -e "XXX\n0\n${w_start_ms}... \nXXX" echo -e "XXX\n0\n${w_start_ms}... \nXXX"
sleep 1 sleep 1
. "${DIR_src}/${script_name}.sh" "${scripture_path}" . "${DIR_src}/${script_name}.sh" "${scripture_path}" "$each"
sleep 1 sleep 1
echo -e "XXX\n100\n${w_end_ms}... \nXXX" echo -e "XXX\n100\n${w_end_ms}... \nXXX"
sleep 1 sleep 1

View File

@ -20,6 +20,7 @@ fi
target_folder="$1" target_folder="$1"
# tracker counter # tracker counter
counter=0 counter=0
each="${2:-1}"
# check if the folder exist # check if the folder exist
if [ ! -d $target_folder ]; then if [ ! -d $target_folder ]; then
@ -120,8 +121,9 @@ for filename in $target_folder/*.json; do
counter=70 counter=70
fi fi
# add more # add more
counter=$((counter + 1)) counter=$((counter + each))
# give notice # give notice
echo -e "XXX\n${counter}\nDone Hashing $abbreviation books\nXXX" echo -e "XXX\n${counter}\nDone Hashing $abbreviation books\nXXX"
sleep 1
fi fi
done done

View File

@ -20,6 +20,7 @@ fi
target_folder="$1" target_folder="$1"
# tracker counter # tracker counter
counter=0 counter=0
each="${2:-1}"
# check if the folder exist # check if the folder exist
if [ ! -d $target_folder ]; then if [ ! -d $target_folder ]; then
@ -121,7 +122,7 @@ for filename in $target_folder/*.json; do
counter=70 counter=70
fi fi
# add more # add more
counter=$((counter + 1)) counter=$((counter + each))
# give notice # give notice
echo -e "XXX\n${counter}\nDone Hashing $abbreviation chapters\nXXX" echo -e "XXX\n${counter}\nDone Hashing $abbreviation chapters\nXXX"
fi fi

View File

@ -29,6 +29,7 @@ nr=1
target_folder="$1" target_folder="$1"
# tracker counter # tracker counter
counter=0 counter=0
each="${2:-1}"
# check if the folder exist # check if the folder exist
if [ ! -d $target_folder ]; then if [ ! -d $target_folder ]; then
@ -90,7 +91,7 @@ for filename in $target_folder/*.json; do
counter=70 counter=70
fi fi
# add more # add more
counter=$((counter + 1)) counter=$((counter + each))
# give notice # give notice
echo -e "XXX\n${counter}\nDone Hashing $abbreviation\nXXX" echo -e "XXX\n${counter}\nDone Hashing $abbreviation\nXXX"
done done

View File

@ -1,14 +1,14 @@
#! /bin/bash #! /bin/bash
# make sure we have at least one argument # make sure we have at least one argument
if [ $# -eq 0 ] if [ $# -eq 0 ]; then
then echo >&2 "Target folder must be supplied. Aborting."
echo >&2 "Target folder must be supplied. Aborting." exit 1
exit 1;
fi fi
# target folder # target folder
API_path="$1" API_path="$1"
each="${2:-1}"
scripture_path="${API_path}_scripture" scripture_path="${API_path}_scripture"
hash_path="${API_path}" hash_path="${API_path}"
@ -35,10 +35,9 @@ fi
declare -a arr=('*.sha' 'checksum' 'checksum.json' 'translations' 'translations.json' 'books' 'books.json' 'chapters' 'chapters.json') declare -a arr=('*.sha' 'checksum' 'checksum.json' 'translations' 'translations.json' 'books' 'books.json' 'chapters' 'chapters.json')
## now loop through the above array ## now loop through the above array
for key in "${arr[@]}" for key in "${arr[@]}"; do
do
# give notice # give notice
counter=0 counter="$each"
echo -e "XXX\n$counter\nMoving all these type ($key) of files\nXXX" echo -e "XXX\n$counter\nMoving all these type ($key) of files\nXXX"
sleep 1 sleep 1
find "$scripture_path" -type f -name "$key" -print0 | while IFS= read -r -d '' file; do find "$scripture_path" -type f -name "$key" -print0 | while IFS= read -r -d '' file; do
@ -50,14 +49,12 @@ do
# copy the files there # copy the files there
cp --remove-destination "$file" "$newFile" cp --remove-destination "$file" "$newFile"
# check if we have counter up-to total # check if we have counter up-to total
if (("$counter" >= 98)) if (("$counter" >= 98)); then
then counter="$each"
counter=3
fi fi
# increment the counter # increment the counter
counter=$((counter+1)) counter=$((counter + 1))
# give notice # give notice
echo -e "XXX\n${counter}\nMoving $file\nXXX" echo -e "XXX\n${counter}\nMoving $file\nXXX"
done done
done done