<commit_before>from cloudshell.api.cloudshell_api import AppConfiguration

from cloudshell.workflow.orchestration.app import App


class AppsConfiguration(object):
    def __init__(self, sandbox):
        self.sandbox = sandbox
        """:type : Sandbox"""

    def set_config_param(self, app, key, value):
        """
        :param App app:
        :param str key:
        :param str value:
        :return:
        """
        if isinstance(app, App):
            self.sandbox.components.apps[app.app_request.app_resource.Name].app_request.add_app_config_param(key, value)
            self.sandbox.logger.info("App config param with key: '{0}' and value: '{1}' was added to app-resource '{2}'"
                                     .format(key, value, app.app_request.app_resource.Name))
        else:
            self.sandbox.logger.error("set_config_param: app parameter is not from the correct type")
            raise Exception("Sandbox is Active with Errors")

    def apply_apps_configurations(self, apps):
        """
        :param list[App] apps:
        :return:
        """
        apps_configuration = []

        for app in apps:
            if len(app.app_request.appConfiguration) > 0:
                apps_configuration.append(AppConfiguration(app.deployed_app.Name,
                                                           app.app_request.appConfiguration))<commit_msg>fix Bug 161794:Handle a scenario where apply_apps_configurations doesn't get an App object<commit_after>from cloudshell.api.cloudshell_api import AppConfiguration

from cloudshell.workflow.orchestration.app import App


class AppsConfiguration(object):
    def __init__(self, sandbox):
        self.sandbox = sandbox
        """:type : Sandbox"""

    def set_config_param(self, app, key, value):
        """
        :param App app:
        :param str key:
        :param str value:
        :return:
        """
        if isinstance(app, App):
            self.sandbox.components.apps[app.app_request.app_resource.Name].app_request.add_app_config_param(key, value)
            self.sandbox.logger.info("App config param with key: '{0}' and value: '{1}' was added to app-resource '{2}'"
                                     .format(key, value, app.app_request.app_resource.Name))
        else:
            self.sandbox.logger.error("set_config_param: app parameter is not from the correct type")
            raise Exception("Sandbox is Active with Errors")

    def apply_apps_configurations(self, apps):
        """
        :param list[App] apps:
        :return:
        """

        if not all(isinstance(app, App) for app in apps):
            self.sandbox.logger.error("apply_apps_configurations should get list of Apps, please refer to the "
                                      "CloudShell DevGuide for more information")
            raise Exception("Sandbox is Active with Errors")

        apps_configuration = []

        for app in apps:
            if len(app.app_request.appConfiguration) > 0:
                apps_configuration.append(AppConfiguration(app.deployed_app.Name,
                                                           app.app_request.appConfiguration))
{'fraction_non_alphanumeric': 0.09577819785759294, 'fraction_numerical': 0.004410838059231254, 'mean_word_length': 2.1529294935451837, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1091480', 'n_tokens_mistral': 867, 'n_tokens_neox': 832, 'n_words': 213}