run_google_api_bindings_gen.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env bash
  2. # ** NOTICE **
  3. # If they exist, this script deletes the "./_google_api_bindings_tmp"
  4. # and "./_google_api_icons_tmp" directories before attempting
  5. # to convert new files. It does not download any JSON, but works on
  6. # files which must already be present in "./_google_api_json_tmp"
  7. # (use "./fetch_google_json.sh" to download the JSON files)
  8. shopt -s nocaseglob #ignore case for filename matches
  9. shopt -s nullglob #if no matches return a null string
  10. SCRIPT_DIR="$(dirname "$0")"
  11. JSON_DIR="$SCRIPT_DIR/_google_api_json_tmp"
  12. ICONS_DIR="$SCRIPT_DIR/_google_api_icons_tmp"
  13. BINDINGS_DIR="$SCRIPT_DIR/_google_api_bindings_tmp"
  14. TIMESTAMP=$(date +%F@%H%M) #Example format: 2006-09-15@1228
  15. LOG_FILE="$BINDINGS_DIR/${TIMESTAMP}-$(basename "$0").txt" #log file with same name as script
  16. if [ ! -d "$JSON_DIR" ]; then
  17. echo "** Nothing to do: $JSON_DIR directory does not exist **"
  18. echo ' 1) First run "fetch_google_json.sh" to download JSON files'
  19. echo ' 2) Then it is recommended to run "nomalize_json_files.sh"'
  20. echo ' (if you have "jq" installed on your system)'
  21. exit 1
  22. fi
  23. rm -r "$BINDINGS_DIR" &> /dev/null
  24. mkdir "$BINDINGS_DIR" &> /dev/null
  25. rm -r "$ICONS_DIR" &> /dev/null
  26. mkdir "$ICONS_DIR" &> /dev/null
  27. {
  28. echo "Run Timestamp: $TIMESTAMP"
  29. echo "Using Google API Converter: " $("$SCRIPT_DIR/googleapiconv" --version)
  30. echo
  31. # Test convert a single JSON file
  32. # echo "googleapiconv --verbose --input=$JSON_DIR/googlegmail.json --output=$BINDINGS_DIR/googlegmail.pp"
  33. # "$SCRIPT_DIR/googleapiconv" --verbose --input="$JSON_DIR/googlegmail.json" --output="$BINDINGS_DIR/googlegmail.pp"
  34. for FILE in "$JSON_DIR/"*.json; do
  35. OUT_NAME="${FILE##*/}"; OUT_NAME="${OUT_NAME%.*}.pp"
  36. #--verbose
  37. echo "googleapiconv --icon --timestamp --input=$FILE --output=$BINDINGS_DIR/$OUT_NAME"
  38. "$SCRIPT_DIR/googleapiconv" --icon --input="$FILE" --output="$BINDINGS_DIR/$OUT_NAME"
  39. done
  40. mv "$BINDINGS_DIR/"*.png "$ICONS_DIR" &> /dev/null
  41. mv "$BINDINGS_DIR/"*.gif "$ICONS_DIR" &> /dev/null
  42. # Check to see if we have any missing generated .pp files
  43. echo ""
  44. ((COUNT=0))
  45. for FILE in "$JSON_DIR/"*.json; do
  46. JSON_NAME="${FILE##*/}"
  47. PASCAL_NAME="${JSON_NAME%.*}.pp"
  48. if [ ! -s "$BINDINGS_DIR/$PASCAL_NAME" ]; then
  49. echo "** Missing or empty file: JSON file $JSON_NAME did not generate $PASCAL_NAME"
  50. ((COUNT++))
  51. fi
  52. done
  53. echo "Missing File Count = $COUNT"
  54. } |& tee "$LOG_FILE" #output both stdout and stderr to logfile and terminal