@@ -370,7 +370,7 @@ def git_cmd_exec(cmd, cwd):
370370 print ('error message:%s%s. %s \n You can solve this problem by manually removing old packages and re-downloading them using env.\t ' %
371371 (cwd , " path doesn't exist" , e .message ))
372372
373-
373+
374374def update_latest_packages (read_back_pkgs_json , bsp_packages_path ):
375375 """ update the packages that are latest version.
376376
@@ -383,15 +383,6 @@ def update_latest_packages(read_back_pkgs_json, bsp_packages_path):
383383
384384 env_root = Import ('env_root' )
385385
386- payload = {
387- "userName" : "RT-Thread" ,
388- "packages" : [
389- {
390- "name" : "NULL" ,
391- }
392- ]
393- }
394-
395386 env_kconfig_path = os .path .join (env_root , 'tools\scripts\cmds' )
396387 env_config_file = os .path .join (env_kconfig_path , '.config' )
397388
@@ -400,54 +391,43 @@ def update_latest_packages(read_back_pkgs_json, bsp_packages_path):
400391 pkg_path = pkg ['path' ]
401392 if pkg_path [0 ] == '/' or pkg_path [0 ] == '\\ ' :
402393 pkg_path = pkg_path [1 :]
394+
403395 pkg_path = os .path .join (env_root , 'packages' , pkg_path , 'package.json' )
404396 package .parse (pkg_path )
405397 pkgs_name_in_json = package .get_name ()
398+
399+ # Find out the packages which version is 'latest'
406400 if pkg ['ver' ] == "latest_version" or pkg ['ver' ] == "latest" :
407401 repo_path = os .path .join (bsp_packages_path , pkgs_name_in_json )
408402 repo_path = get_pkg_folder_by_orign_path (repo_path , pkg ['ver' ])
409403
404+ # If mirror acceleration is enabled, get the update address from the mirror server.
410405 if os .path .isfile (env_config_file ) and find_macro_in_condfig (env_config_file , 'SYS_PKGS_DOWNLOAD_ACCELERATE' ):
411406 payload_pkgs_name_in_json = pkgs_name_in_json .encode ("utf-8" )
412- payload ["packages" ][0 ]['name' ] = payload_pkgs_name_in_json
413-
414- try :
415- r = requests .post (
416- "http://packages.rt-thread.org/packages/queries" , data = json .dumps (payload ))
417- if r .status_code == requests .codes .ok :
418- #print("Software package get Successful")
419- package_info = json .loads (r .text )
420-
421- if len (package_info ['packages' ]) == 0 :
422- print ("Package was NOT found on mirror server." )
423- else :
424- for item in package_info ['packages' ][0 ]['packages_info' ]['site' ]:
425- if item ['version' ] == "latest_version" or item ['version' ] == "latest" :
426- # change origin url to the path which get
427- # from mirror server
428- cmd = 'git remote set-url origin ' + \
429- item ['URL' ]
430-
431- git_cmd_exec (cmd , repo_path )
432-
433- #print(cmd)
434- except Exception , e :
435- print ('e.message:%s\t ' % e .message )
436- print (
437- "The server could not be contacted. Please check your network connection." )
438-
439- # Only one trace relationship can be used directly with git pull.
407+
408+ # Change repo's upstream address.
409+ mirror_url = get_url_from_mirror_server (payload_pkgs_name_in_json , pkg ['ver' ])
410+
411+ if mirror_url [0 ] != None :
412+ cmd = 'git remote set-url origin ' + mirror_url [0 ]
413+ git_cmd_exec (cmd , repo_path )
414+
415+ # Update the package repository from upstream.
440416 cmd = 'git pull'
441417 git_cmd_exec (cmd , repo_path )
442418
443419 # If the package has submodules, update the submodules.
444420 update_submodule (repo_path )
445421
446422 # recover origin url to the path which get from packages.json file
447- if package .get_url (pkg ['ver' ]) :
448- cmd = 'git remote set-url origin ' + package .get_url (pkg ['ver' ])
449- git_cmd_exec (cmd , repo_path )
450-
423+ if package .get_url (pkg ['ver' ]):
424+ cmd = 'git remote set-url origin ' + \
425+ package .get_url (pkg ['ver' ])
426+ git_cmd_exec (cmd , repo_path )
427+ else :
428+ print ("Can't find the package : %s's url in file : %s" %
429+ (payload_pkgs_name_in_json , pkg_path ))
430+
451431 print ("==============================> %s update done \n " %
452432 (pkgs_name_in_json ))
453433
0 commit comments