<commit_before>import os
import re

import docker

from cloudify import exceptions


_ERR_MSG_UNKNOWN_IMAGE_IMPORT = 'Unknown error during image import'
_ERR_MSG_UNKNOWN_IMAGE_BUILD = 'Unknown error while building image'


def _is_image_id_valid(ctx, image_id):
    return re.match('^[a-f0-9]{12,64}$', image_id) is not None


def _get_import_image_id(ctx, client, import_image_output):
    # import_image returns long string where in the second line
    # after last status is image id
    try:
        output_line = import_image_output.split('\n')[1]
    except IndexError as e:
        _log_and_raise(ctx, client, _ERR_MSG_UNKNOWN_IMAGE_IMPORT)
    position_of_last_status = output_line.rfind('status')
    if position_of_last_status < 0:
        # If there was an error, there is no 'status'
        # in second output line
        # error message is after last 'error'
        position_of_error = output_line.rfind('error')
        err_msg = output_line[position_of_error:].split('"')[2]
        err_msg = 'Error during image import {}'.format(err_msg)
        _log_and_raise(ctx, client, err_msg)
    try:<commit_msg>Fixed picking wrong line during image import<commit_after>import os
import re

import docker

from cloudify import exceptions


_ERR_MSG_UNKNOWN_IMAGE_IMPORT = 'Unknown error during image import'
_ERR_MSG_UNKNOWN_IMAGE_BUILD = 'Unknown error while building image'


def _is_image_id_valid(ctx, image_id):
    return re.match('^[a-f0-9]{12,64}$', image_id) is not None


def _get_import_image_id(ctx, client, import_image_output):
    # import_image returns long string where in the second line
    # after last status is image id
    try:
        output_line = import_image_output.split('\n')[-2]
    except IndexError as e:
        _log_and_raise(ctx, client, _ERR_MSG_UNKNOWN_IMAGE_IMPORT)
    position_of_last_status = output_line.rfind('status')
    if position_of_last_status < 0:
        # If there was an error, there is no 'status'
        # in second output line
        # error message is after last 'error'
        position_of_error = output_line.rfind('error')
        err_msg = output_line[position_of_error:].split('"')[2]
        err_msg = 'Error during image import {}'.format(err_msg)
        _log_and_raise(ctx, client, err_msg)
    try:
{'fraction_non_alphanumeric': 0.08560140474100088, 'fraction_numerical': 0.007901668129938543, 'mean_word_length': 3.848936170212766, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5262912', 'n_tokens_mistral': 731, 'n_tokens_neox': 726, 'n_words': 201}