From d65b85be8f2fa88d975e8817f3d177704b015f37 Mon Sep 17 00:00:00 2001 From: ayakael Date: Sat, 7 Apr 2018 17:09:22 -0400 Subject: [PATCH] [chk_metadata] [cmd_deploy] [deploy_meta] Added prettier CLI logging --- src/chk_metadata | 7 ++++--- src/cmd_deploy | 22 +++++++++++++++++----- src/deploy_meta | 7 ++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/chk_metadata b/src/chk_metadata index 3b57709..1c60b6e 100644 --- a/src/chk_metadata +++ b/src/chk_metadata @@ -18,10 +18,11 @@ chk_metadata() { [[ -z "${imageidList[@]}" ]] && local imageidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4!="null"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++')) + local COUNT=1 for imageid in ${imageidList[@]}; do - _msg EXEC "Checking ${imageid}" + echo "[ ${COUNT} / ${#imageidList[@]} ] Checking ${imageid} in ${TARGET}" deploy_meta "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageid} >${STDERR} 2>&1 - [[ $? -eq 0 ]] && _msg OK || _msg WARN - + [[ $? -eq 0 ]] && { _ansi up 2; echo -en '\033[K'; } || { echo "[>>>>>>] Error reported"; cat ${STDERR}; local ERR=true; } + local COUNT=$(( ${COUNT} + 1 )) done } diff --git a/src/cmd_deploy b/src/cmd_deploy index e4929ec..1365c07 100644 --- a/src/cmd_deploy +++ b/src/cmd_deploy @@ -13,6 +13,7 @@ cmd_deploy() { local GIT_DIR="${1}" local TARGET="${2}"; shift 2 + local ERR=false local DB_FILE="${TARGET}/${_OPT_DB_FILE}" [[ ! -f "${DB_FILE}" ]] && return 1 @@ -35,19 +36,30 @@ cmd_deploy() { [[ ${DU} -ge ${DF} ]] && { _msg ECHO "Target does not have enough space for deployable IMAGEID. Need ${DU}, has ${DF}."; return 2; } # Cleans target of removable TRACKID + local COUNT=1 for removableid in ${removableidList[@]}; do - deploy_rm "${TARGET}" "${DB_FILE}" ${removableid} + echo "[ ${COUNT} / ${#removableidList[@]} ] Removing ${removableid} from ${TARGET}" + deploy_rm "${TARGET}" "${DB_FILE}" ${removableid} >${STDERR} 2>&1 + [[ $? -eq 0 ]] && { _ansi up 2; echo -en '\033[K'; } || { echo "[>>>>>>] Error reported"; cat ${STDERR}; local ERR=true; } + local COUNT=$(( ${COUNT} + 1 )) done + local COUNT=0 for imageid in ${updateableidList[@]}; do + local COUNT=$(( ${COUNT} + 1 )) + echo "[ ${COUNT} / ${#updateableidList[@]} ] Deploying ${imageid} to ${TARGET}" # Processes deployableids (IMAGEIDs that have TRACKIDs that are not present in target, but are selected) if _if_array_contains ${imageid} ${deployableidList[@]}; then - deploy_cp "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageid} + deploy_cp "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageid} > ${STDERR} 2>&1 + [[ $? -eq 0 ]] || { echo "[>>>>>>] Error reported"; cat ${STDERR}; local ERR=true; continue; } fi + - # Processed metadata changes - deploy_meta "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageid} + # Processes metadata changes + deploy_meta "${GIT_DIR}" "${TARGET}" "${DB_FILE}" ${imageid} >${STDERR} 2>&1 + [[ $? -eq 0 ]] && { _ansi up 2; echo -en '\033[K'; } || { echo "[>>>>>>] Error reported"; cat ${STDERR}; local ERR=true; } done - [[ ${ERR} ]] && return 1 || { gawk -i inplace -v newcommit=${NEW_COMMIT} 'BEGIN{FS="\t";OFS="\t"}{if($1=="LAST_DEPLOY"){$2=newcommit}{print $0}}' ${DB_FILE}; return 0; } + [[ "${ERR}" == "true" ]] && return 1 || { gawk -i inplace -v newcommit=${NEW_COMMIT} 'BEGIN{FS="\t";OFS="\t"}{if($1=="LAST_DEPLOY"){$2=newcommit}{print $0}}' ${DB_FILE}; return 0; } + } diff --git a/src/deploy_meta b/src/deploy_meta index 4390564..9182bd1 100644 --- a/src/deploy_meta +++ b/src/deploy_meta @@ -30,19 +30,20 @@ deploy_meta() { # If the PRESENT_META and FUTURE_META diverge, wipe the old metadata, and reapply if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then - local ERR=true _msg ECHO "${trackid} has differing metadata. Updating" [[ "${PRESENT_PATH}" == "null" ]] || metaflac --remove-all "${TARGET}/${PRESENT_PATH}" awk 'BEGIN {RS=";"}{print $0}' <<< ${FUTURE_META} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${TARGET}/${PRESENT_PATH}" + [[ $? -eq 0 ]] || local ERR=true fi # If the PRESENT_PATH and FUTURE_PATH diverge, move to new location if [[ "${PRESENT_PATH}" != "${FUTURE_PATH}" ]]; then - local ERR=true _msg ECHO "${trackid} has differing paths. Moving" mkdir -p "$(dirname "${TARGET}/${FUTURE_PATH}")" + [[ $? -eq 0 ]] || local ERR=true mv "${TARGET}/${PRESENT_PATH}" "${TARGET}/${FUTURE_PATH}" - rmdir -p --ignore-fail-on-non-empty "$(dirname "${TARGET}/${PRESENT_PATH}")" >${STDERR} 2>&1 + [[ $? -eq 0 ]] || local ERR=true + rmdir -p --ignore-fail-on-non-empty "$(dirname "${TARGET}/${PRESENT_PATH}")" >/dev/null 2>&1 gawk -i inplace -v trackid=${trackid} -v value="${FUTURE_PATH}" 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE} fi done