From f9a7a1031a8870445af850fb7446f48e3a6d813d Mon Sep 17 00:00:00 2001 From: William Floyd Date: Wed, 27 May 2020 19:37:18 -0400 Subject: [PATCH] rice: Move and adapt dot graph, make script run scripts. --- .../smart-rice-cooker/media/connections.svg | 353 ++++++++++++++++++ .../posts/smart-rice-cooker/media/src/.env | 0 .../smart-rice-cooker/media/src/rice_build.sh | 22 ++ .../media/src/rice_build.sh.hash | 1 + .../media/src}/rice_connections.dot | 1 - src/images_build.sh | 140 +++++-- src/rice_build.sh | 14 - 7 files changed, 494 insertions(+), 37 deletions(-) create mode 100644 content/posts/smart-rice-cooker/media/connections.svg create mode 100644 content/posts/smart-rice-cooker/media/src/.env create mode 100755 content/posts/smart-rice-cooker/media/src/rice_build.sh create mode 100644 content/posts/smart-rice-cooker/media/src/rice_build.sh.hash rename {src => content/posts/smart-rice-cooker/media/src}/rice_connections.dot (99%) delete mode 100755 src/rice_build.sh diff --git a/content/posts/smart-rice-cooker/media/connections.svg b/content/posts/smart-rice-cooker/media/connections.svg new file mode 100644 index 0000000..6a6ed6e --- /dev/null +++ b/content/posts/smart-rice-cooker/media/connections.svg @@ -0,0 +1,353 @@ + + + + + + + + +cluster_key + +Key + + +cluster_doc + + + +cluster_sub + + + +cluster_directives + +Directives + + +cluster_primary + +Primary + + +cluster_secondary + +Secondary + + +cluster_directives_lighting + +Lighting + + +cluster_directives_temperature + +Temperature + + +cluster_sensor + +Sensors + + +cluster_api + +api + + +cluster_api_sensor + +sensor + + +cluster_recipe + +recipe + + +cluster_schedule + +schedule + + +cluster_settings + +settings + + +cluster_time + +time + + +cluster_lighting + +lighting + + +cluster_settings_recipe + +recipe + + + +Done + +Done + + + +Documented + +Documented + + + +Undocumented + +Undocumented + + + +Depend on value + +Depend on value + + + +Node + +Node + + + +Depend on value->Node + + + + + +Proxy to value + +Proxy to value + + + +Proxy to value->Node + + + + + +Depend on function + +Depend on function + + + +Depend on function->Node + + + + + +Proxy to function + +Proxy to function + + + +Proxy to function->Node + + + + + +Sleep + +Sleep + + + +Heat + +Heat + + + +All Kill + +All Kill + + + +Lighting Kill + +Lighting Kill + + + +All Kill->Lighting Kill + + + + + +Temperature Kill + +Temperature Kill + + + +All Kill->Temperature Kill + + + + + +Lighting Change + +Lighting Change + + + +Temperature Change + +Temperature Change + + + +Temperature Change->Sleep + + + + + +Temperature Change->Heat + + + + + +Temperature + +Temperature + + + +Temperature Change->Temperature + + + + + +Temperature Hold + +Temperature Hold + + + +Temperature Hold->Sleep + + + + + +Temperature Hold->Heat + + + + + +Temperature Hold->Temperature + + + + + +Temperature Kill->Heat + + + + + +/api/sensor/temperature + +temperature + + + +/api/sensor/temperature->Temperature + + + + + +/api/recipe/list + +list + + + +/api/recipe/start + +start + + + +/api/recipe/kill + +kill + + + +/api/recipe/kill->All Kill + + + + + +/api/recipe/schedule/add + +add + + + +/api/recipe/schedule/delete + +delete + + + +/api/recipe/schedule/list + +list + + + +/api/settings/time/set + +set + + + +/api/settings/lighting/list + +list + + + +/api/settings/lighting/set + +set + + + +/api/settings/recipe/set + +set + + + diff --git a/content/posts/smart-rice-cooker/media/src/.env b/content/posts/smart-rice-cooker/media/src/.env new file mode 100644 index 0000000..e69de29 diff --git a/content/posts/smart-rice-cooker/media/src/rice_build.sh b/content/posts/smart-rice-cooker/media/src/rice_build.sh new file mode 100755 index 0000000..ea540d0 --- /dev/null +++ b/content/posts/smart-rice-cooker/media/src/rice_build.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [ "${1}" == '-d' ]; then + echo 'src/rice_connections.dot' + exit +fi + +__target='connections.svg' + +if [ "${1}" == '-t' ]; then + echo "${__target}" + exit +fi + +sed -e 's/\[depend_value\]/[color=blue]/' \ + -e 's/\[proxy_value\]/\[color=deepskyblue\]/' \ + -e 's/\[proxy_function\]/\[color=dodgerblue\]/' \ + -e 's/\[documented\]/\[fillcolor=darkolivegreen1\]/' \ + -e 's/\[done\]/\[fillcolor=chartreuse\]/' \ + -e 's/\[depend_function\]/\[color=cornflowerblue\]/' 'src/rice_connections.dot' | fdp -Ln5 -Tsvg >"${__target}" + +exit diff --git a/content/posts/smart-rice-cooker/media/src/rice_build.sh.hash b/content/posts/smart-rice-cooker/media/src/rice_build.sh.hash new file mode 100644 index 0000000..fa3428a --- /dev/null +++ b/content/posts/smart-rice-cooker/media/src/rice_build.sh.hash @@ -0,0 +1 @@ +8c980661e6c1b89a78f54e068a10dd93 diff --git a/src/rice_connections.dot b/content/posts/smart-rice-cooker/media/src/rice_connections.dot similarity index 99% rename from src/rice_connections.dot rename to content/posts/smart-rice-cooker/media/src/rice_connections.dot index a2743e7..d7846d6 100644 --- a/src/rice_connections.dot +++ b/content/posts/smart-rice-cooker/media/src/rice_connections.dot @@ -176,5 +176,4 @@ digraph { //////////////////////////////////////////////////////////////////////////////// - } diff --git a/src/images_build.sh b/src/images_build.sh index 377cf30..dcd1c9c 100755 --- a/src/images_build.sh +++ b/src/images_build.sh @@ -50,18 +50,22 @@ __PROCESS_PNG=true __depends__PROCESS_PNG=(PNG_OPTIMIZE PNG_RESCALE) __PNG_OPTIMIZE=false __depends__PNG_OPTIMIZE=(PNG_EFFORT) -__PNG_EFFORT=9 +# quick/default/more/placebo +__PNG_EFFORT='quick' __PNG_RESCALE=true -__depends__PNG_RESCALE=(PNG_SCALE) +__depends__PNG_RESCALE=(PNG_SCALE PNG_QUALITY) __PNG_SCALE="${__global_scale}" +__PNG_QUALITY=0 -__ENVIRONMENT_LIST='JPEG_QUALITY +__ENVIRONMENT_LIST='PROCESS_JPEG +PROCESS_PNG +PROCESS_SCRIPT +JPEG_QUALITY JPEG_RESCALE JPEG_SCALE JPEG_OPTIMIZE -PROCESS_JPEG -PROCESS_PNG PNG_OPTIMIZE +PNG_QUALITY PNG_EFFORT PNG_RESCALE PNG_SCALE' @@ -70,11 +74,11 @@ PNG_SCALE' # Functions ############################################################################### -__fatal_error_handler(){ -if [ "${__fatal_error}" == 'true' ]; then - echo 'Fatal Error: Exiting' - exit -fi +__fatal_error_handler() { + if [ "${__fatal_error}" == 'true' ]; then + echo 'Fatal Error: Exiting' + exit + fi } ######################################## @@ -212,6 +216,17 @@ __clear_env() { } +__unset_unused() { + while read -r __var; do + #local "${__var}" + if [ "${__var}" != "__PROCESS_${1^^}" ]; then + eval "${__var#__}"='false' + fi + done < <(set | grep -E '^__PROCESS_' | sed 's/^\([^=]*\)=.*/\1/') + + __resolve_env +} + ######################################## # __process <.env> ######################################## @@ -224,6 +239,8 @@ __clear_env() { __process() { + __process_scripts + if [ "${PROCESS_JPEG}" == 'true' ]; then __process_generic_image jpeg fi @@ -244,14 +261,7 @@ __find_png() { __process_generic_image() { - while read -r __var; do - #local "${__var}" - if [ "${__var}" != "__PROCESS_${1^^}" ]; then - eval "${__var#__}"='false' - fi - done < <(set | grep -E '^__PROCESS_' | sed 's/^\([^=]*\)=.*/\1/') - - __resolve_env + __unset_unused "${1}" "__find_${1}" | while read -r __source_file; do @@ -305,6 +315,69 @@ __optimize_jpeg() { jpegoptim -s "${1}" 1>/dev/null } +__rescale_png() { + convert "${1}" -quality "${PNG_QUALITY}" -auto-orient -resize "${PNG_SCALE}"% "${2}" +} + +__optimize_png() { + + local __options='' + + case $variable-name in + 'quick') + __options='-q' + ;; + 'default') + __options='' + ;; + 'more') + __options='-m' + ;; + 'placebo') + __options='--iterations=500 --filters=01234mepb --lossy_8bit --lossy_transparent' + ;; + *) + echo "Unknown PNG_EFFORT option '${PNG_EFFORT}', defaulting to 'quick'" + __options='-q' + ;; + esac + + zopflipng -y ${__options} "${1}" "${1}" +} + +__process_scripts() { + + __unset_unused SCRIPT + + find './src/' -type f \( -iname \*.sh \) | while read -r __source_file; do + + export FILE_HASH="$( + { + md5sum "${__source_file}" + "${__source_file}" -d | sort | while read -r __file; do + md5sum "${__file}" + done + } | sort | md5sum - + )" + + if ! __check_file "${__source_file}" "$("${__source_file}" -t)"; then + + echo "Running: ${__source_file}" + + echo "$(__hash_env)" >"$(__get_hash_file "${__source_file}")" + + "${__source_file}" + + fi + + unset FILE_HASH + + done + + __set_env './src/.env' + +} + ######################################## # __get_hash_file ######################################## @@ -319,7 +392,7 @@ __get_hash_file() { } ######################################## -# __check_file +# __check_file [ ...] ######################################## # # Check File @@ -331,12 +404,35 @@ __check_file() { __hash_file="$(__get_hash_file "${1}")" - __target="$(sed 's|^\./src/|./|' <<<"${1}")" + shift + + __targets='' + + if [ "${#}" == '0' ]; then + + __targets="$(sed 's|^\./src/|./|' <<<"${1}")" + + else + + until [ "${#}" == '0' ]; do + + __targets="${__target} +${1}" + + shift + + done - if ! [ -e "${__target}" ]; then - return 1 fi + while read -r __target; do + + if ! [ -e "${__target}" ]; then + return 1 + fi + + done + if [ -e "${__hash_file}" ]; then __file_hash="$(cat "${__hash_file}")" if [ "${__file_hash}" == "$(__hash_env)" ]; then diff --git a/src/rice_build.sh b/src/rice_build.sh deleted file mode 100755 index 240738e..0000000 --- a/src/rice_build.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -__target='./static/images/generated/rice/connections.svg' - -mkdir -p "$(dirname "${__target}")" - -sed -e 's/\[depend_value\]/[color=blue]/' \ --e 's/\[proxy_value\]/\[color=deepskyblue\]/' \ --e 's/\[proxy_function\]/\[color=dodgerblue\]/' \ --e 's/\[documented\]/\[fillcolor=darkolivegreen1\]/' \ --e 's/\[done\]/\[fillcolor=chartreuse\]/' \ --e 's/\[depend_function\]/\[color=cornflowerblue\]/' 'src/rice_connections.dot' | fdp -Ln5 -Tsvg > "${__target}" - -exit