<commit_before># Copyright 2015 Cloudbase Solutions Srl
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""Contains base recipes functionality.

A recipe is a class which knows how to provision an instance,
by installing and configuring it with what it's necessary.
"""

import abc

import six

from argus import util


LOG = util.get_logger()
RETRY_COUNT = 15
RETRY_DELAY = 10


__all__ = (
    'BaseRecipe',
)


@six.add_metaclass(abc.ABCMeta)
class BaseRecipe(object):
    """Base class for a recipe.

    A recipe is a way in which an instance can be provisioned with
    some easy steps.
    """

    def __init__(self, instance_id, api_manager, remote_client, image,
                 service_type, output_directory=None):
        self._api_manager = api_manager
        self._instance_id = instance_id
        self._remote_client = remote_client
        self._image = image
        self._service_type = service_type
        self._output_directory = output_directory

    def _execute(self, cmd, count=RETRY_COUNT, delay=RETRY_DELAY):
        """Execute until success and return only the standard output."""

        # A positive exit code will trigger the failure
        # in the underlying methods as an `ArgusError`.
        # Also, if the retrying limit is reached, `ArgusTimeoutError`
        # will be raised.
        return self._remote_client.run_command_with_retry(
            cmd, retry_count=count, delay=delay)[0]

    def _execute_until_condition(self, cmd, cond, count=RETRY_COUNT,
                                 delay=RETRY_DELAY):
        """Execute a command until the condition is met without returning."""
        self._remote_client.run_command_until_condition(
            cmd, cond, count=count, delay=delay)

    @abc.abstractmethod
    def prepare(self):
        """Call this method to provision an instance."""<commit_msg>fixed call to run_command_until_condition<commit_after># Copyright 2015 Cloudbase Solutions Srl
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""Contains base recipes functionality.

A recipe is a class which knows how to provision an instance,
by installing and configuring it with what it's necessary.
"""

import abc

import six

from argus import util


LOG = util.get_logger()
RETRY_COUNT = 15
RETRY_DELAY = 10


__all__ = (
    'BaseRecipe',
)


@six.add_metaclass(abc.ABCMeta)
class BaseRecipe(object):
    """Base class for a recipe.

    A recipe is a way in which an instance can be provisioned with
    some easy steps.
    """

    def __init__(self, instance_id, api_manager, remote_client, image,
                 service_type, output_directory=None):
        self._api_manager = api_manager
        self._instance_id = instance_id
        self._remote_client = remote_client
        self._image = image
        self._service_type = service_type
        self._output_directory = output_directory

    def _execute(self, cmd, count=RETRY_COUNT, delay=RETRY_DELAY):
        """Execute until success and return only the standard output."""

        # A positive exit code will trigger the failure
        # in the underlying methods as an `ArgusError`.
        # Also, if the retrying limit is reached, `ArgusTimeoutError`
        # will be raised.
        return self._remote_client.run_command_with_retry(
            cmd, retry_count=count, delay=delay)[0]

    def _execute_until_condition(self, cmd, cond, count=RETRY_COUNT,
                                 delay=RETRY_DELAY):
        """Execute a command until the condition is met without returning."""
        self._remote_client.run_command_until_condition(
            cmd, cond, retry_count=count, delay=delay)

    @abc.abstractmethod
    def prepare(self):
        """Call this method to provision an instance."""
{'fraction_non_alphanumeric': 0.07263722657862154, 'fraction_numerical': 0.005365249690466364, 'mean_word_length': 3.0459098497495827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2602461', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1291, 'n_words': 498}