@@ -503,6 +503,48 @@ def pre_package_update():
503503 return [oldpkgs , newpkgs , pkgs_fn , bsp_packages_path , dbsqlite_pathname ]
504504
505505
506+ def error_packages_handle (error_packages_list , read_back_pkgs_json , pkgs_fn ):
507+ bsp_root = Import ('bsp_root' )
508+ env_root = Import ('env_root' )
509+
510+ flag = None
511+
512+ error_packages_redownload_error_list = []
513+
514+ if len (error_packages_list ):
515+ print ("\n ==============================> Error packages list : \n " )
516+ for pkg in error_packages_list :
517+ print pkg ['name' ], pkg ['ver' ]
518+ print ("\n The package in the list above is accidentally deleted." )
519+ print ("Env will redownload packages that have been accidentally deleted." )
520+ print ("If you really want to remove these packages, do that in the menuconfig command.\n " )
521+
522+ for pkg in error_packages_list : # Redownloaded the packages in error_packages_list
523+ if install_pkg (env_root , bsp_root , pkg ):
524+ print ("==============================> %s %s is redownloaded successfully. \n " % (
525+ pkg ['name' ], pkg ['ver' ]))
526+ else :
527+ error_packages_redownload_error_list .append (pkg )
528+ print pkg , 'download failed.'
529+ flag = False
530+
531+ if len (error_packages_redownload_error_list ):
532+ print ("%s" % error_packages_redownload_error_list )
533+ print ("Packages:%s,%s redownloed error,you need to use 'pkgs --update' command again to redownload them." %
534+ pkg ['name' ], pkg ['ver' ])
535+ write_back_pkgs_json = sub_list (
536+ read_back_pkgs_json , error_packages_redownload_error_list )
537+ read_back_pkgs_json = write_back_pkgs_json
538+ #print("write_back_pkgs_json:%s"%write_back_pkgs_json)
539+ pkgs_file = file (pkgs_fn , 'w' )
540+ pkgs_file .write (json .dumps (write_back_pkgs_json , indent = 1 ))
541+ pkgs_file .close ()
542+ else :
543+ print ("\n All the selected packages have been downloaded successfully.\n " )
544+
545+ return flag
546+
547+
506548def package_update ():
507549 """Update env's packages.
508550
@@ -511,12 +553,12 @@ def package_update():
511553 Check if the files in the deleted packages have been changed, and if so,
512554 remind the user saved the modified file.
513555 """
514-
556+
515557 bsp_root = Import ('bsp_root' )
516558 env_root = Import ('env_root' )
517559
518560 flag = True
519-
561+
520562 sys_value = pre_package_update ()
521563 oldpkgs = sys_value [0 ]
522564 newpkgs = sys_value [1 ]
@@ -543,7 +585,7 @@ def package_update():
543585 removepath_git = os .path .join (git_removepath , '.git' )
544586 #print "floder to delete",removepath
545587 #print "removepath_git to delete",removepath_git
546-
588+
547589 # Delete. Git directory.
548590
549591 if os .path .isdir (git_removepath ) and os .path .isdir (removepath_git ):
@@ -628,7 +670,7 @@ def package_update():
628670 #print(read_back_pkgs_json)
629671
630672 error_packages_list = []
631- error_packages_redownload_error_list = []
673+
632674 for pkg in read_back_pkgs_json :
633675 dirpath = pkg ['path' ]
634676 ver = pkg ['ver' ]
@@ -638,56 +680,33 @@ def package_update():
638680
639681 dirpath = os .path .basename (dirpath )
640682 removepath = os .path .join (bsp_packages_path , dirpath )
641-
683+ #print("if floder exist : %s"%removepath)
642684 git_removepath = get_pkg_folder_by_orign_path (removepath , ver )
643- #print "if floder exist",removepath
685+ #print( "if floder exist : %s"%git_removepath)
644686 removepath_ver = get_pkg_folder_by_orign_path (removepath , ver [1 :])
645- #print "if floder exist",removepath
687+ #print( "if floder exist : %s"%removepath_ver)
646688
647689 if os .path .exists (removepath ):
648690 continue
649691 elif os .path .exists (removepath_ver ):
650692 continue
651693 elif os .path .exists (git_removepath ):
652- continue
694+ continue
653695 else :
654696 error_packages_list .append (pkg )
655697
656- if len (error_packages_list ):
657- print ("\n ==============================> Error packages list : \n " )
658- for pkg in error_packages_list :
659- print pkg ['name' ], pkg ['ver' ]
660- print ("\n The package in the list above is accidentally deleted." )
661- print ("Env will redownload packages that have been accidentally deleted." )
662- print ("If you really want to remove these packages, do that in the menuconfig command.\n " )
698+ # Handle the failed download packages
699+ get_flag = error_packages_handle (
700+ error_packages_list , read_back_pkgs_json , pkgs_fn )
663701
664- for pkg in error_packages_list : # Redownloaded the packages in error_packages_list
665- if install_pkg (env_root , bsp_root , pkg ):
666- print ("==============================> %s %s is redownloaded successfully. \n " % (
667- pkg ['name' ], pkg ['ver' ]))
668- else :
669- error_packages_redownload_error_list .append (pkg )
670- print pkg , 'download failed.'
671- flag = False
672-
673- if len (error_packages_redownload_error_list ):
674- print ("%s" % error_packages_redownload_error_list )
675- print ("Packages:%s,%s redownloed error,you need to use 'pkgs --update' command again to redownload them." %
676- pkg ['name' ], pkg ['ver' ])
677- write_back_pkgs_json = sub_list (
678- read_back_pkgs_json , error_packages_redownload_error_list )
679- read_back_pkgs_json = write_back_pkgs_json
680- #print("write_back_pkgs_json:%s"%write_back_pkgs_json)
681- pkgs_file = file (pkgs_fn , 'w' )
682- pkgs_file .write (json .dumps (write_back_pkgs_json , indent = 1 ))
683- pkgs_file .close ()
684- else :
685- print ("\n All the selected packages have been downloaded successfully.\n " )
702+ if get_flag != None :
703+ flag = get_flag
686704
705+ # Update the software packages, which the version is 'latest'
687706 try :
688707 update_latest_packages (read_back_pkgs_json , bsp_packages_path )
689708 except KeyboardInterrupt :
690- flag = 0
709+ flag = False
691710
692711 if flag :
693712 print ("Operation completed successfully." )
0 commit comments