@@ -5,55 +5,118 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
55
66FLUIDDOCDIR=${FLUIDDOCDIR:=/ FluidDoc}
77DOCROOT=${FLUIDDOCDIR} /docs
8-
9-
10- # # 1. 获取API映射文件
118APIMAPPING_ROOT=${DOCROOT} /guides/model_convert/convert_from_pytorch
129TOOLS_DIR=${APIMAPPING_ROOT} /tools
1310
14- # 确保tools目录存在
15- mkdir -p ${TOOLS_DIR}
11+ # Create tools directory if not exists
12+ if [ ! -d " ${TOOLS_DIR} " ]; then
13+ echo " INFO: Creating tools directory at ${TOOLS_DIR} "
14+ mkdir -p " ${TOOLS_DIR} "
15+ if [ $? -ne 0 ]; then
16+ echo " ERROR: Failed to create directory ${TOOLS_DIR} "
17+ exit 1
18+ fi
19+ else
20+ echo " INFO: Tools directory ${TOOLS_DIR} already exists"
21+ fi
1622
17- # 下载的文件URL
23+ # Define API mapping files URLs
1824API_ALIAS_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_alias_mapping.json"
1925API_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_mapping.json"
2026GLOBAL_VAR_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/global_var.py"
2127ATTRIBUTE_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/attribute_mapping.json"
2228
23- # 下载文件
29+ # Check for proxy settings
2430PROXY=" "
2531if [ -n " $https_proxy " ]; then
2632 PROXY=" $https_proxy "
33+ echo " INFO: Using proxy"
2734elif [ -n " $http_proxy " ]; then
2835 PROXY=" $http_proxy "
36+ echo " INFO: Using proxy"
37+ else
38+ echo " INFO: No proxy detected, downloading directly."
2939fi
3040
31- # 构建 curl 代理参数
32- CURL_PROXY_ARGS=" "
41+ # Build curl proxy arguments
3342if [ -n " $PROXY " ]; then
34- CURL_PROXY_ARGS=" --proxy $PROXY "
43+ CURL_PROXY_ARGS=" --proxy ${ PROXY} "
3544else
36- echo " No proxy detected, downloading directly. "
45+ CURL_PROXY_ARGS= " "
3746fi
3847
39- # 执行下载
40- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /api_alias_mapping.json" -s " ${API_ALIAS_MAPPING_URL} "
41- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /api_mapping.json" -s " ${API_MAPPING_URL} "
42- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /global_var.py" -s " ${GLOBAL_VAR_URL} "
43- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /attribute_mapping.json" -s " ${ATTRIBUTE_MAPPING_URL} "
48+ # Handle failure: copy cached file and exit
49+ handle_failure () {
50+ local cached_file=" ${APIMAPPING_ROOT} /cached_pytorch_api_mapping_cn.md"
51+ local target_file=" ${APIMAPPING_ROOT} /pytorch_api_mapping_cn.md"
52+
53+ if [ -f " $cached_file " ]; then
54+ echo " INFO: Copying cached file to target: $cached_file -> $target_file "
55+ cp " $cached_file " " $target_file "
56+ echo " INFO: Successfully copied cached file to $target_file "
57+ exit 0
58+ else
59+ echo " ERROR: Cached file not found at $cached_file "
60+ exit 1
61+ fi
62+ }
63+
64+ # Download file with retry and failure handling
65+ download_file () {
66+ local url=$1
67+ local dest=$2
68+ local filename=$( basename " $dest " )
69+ local max_retries=3
70+ local retry_count=0
71+
72+ echo " INFO: Starting download of ${filename} from ${url} "
4473
45- # 检查下载是否成功
46- if [ $? -ne 0 ]; then
47- echo " Error: Failed to download API mapping files"
48- exit 1
74+ while [ $retry_count -lt $max_retries ]; do
75+ retry_count=$(( retry_count + 1 ))
76+ echo " INFO: Attempt $retry_count of $max_retries to download ${filename} "
77+
78+ if curl $CURL_PROXY_ARGS -o " ${dest} " -s " ${url} " > /dev/null 2>&1 ; then
79+ echo " SUCCESS: Successfully downloaded ${filename} to ${dest} "
80+ return 0
81+ else
82+ echo " WARNING: Failed to download ${filename} from ${url} (attempt $retry_count )"
83+ sleep 2 # Wait for 2 seconds before next retry
84+ fi
85+ done
86+
87+ echo " ERROR: Failed to download ${filename} after $max_retries attempts"
88+ handle_failure
89+ }
90+
91+ # Download all API mapping files
92+ download_file " ${API_ALIAS_MAPPING_URL} " " ${TOOLS_DIR} /api_alias_mapping.json"
93+ download_file " ${API_MAPPING_URL} " " ${TOOLS_DIR} /api_mapping.json"
94+ download_file " ${GLOBAL_VAR_URL} " " ${TOOLS_DIR} /global_var.py"
95+ download_file " ${ATTRIBUTE_MAPPING_URL} " " ${TOOLS_DIR} /attribute_mapping.json"
96+
97+ echo " INFO: All API mapping files successfully downloaded"
98+
99+ # Run the remaining scripts with failure handling
100+ echo " INFO: Running get_api_difference_info.py"
101+ if ! python " ${APIMAPPING_ROOT} /tools/get_api_difference_info.py" ; then
102+ handle_failure
49103fi
50104
51- # # 3. Apply PyTorch-PaddlePaddle mapping using the new API mapping files
52- python ${APIMAPPING_ROOT} /tools/get_api_difference_info.py
53- python ${APIMAPPING_ROOT} /tools/generate_pytorch_api_mapping.py
105+ echo " INFO: Running generate_pytorch_api_mapping.py"
106+ if ! python " ${APIMAPPING_ROOT} /tools/generate_pytorch_api_mapping.py" ; then
107+ handle_failure
108+ fi
54109
110+ # Create backup of generated file
111+ BACKUP_FILE=" ${APIMAPPING_ROOT} /cached_pytorch_api_mapping_cn.md"
112+ GENERATED_FILE=" ${APIMAPPING_ROOT} /pytorch_api_mapping_cn.md"
55113
56- if [ $? -ne 0 ]; then
57- echo " Error: API mapping generate script failed, please check changes in ${APIMAPPING_ROOT} "
58- exit 1
114+ if [ -f " $GENERATED_FILE " ]; then
115+ echo " INFO: Generated API mapping file successfully created at $GENERATED_FILE "
116+ echo " INFO: Creating backup file: $BACKUP_FILE "
117+ cp " $GENERATED_FILE " " $BACKUP_FILE "
118+ echo " INFO: Successfully created backup file at $BACKUP_FILE "
119+ else
120+ echo " ERROR: Generated API mapping file not found at $GENERATED_FILE "
121+ handle_failure
59122fi
0 commit comments