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 statest when pulling an image from the docker registry
        valid_states = [
            'Download complete',
            'Already exists',
        ]

        # search last layer grabbed
        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
dataset/ETHPy150Open saltstack/salt/salt/modules/dockerio.py/_parse_image_multilogs_string