From 11a0e0fe1df6775dadc1a97092ecadd3bb56bdb9 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 3 Feb 2021 14:10:07 +0800 Subject: [PATCH 1/2] exception handle and encode problem --- scripts/automation_generate.sh | 19 +++++++++++++------ .../packaging_tools/auto_package.py | 2 -- .../swaggertosdk/autorest_tools.py | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/automation_generate.sh b/scripts/automation_generate.sh index f2c291651fdb..5d7575870488 100644 --- a/scripts/automation_generate.sh +++ b/scripts/automation_generate.sh @@ -10,12 +10,19 @@ sudo npm install -g n sudo n 10.15.0 export PATH=/usr/local/n/versions/node/10.15.0/bin:$PATH -# generate code and package -python -m packaging_tools.auto_codegen "$1" "$TMPDIR/venv-sdk/auto_temp.json" 2>&1 +TEMP_FILE="$TMPDIR/venv-sdk/auto_temp.json" +# generate code +python -m packaging_tools.auto_codegen "$1" "$TEMP_FILE" 2>&1 echo "[Generate] codegen done!!!" -python -m packaging_tools.auto_package "$TMPDIR/venv-sdk/auto_temp.json" "$2" 2>&1 -echo "[Generate] generate done!!!" +if [ ! -f "$TEMP_FILE" ]; then + echo "[Autorest]$TEMP_FILE does not exist!!!Error happened during codegen" + exit 1 +fi +# package +python -m packaging_tools.auto_package "$TEMP_FILE" "$2" 2>&1 +echo "[Generate] generate done!!!" if [ ! -f "$2" ]; then - echo "[Autorest]$2 does not exist!!!" -fi + echo "[Autorest]$2 does not exist!!!Error happened during package" + exit 1 +fi \ No newline at end of file diff --git a/tools/azure-sdk-tools/packaging_tools/auto_package.py b/tools/azure-sdk-tools/packaging_tools/auto_package.py index 323fc2d305f2..52f633ff105b 100644 --- a/tools/azure-sdk-tools/packaging_tools/auto_package.py +++ b/tools/azure-sdk-tools/packaging_tools/auto_package.py @@ -47,8 +47,6 @@ def change_log_generate(package_name): def main(generate_input, generate_output): with open(generate_input, "r") as reader: data = json.load(reader) - if not data: - return sdk_folder = '.' result = { diff --git a/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py b/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py index d9347b9132ec..b13bc99078b0 100644 --- a/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py +++ b/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py @@ -4,7 +4,7 @@ from pathlib import Path import shutil import subprocess - +import io _LOGGER = logging.getLogger(__name__) @@ -131,7 +131,7 @@ def execute_simple_command(cmd_line, cwd=None, shell=False, env=None): shell=shell, env=env) output_buffer = [] - for line in process.stdout: + for line in io.TextIOWrapper(process.stdout, encoding='utf-8'): output_buffer.append(line.rstrip()) _LOGGER.info(f"==[autorest]"+output_buffer[-1]) process.wait() From b22e1cb97c3eda94fae123c252d7f2176246f31c Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 3 Feb 2021 18:33:47 +0800 Subject: [PATCH 2/2] Update autorest_tools.py --- .../packaging_tools/swaggertosdk/autorest_tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py b/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py index b13bc99078b0..20e59f16ca0c 100644 --- a/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py +++ b/tools/azure-sdk-tools/packaging_tools/swaggertosdk/autorest_tools.py @@ -4,7 +4,6 @@ from pathlib import Path import shutil import subprocess -import io _LOGGER = logging.getLogger(__name__) @@ -129,9 +128,10 @@ def execute_simple_command(cmd_line, cwd=None, shell=False, env=None): universal_newlines=True, cwd=cwd, shell=shell, - env=env) + env=env, + encoding='utf-8') output_buffer = [] - for line in io.TextIOWrapper(process.stdout, encoding='utf-8'): + for line in process.stdout: output_buffer.append(line.rstrip()) _LOGGER.info(f"==[autorest]"+output_buffer[-1]) process.wait()