<commit_before>import os
import pipes

from fabric.api import (put, run, sudo)
from fabric.tasks import WrappedCallableTask

from st2common import log as logging


LOG = logging.getLogger(__name__)


class SSHCommandAction(object):
    def __init__(self, name, action_exec_id, command, user, password=<PASSWORD>, pkey=None, hosts=None,
                 parallel=True, sudo=False):
        self.name = name
        self.command = command
        self.id = action_exec_id
        self.hosts = hosts
        self.parallel = parallel
        self.sudo = sudo
        self.user = user
        self.pkey = pkey
        self.password = password

    def is_parallel(self):
        return self.parallel

    def is_sudo(self):
        return self.sudo

    def get_user(self):
        return self.user

    def get_hosts(self):
        return self.hosts

    def is_pkey_authentication(self):
        return self.pkey is not None

    def get_pkey(self):
        return self.pkey

    def get_password(self):
        return self.password

    def get_command(self):
        return self.command

    def __str__(self):
        str_rep = []
        str_rep.append('%s@%s(name: %s' % (self.__class__.__name__, id(self), self.name))
        str_rep.append('id: ' + self.id)
        str_rep.append('command: ' + self.command)
        str_rep.append('user: ' + self.user)
        str_rep.append('sudo: ' + str(self.sudo))
        str_rep.append('parallel: ' + str(self.parallel))
        str_rep.append('hosts: %s)' % str(self.hosts))

        return ', '.join(str_rep)


class RemoteAction(SSHCommandAction):
    def __init__(self, name, action_exec_id, command, on_behalf_user=None, user=None, hosts=None,
                 parallel=True, sudo=False):
        super(RemoteAction, self).__init__(name, action_exec_id, command, user,
                                           hosts=hosts, parallel=parallel, sudo=sudo)
        self.on_behalf_user = on_behalf_user  # Used for audit purposes.

    def get_on_behalf_user(self):
        return self.user

    def __str__(self):
        str_rep = []
        str_rep.append('%s@%s(name: %s' % (self.__class__.__name__, id(self), self.name))
        str_rep.append('id: ' + self.id)
        str_rep.append('command: ' + self.command)
        str_rep.append('user: ' + self.user)
        str_rep.append('on_behalf_user: ' + self.on_behalf_user)
        str_rep.append('sudo: ' + str(self.sudo))
        str_rep.append('parallel: ' + str(self.parallel))
        str_rep.append('hosts: %s)' % str(self.hosts))

        return ', '.join(str_rep)


class RemoteScriptAction(RemoteAction):
    def __init__(self, name, action_exec_id, script_local_path_abs, script_args=None,
                 on_behalf_user=None, user=None, remote_dir=None, hosts=None, parallel=True,
                 sudo=False):
        super(RemoteScriptAction, self).__init__(name, action_exec_id, '', on_behalf_user, user,
                                                 hosts=hosts, parallel=parallel, sudo=sudo)
        self.script_local_path_abs = script_local_path_abs
        self.script_local_dir, self.script_name = os.path.split(self.script_local_path_abs)
        self.script_args = script_args

        self.remote_dir = remote_dir if remote_dir is not None else '/tmp'
        self.remote_script = os.path.join(self.remote_dir, self.script_name)
        command_parts = []
        command_parts.append(self.remote_script)
        if self.script_args is not None:
            command_parts.append(self.script_args)
        self.command = " ".join(pipes.quote(s) for s in command_parts)
        LOG.debug('RemoteScriptAction: command to run on remote box: %s', self.command)
<commit_msg>Fix: args for script action passed in correctly<commit_after>import os
import pipes

from fabric.api import (put, run, sudo)
from fabric.tasks import WrappedCallableTask

from st2common import log as logging


LOG = logging.getLogger(__name__)


class SSHCommandAction(object):
    def __init__(self, name, action_exec_id, command, user, password=<PASSWORD>, pkey=None, hosts=None,
                 parallel=True, sudo=False):
        self.name = name
        self.command = command
        self.id = action_exec_id
        self.hosts = hosts
        self.parallel = parallel
        self.sudo = sudo
        self.user = user
        self.pkey = pkey
        self.password = password

    def is_parallel(self):
        return self.parallel

    def is_sudo(self):
        return self.sudo

    def get_user(self):
        return self.user

    def get_hosts(self):
        return self.hosts

    def is_pkey_authentication(self):
        return self.pkey is not None

    def get_pkey(self):
        return self.pkey

    def get_password(self):
        return <PASSWORD>

    def get_command(self):
        return self.command

    def __str__(self):
        str_rep = []
        str_rep.append('%s@%s(name: %s' % (self.__class__.__name__, id(self), self.name))
        str_rep.append('id: ' + self.id)
        str_rep.append('command: ' + self.command)
        str_rep.append('user: ' + self.user)
        str_rep.append('sudo: ' + str(self.sudo))
        str_rep.append('parallel: ' + str(self.parallel))
        str_rep.append('hosts: %s)' % str(self.hosts))

        return ', '.join(str_rep)


class RemoteAction(SSHCommandAction):
    def __init__(self, name, action_exec_id, command, on_behalf_user=None, user=None, hosts=None,
                 parallel=True, sudo=False):
        super(RemoteAction, self).__init__(name, action_exec_id, command, user,
                                           hosts=hosts, parallel=parallel, sudo=sudo)
        self.on_behalf_user = on_behalf_user  # Used for audit purposes.

    def get_on_behalf_user(self):
        return self.user

    def __str__(self):
        str_rep = []
        str_rep.append('%s@%s(name: %s' % (self.__class__.__name__, id(self), self.name))
        str_rep.append('id: ' + self.id)
        str_rep.append('command: ' + self.command)
        str_rep.append('user: ' + self.user)
        str_rep.append('on_behalf_user: ' + self.on_behalf_user)
        str_rep.append('sudo: ' + str(self.sudo))
        str_rep.append('parallel: ' + str(self.parallel))
        str_rep.append('hosts: %s)' % str(self.hosts))

        return ', '.join(str_rep)


class RemoteScriptAction(RemoteAction):
    def __init__(self, name, action_exec_id, script_local_path_abs, script_args=None,
                 on_behalf_user=None, user=None, remote_dir=None, hosts=None, parallel=True,
                 sudo=False):
        super(RemoteScriptAction, self).__init__(name, action_exec_id, '', on_behalf_user, user,
                                                 hosts=hosts, parallel=parallel, sudo=sudo)
        self.script_local_path_abs = script_local_path_abs
        self.script_local_dir, self.script_name = os.path.split(self.script_local_path_abs)
        self.script_args = script_args

        self.remote_dir = remote_dir if remote_dir is not None else '/tmp'
        self.remote_script = os.path.join(self.remote_dir, self.script_name)
        command_parts = []
        command_parts.append(self.remote_script)
        for arg in self.script_args.split(' '):
            command_parts.append(arg)
        self.command = " ".join(pipes.quote(s) for s in command_parts)
        LOG.debug('RemoteScriptAction: command to run on remote box: %s', self.command)

{'fraction_non_alphanumeric': 0.11247471341874579, 'fraction_numerical': 0.00026972353337828726, 'mean_word_length': 2.6157971721111655, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4219201', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2272, 'n_words': 466}