def _parse_image_multilogs_string(ret):
 (image_logs, infos) = ([], None)
 if (ret and ret.strip().startswith('{') and ret.strip().endswith('}')):
  pushd = 0
  buf = ''
  for char in ret:
   buf += char
   if (char == '{'):
    pushd += 1
   if (char == '}'):
    pushd -= 1
   if (pushd == 0):
    try:
     buf = json.loads(buf)
    except Exception:
     pass
    else:
     image_logs.append(buf)
    buf = ''
  image_logs.reverse()
  valid_states = ['Download complete', 'Already exists']
  for ilog in image_logs:
   if isinstance(ilog, dict):
    if ((ilog.get('status') in valid_states) and ilog.get('id')):
     infos = _get_image_infos(ilog['id'])
     break
 return (image_logs, infos)

def _parse_image_multilogs_string ( ret ) : ( image_logs , infos ) = ( [ ] , None ) if ( ret and ret . strip ( ) . startswith ( '{' ) and ret . strip ( ) . endswith ( '}' ) ) : pushd = 0 buf = '' for char in ret : buf += char if ( char == '{' ) : pushd += 1 if ( char == '}' ) : pushd -= 1 if ( pushd == 0 ) : try : buf = json . loads ( buf ) except Exception : pass else : image_logs . append ( buf ) buf = '' image_logs . reverse ( ) valid_states = [ 'Download complete' , 'Already exists' ] for ilog in image_logs : if isinstance ( ilog , dict ) : if ( ( ilog . get ( 'status' ) in valid_states ) and ilog . get ( 'id' ) ) : infos = _get_image_infos ( ilog [ 'id' ] ) break return ( image_logs , infos )
parse image log strings into grokable data .