<commit_before>#/***************************************************************************
# * Copyright (c) 2013 GigaSpaces Technologies Ltd. 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.
# ***************************************************************************/

import logging
import os
from os.path import dirname
import subprocess
import shlex
import ast
import _ast
from os import path

from celery.utils.log import get_task_logger
from cloudify.constants import VIRTUALENV_PATH_KEY, CELERY_WORK_DIR_PATH_KEY
from cloudify.utils import get_cosmo_properties
from cloudify.decorators import operation


logger = get_task_logger(__name__)
logger.level = logging.DEBUG


@operation
def install(plugin, __cloudify_id, **kwargs):
    """
    Installs plugin as celery task according to the provided plugins details.
    plugin parameter is expected to be in the following format:
            { name: "...", url: "..." }
    The plugin url should be a URL pointing to either a zip or tar.gz file.
    """

    logger.debug("installing plugin [%s] in host [%s]", plugin, __cloudify_id)

    management_ip = get_cosmo_properties()["management_ip"]
    if management_ip:
        plugin["url"] = plugin['url'] \
            .replace("#{plugin_repository}",
                     "http://{0}:{1}".format(management_ip, "53229"))

    install_celery_plugin(plugin)


def uninstall(plugin, __cloudify_id, **kwargs):
    logger.debug("uninstalling plugin [%s] in host [%s]",
                 plugin,
                 __cloudify_id)

    uninstall_celery_plugin(plugin['name'])


@operation
def verify_plugin(worker_id, plugin_name, operation, throw_on_failure,
                  **kwargs):
    """<commit_msg>CLOUDIFY-2475 use new ctx in plugin<commit_after>#/***************************************************************************
# * Copyright (c) 2013 GigaSpaces Technologies Ltd. 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.
# ***************************************************************************/

import logging
import os
from os.path import dirname
import subprocess
import shlex
import ast
import _ast
from os import path

from celery.utils.log import get_task_logger
from cloudify.constants import VIRTUALENV_PATH_KEY, CELERY_WORK_DIR_PATH_KEY
from cloudify.utils import get_cosmo_properties
from cloudify.decorators import operation


logger = get_task_logger(__name__)
logger.level = logging.DEBUG


@operation
def install(ctx, plugin, **kwargs):
    """
    Installs plugin as celery task according to the provided plugins details.
    plugin parameter is expected to be in the following format:
            { name: "...", url: "..." }
    The plugin url should be a URL pointing to either a zip or tar.gz file.
    """

    ctx.logger.debug("installing plugin [%s] ", plugin)

    management_ip = get_cosmo_properties()["management_ip"]
    if management_ip:
        plugin["url"] = plugin['url'] \
            .replace("#{plugin_repository}",
                     "http://{0}:{1}".format(management_ip, "53229"))

    install_celery_plugin(plugin)


def uninstall(plugin, __cloudify_id, **kwargs):
    logger.debug("uninstalling plugin [%s] in host [%s]",
                 plugin,
                 __cloudify_id)

    uninstall_celery_plugin(plugin['name'])


@operation
def verify_plugin(worker_id, plugin_name, operation, throw_on_failure,
                  **kwargs):
    """
{'fraction_non_alphanumeric': 0.1561321800842759, 'fraction_numerical': 0.00754047460634287, 'mean_word_length': 3.7724867724867726, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4408091', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1180, 'n_words': 421}