@@ -2012,11 +2012,14 @@ def _textualize_pull_logs(logs, image, tag):
20122012 The image tag being pulled.
20132013
20142014 """
2015- pstats : dict [str , tuple [int , int ]] = {}
2016- pstats_cursor : int = 0
2017- pstats_cursor_move : int = 1
2015+ pstats : dict [str , tuple [int , int , int ]] = {}
20182016 dmsgs : list [str ] = []
20192017
2018+ p_c : int = 0 # bytes cursor
2019+ p_c_m : int = 1 # bytes cursor move
2020+ p_c_p : int = 0 # progress cursor
2021+ p_c_p_m : int = 1 # progress cursor move
2022+
20202023 for log in logs :
20212024 id_ = log .get ("id" , None )
20222025 status = log .get ("status" , "" )
@@ -2027,38 +2030,50 @@ def _textualize_pull_logs(logs, image, tag):
20272030 continue
20282031
20292032 if id_ not in pstats :
2030- pstats [id_ ] = (0 , 0 )
2033+ pstats [id_ ] = (0 , 0 , 0 )
20312034 continue
20322035
20332036 progress = log .get ("progressDetail" , {})
20342037 progress_total = progress .get ("total" , None )
20352038 progress_current = progress .get ("current" , None )
20362039
20372040 if progress_total is not None or progress_current is not None :
2038- pstats [id_ ] = (progress_total or 0 , progress_current or 0 )
2041+ pstats [id_ ] = (
2042+ progress_total or 0 ,
2043+ progress_current or 0 ,
2044+ 0 if not progress_total else progress_current * 100 // progress_total ,
2045+ )
20392046
2040- pstats_total , pstats_current = 0 , 0
2041- for t , c in pstats .values ():
2047+ pstats_total , pstats_current , pstats_progress = 0 , 0 , 0
2048+ for t , c , p in pstats .values ():
20422049 pstats_total += t
20432050 pstats_current += c
2051+ pstats_progress += p
2052+
2053+ p_c_d = pstats_current - p_c # bytes cursor delta
20442054
20452055 if pstats_total :
2046- pstats_cursor_diff = int (
2047- pstats_current * 100 // pstats_total - pstats_cursor ,
2048- )
2049- if pstats_cursor_diff >= pstats_cursor_move and pstats_cursor < 100 :
2050- pstats_cursor += pstats_cursor_diff
2051- pstats_cursor_move = min (5 , pstats_cursor_move + 1 )
2052- print (f"Pulling image { image } : { pstats_cursor } %" , flush = True )
2056+ p_c_p_d = pstats_progress // len (pstats ) - p_c_p # progress cursor delta
2057+ # Update textual progress when:
2058+ # 1. Progress is not complete yet, and
2059+ # 2. Progress cursor delta >= progress cursor move, or
2060+ # 3. Bytes cursor delta >= bytes cursor move.
2061+ if p_c_p < 100 and (p_c_p_d >= p_c_p_m or p_c_d >= p_c_m ):
2062+ p_c += p_c_d
2063+ p_c_m = min (200 * _MiB , p_c_m + 2 * _MiB )
2064+ p_c_p_n = min (p_c_p + p_c_p_d , 100 ) # progress cursor new
2065+ # Update progress cursor if it has advanced.
2066+ if p_c_p_n > p_c_p :
2067+ p_c_p = p_c_p_n
2068+ p_c_p_m = min (5 , p_c_p_m + 1 , 100 - p_c_p )
2069+ print (f"Pulling image { image } : { p_c_p } %" , flush = True )
20532070 elif pstats_current :
2054- pstats_cursor_diff = int (
2055- pstats_current - pstats_cursor ,
2056- )
2057- if pstats_cursor_diff >= pstats_cursor_move :
2058- pstats_cursor += pstats_cursor_diff
2059- pstats_cursor_move = min (200 * _MiB , pstats_cursor_move + 2 * _MiB )
2060- pstats_cursor_human = bytes_to_human_readable (pstats_cursor )
2061- print (f"Pulling image { image } : { pstats_cursor_human } " , flush = True )
2071+ # Update textual progress when bytes cursor delta >= bytes cursor move.
2072+ if p_c_d >= p_c_m :
2073+ p_c += p_c_d
2074+ p_c_m = min (200 * _MiB , p_c_m + 2 * _MiB )
2075+ p_c_h = bytes_to_human_readable (p_c )
2076+ print (f"Pulling image { image } : { p_c_h } " , flush = True )
20622077
20632078 for msg in dmsgs :
20642079 print (msg , flush = True )
0 commit comments