#NEWLINE# def log_pull_stream( stream ) : #NEWLINE# #INDENT# '\n    Handle the printing of pull statuses\n    ' #NEWLINE# previous_id = '' #NEWLINE# previous_message = '' #NEWLINE# for line in stream : #NEWLINE# #INDENT# json_line = json . loads ( line ) #NEWLINE# current_id = ( json_line [ 'id' ] if ( 'id' in json_line ) else '' ) #NEWLINE# current_status = ( json_line [ 'status' ] if ( 'status' in json_line ) else '' ) #NEWLINE# backspaces = ( '\x08' * len ( previous_message ) ) #NEWLINE# spaces = ( ' ' * len ( previous_message ) ) #NEWLINE# current_message = '\n{0}: {1}' . format ( spaces , current_status ) #NEWLINE# if ( ( current_status == 'Downloading' ) or ( current_status == 'Extracting' ) ) : #NEWLINE# #INDENT# current_message = '{0} {1}' . format ( current_message , json_line [ 'progress' ] ) #NEWLINE# #UNINDENT# if ( not current_id ) : #NEWLINE# #INDENT# sys . stdout . write ( '\n{0}' . format ( current_status ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( current_id == previous_id ) : #NEWLINE# #INDENT# sys . stdout . write ( backspaces ) #NEWLINE# sys . stdout . write ( spaces ) #NEWLINE# sys . stdout . write ( backspaces ) #NEWLINE# sys . stdout . write ( current_message . strip ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . stdout . write ( current_message ) #NEWLINE# #UNINDENT# #UNINDENT# sys . stdout . flush ( ) #NEWLINE# previous_message = current_message #NEWLINE# previous_id = current_id #NEWLINE# #UNINDENT# print ( )