Skip to content

Commit d4fb61a

Browse files
committed
【完善】:链接有效性检查函数
1 parent 007980f commit d4fb61a

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

cmds/cmd_package.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ def get_url_from_mirror_server(pkgs_name_in_json, pkgs_ver):
202202

203203
except Exception, e:
204204
print('e.message:%s\t' % e.message)
205-
print(
206-
"The server could not be contacted. Please check your network connection.")
205+
print("The server could not be contacted. Please check your network connection.")
207206

208207

209208
def determine_url_valid(url_from_srv):
@@ -214,22 +213,21 @@ def determine_url_valid(url_from_srv):
214213
'User-Agent': 'curl/7.54.0'}
215214

216215
try:
217-
r = requests.get(url_from_srv, stream=True, headers=headers)
218-
if r.status_code == requests.codes.not_found:
219-
time.sleep(1)
216+
for i in range(0, 3):
220217
r = requests.get(url_from_srv, stream=True, headers=headers)
221218
if r.status_code == requests.codes.not_found:
222-
time.sleep(1)
223-
r = requests.get(url_from_srv, stream=True, headers=headers)
224-
if r.status_code == requests.codes.not_found:
225-
print("Warning : %s is invalid."%package_url)
219+
if i == 2:
220+
print("Warning : %s is invalid." % package_url)
226221
return False
222+
time.sleep(1)
223+
else:
224+
break
227225

228226
return True
229227

230228
except Exception, e:
231-
# print('e.message:%s\t' % e.message)
232-
print('Network connection error or the url : %s is invalid.\n'%url_from_srv)
229+
# print('e.message:%s\t' % e.message)
230+
print('Network connection error or the url : %s is invalid.\n' % url_from_srv)
233231

234232

235233
def install_pkg(env_root, bsp_root, pkg):
@@ -255,11 +253,7 @@ def install_pkg(env_root, bsp_root, pkg):
255253
package_url = package.get_url(pkg['ver'])
256254
#package_name = pkg['name']
257255
pkgs_name_in_json = package.get_name()
258-
259-
# if not determine_url_valid(package_url):
260-
# print("Please check the json file.")
261-
# return False
262-
256+
263257
if package_url[-4:] == '.git':
264258
ver_sha = package.get_versha(pkg['ver'])
265259

@@ -276,31 +270,31 @@ def install_pkg(env_root, bsp_root, pkg):
276270

277271
if os.path.isfile(env_config_file) and find_macro_in_config(env_config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE'):
278272
get_package_url, get_ver_sha = get_url_from_mirror_server(pkgs_name_in_json, pkg['ver'])
279-
273+
280274
# determine whether the package package url is valid
281275
if get_package_url != None and determine_url_valid(get_package_url):
282276
package_url = get_package_url
283-
277+
284278
if get_ver_sha != None:
285279
ver_sha = get_ver_sha
286-
280+
287281
upstream_change_flag = True
288-
282+
289283
if package_url[-4:] == '.git':
290-
284+
291285
repo_path = os.path.join(bsp_pkgs_path, pkgs_name_in_json)
292286
repo_path = repo_path + '-' + pkg['ver']
293-
287+
294288
cmd = 'git clone ' + package_url + ' ' + repo_path
295289
execute_command(cmd, cwd=bsp_pkgs_path)
296-
290+
297291
cmd = 'git checkout -q ' + ver_sha
298292
execute_command(cmd, cwd=repo_path)
299-
293+
300294
if upstream_change_flag:
301295
cmd = 'git remote set-url origin ' + url_from_json
302296
execute_command(cmd, cwd=repo_path)
303-
297+
304298
# If there is a .gitmodules file in the package, prepare to update the
305299
# submodule.
306300
submod_path = os.path.join(repo_path, '.gitmodules')

0 commit comments

Comments
 (0)