2020 echo " INFO: Tools directory ${TOOLS_DIR} already exists"
2121fi
2222
23- # Define API mapping files URLs
23+ # Define API mapping files URLs (only main URLs, no backups)
2424API_ALIAS_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_alias_mapping.json"
2525API_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_mapping.json"
2626GLOBAL_VAR_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/global_var.py"
2727ATTRIBUTE_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/attribute_mapping.json"
2828
29- # Define backup URLs
30- BACKUP_API_ALIAS_MAPPING_URL=" https://paddle-paconvert.bj.bcebos.com/api_alias_mapping.json"
31- BACKUP_API_MAPPING_URL=" https://paddle-paconvert.bj.bcebos.com/api_mapping.json"
32- BACKUP_GLOBAL_VAR_URL=" https://paddle-paconvert.bj.bcebos.com/global_var.py"
33- BACKUP_ATTRIBUTE_MAPPING_URL=" https://paddle-paconvert.bj.bcebos.com/attribute_mapping.json"
34-
3529# Check for proxy settings
3630PROXY=" "
3731if [ -n " $https_proxy " ]; then
3832 PROXY=" $https_proxy "
39- echo " INFO: find proxy"
33+ echo " INFO: Using proxy"
4034elif [ -n " $http_proxy " ]; then
4135 PROXY=" $http_proxy "
42- echo " INFO: find proxy"
36+ echo " INFO: Using proxy"
4337else
4438 echo " INFO: No proxy detected, downloading directly."
4539fi
@@ -56,7 +50,7 @@ download_file() {
5650 local url=$1
5751 local dest=$2
5852 local filename=$( basename " $dest " )
59- local max_retries=5
53+ local max_retries=3
6054 local retry_count=0
6155
6256 echo " INFO: Starting download of ${filename} from ${url} "
@@ -78,39 +72,87 @@ download_file() {
7872 return 1
7973}
8074
81- # Download each file with detailed logging
75+ # Check if cached file exists
76+ check_cached_file () {
77+ local cached_file=" ${APIMAPPING_ROOT} /cached_pytorch_api_mapping_cn.md"
78+ if [ -f " $cached_file " ]; then
79+ echo " INFO: Cached file found at $cached_file "
80+ return 0
81+ else
82+ echo " INFO: No cached file found at $cached_file "
83+ return 1
84+ fi
85+ }
86+
87+ # Copy cached file to target if download fails
88+ copy_cached_file () {
89+ local cached_file=" ${APIMAPPING_ROOT} /cached_pytorch_api_mapping_cn.md"
90+ local target_file=" ${APIMAPPING_ROOT} /pytorch_api_mapping_cn.md"
91+
92+ if [ -f " $cached_file " ]; then
93+ echo " INFO: Copying cached file to target: $cached_file -> $target_file "
94+ cp " $cached_file " " $target_file "
95+ echo " INFO: Successfully copied cached file to $target_file "
96+ return 0
97+ else
98+ echo " ERROR: Cached file not found at $cached_file "
99+ return 1
100+ fi
101+ }
102+
103+ # Download API mapping files
82104echo " INFO: Downloading API alias mapping file"
83105if ! download_file " ${API_ALIAS_MAPPING_URL} " " ${TOOLS_DIR} /api_alias_mapping.json" ; then
84- echo " INFO: Trying backup URL for API alias mapping file"
85- if ! download_file " ${BACKUP_API_ALIAS_MAPPING_URL} " " ${TOOLS_DIR} /api_alias_mapping.json" ; then
86- echo " ERROR: API alias mapping download failed (both main and backup URLs). Exiting."
106+ echo " INFO: API alias mapping download failed. Checking for cached file..."
107+ if check_cached_file; then
108+ if ! copy_cached_file; then
109+ echo " ERROR: Failed to copy cached file to target"
110+ exit 1
111+ fi
112+ else
113+ echo " ERROR: API alias mapping download failed and no cached file available"
87114 exit 1
88115 fi
89116fi
90117
91118echo " INFO: Downloading API mapping file"
92119if ! download_file " ${API_MAPPING_URL} " " ${TOOLS_DIR} /api_mapping.json" ; then
93- echo " INFO: Trying backup URL for API mapping file"
94- if ! download_file " ${BACKUP_API_MAPPING_URL} " " ${TOOLS_DIR} /api_mapping.json" ; then
95- echo " ERROR: API mapping download failed (both main and backup URLs). Exiting."
120+ echo " INFO: API mapping download failed. Checking for cached file..."
121+ if check_cached_file; then
122+ if ! copy_cached_file; then
123+ echo " ERROR: Failed to copy cached file to target"
124+ exit 1
125+ fi
126+ else
127+ echo " ERROR: API mapping download failed and no cached file available"
96128 exit 1
97129 fi
98130fi
99131
100132echo " INFO: Downloading global variable file"
101133if ! download_file " ${GLOBAL_VAR_URL} " " ${TOOLS_DIR} /global_var.py" ; then
102- echo " INFO: Trying backup URL for global variable file"
103- if ! download_file " ${BACKUP_GLOBAL_VAR_URL} " " ${TOOLS_DIR} /global_var.py" ; then
104- echo " ERROR: Global variable download failed (both main and backup URLs). Exiting."
134+ echo " INFO: Global variable download failed. Checking for cached file..."
135+ if check_cached_file; then
136+ if ! copy_cached_file; then
137+ echo " ERROR: Failed to copy cached file to target"
138+ exit 1
139+ fi
140+ else
141+ echo " ERROR: Global variable download failed and no cached file available"
105142 exit 1
106143 fi
107144fi
108145
109146echo " INFO: Downloading attribute mapping file"
110147if ! download_file " ${ATTRIBUTE_MAPPING_URL} " " ${TOOLS_DIR} /attribute_mapping.json" ; then
111- echo " INFO: Trying backup URL for attribute mapping file"
112- if ! download_file " ${BACKUP_ATTRIBUTE_MAPPING_URL} " " ${TOOLS_DIR} /attribute_mapping.json" ; then
113- echo " ERROR: Attribute mapping download failed (both main and backup URLs). Exiting."
148+ echo " INFO: Attribute mapping download failed. Checking for cached file..."
149+ if check_cached_file; then
150+ if ! copy_cached_file; then
151+ echo " ERROR: Failed to copy cached file to target"
152+ exit 1
153+ fi
154+ else
155+ echo " ERROR: Attribute mapping download failed and no cached file available"
114156 exit 1
115157 fi
116158fi
@@ -142,3 +184,17 @@ if ! python "${APIMAPPING_ROOT}/tools/generate_pytorch_api_mapping.py"; then
142184 echo " ERROR: generate_pytorch_api_mapping.py failed. Please check the script."
143185 exit 1
144186fi
187+
188+ # Create backup of generated file
189+ BACKUP_FILE=" ${APIMAPPING_ROOT} /cached_pytorch_api_mapping_cn.md"
190+ GENERATED_FILE=" ${APIMAPPING_ROOT} /pytorch_api_mapping_cn.md"
191+
192+ if [ -f " $GENERATED_FILE " ]; then
193+ echo " INFO: Generated API mapping file successfully created at $GENERATED_FILE "
194+ echo " INFO: Creating backup file: $BACKUP_FILE "
195+ cp " $GENERATED_FILE " " $BACKUP_FILE "
196+ echo " INFO: Successfully created backup file at $BACKUP_FILE "
197+ else
198+ echo " ERROR: Generated API mapping file not found at $GENERATED_FILE "
199+ exit 1
200+ fi
0 commit comments