From fc2708d8e2365d40d006e22de5721309e4a37c0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=EC=83=81=EA=B7=9C/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 28 Oct 2019 15:23:18 +0900 Subject: [PATCH] [tf2nnpk] check existence and provide help (#8499) It will show help with `--help`. It will check existence of flatc, graphdef and info file. Signed-off-by: Sanggyu Lee --- infra/packaging/res/tf2nnpkg | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/infra/packaging/res/tf2nnpkg b/infra/packaging/res/tf2nnpkg index e502dda..cbb0181 100644 --- a/infra/packaging/res/tf2nnpkg +++ b/infra/packaging/res/tf2nnpkg @@ -1,14 +1,28 @@ #!/bin/bash +set -e + ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +command_exists() { + command -v "$@" > /dev/null 2>&1 +} + +usage() +{ + echo "Usage: tf2nnpkg --info --graphdef -o " + exit 0 +} + # Parse command-line arguments # -# --info --graphdef -o while [ "$#" -ne 0 ]; do CUR="$1" case $CUR in + '--help') + usage + ;; '--info') export INFO_FILE="$2" shift 2 @@ -28,12 +42,15 @@ while [ "$#" -ne 0 ]; do esac done -set -e - -# TODO CHECK ARGUMENTS -# TODO CHECK "flatc" +if [ -z ${GRAPHDEF_FILE} ] || [ ! -e ${GRAPHDEF_FILE} ]; then + echo "pb is not found. Please check --graphdef is correct." + exit 2 +fi -echo "ROOT is '${ROOT}'" +if [ -z ${INFO_FILE} ] || [ ! -e ${INFO_FILE} ]; then + echo "info is not found. Please check --info is correct." + exit 2 +fi FILE_BASE=$(basename ${GRAPHDEF_FILE}) MODEL_NAME="${FILE_BASE%.*}" @@ -42,6 +59,11 @@ export flatc=$(which flatc) export tflite_schema="${ROOT}/res/tflite_schema.fbs" export circle_schema="${ROOT}/res/circle_schema.fbs" +if ! command_exists $flatc; then + echo "Please make sure flatc is in path" + exit 2 +fi + TMPDIR=$(mktemp -d) trap "{ rm -rf $TMPDIR; }" EXIT -- 2.7.4