<commit_before># -*- coding: utf-8 -*-

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


import os

import fabric.api
import fabric.contrib.files

from fab.helpers.feedback import ExecutionFeedback


class RemoteHostController(object):
    """RemoteHostController encapsulates basic command execution and path validation calls made to a remote host via Fabric"""

    def __init__(self, feedback):
        self.feedback = feedback

    @staticmethod
    def create_instance():
        return RemoteHostController(ExecutionFeedback())

    def path_exists(self, path):
        return fabric.contrib.files.exists(path)

    def run(self, command):
        return fabric.api.run(command)

    def sudo(self, command):
        return fabric.api.sudo(command)

    def cd(self, path):
        return fabric.api.cd(path)

    def hide_output(self):
        return fabric.api.hide('stdout')

    def get(self, remote_path, local_path=None):
        return fabric.api.get(remote_path, local_path)


class LocalHostController(object):
    """LocalHostController encapsulates basic command execution and path validation calls made to a local host via Fabric"""

    def __init__(self, feedback):
        self.feedback = feedback

    @staticmethod
    def create_instance():
        return LocalHostController(ExecutionFeedback())

    def path_exists(self, path):
        return os.path.exists(path)

    def run(self, command):
        return fabric.api.local(command)

    def sudo(self, command):
        return self.run("sudo %s" % command)

    def cd(self, path):
        return fabric.api.lcd(path)

    def hide_output(self):
        return fabric.api.hide('stdout')

    def get(self, remote_path, local_path=None):
        raise Exception("Unsupported operation: %s.get()" % LocalHostController.__name__)


class HostControllerMode(object):

    LOCAL = 'local'
    REMOTE = 'remote'

    allowed_modes = [LOCAL, REMOTE]

    @staticmethod
    def parse(mode_key):
        mode = mode_key.lower()
        if mode not in HostControllerMode.allowed_modes:<commit_msg>[#17289463] Added hide_command_and_output() wrapper methods on fab.host.controller.LocalHostController and RemoteHostController.<commit_after># -*- coding: utf-8 -*-

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


import os

import fabric.api
import fabric.contrib.files

from fab.helpers.feedback import ExecutionFeedback


class RemoteHostController(object):
    """RemoteHostController encapsulates basic command execution and path validation calls made to a remote host via Fabric"""

    def __init__(self, feedback):
        self.feedback = feedback

    @staticmethod
    def create_instance():
        return RemoteHostController(ExecutionFeedback())

    def path_exists(self, path):
        return fabric.contrib.files.exists(path)

    def run(self, command):
        return fabric.api.run(command)

    def sudo(self, command):
        return fabric.api.sudo(command)

    def cd(self, path):
        return fabric.api.cd(path)

    def hide_output(self):
        return fabric.api.hide('stdout')

    def hide_command_and_output(self):
        return fabric.api.hide('running', 'stdout')

    def get(self, remote_path, local_path=None):
        return fabric.api.get(remote_path, local_path)


class LocalHostController(object):
    """LocalHostController encapsulates basic command execution and path validation calls made to a local host via Fabric"""

    def __init__(self, feedback):
        self.feedback = feedback

    @staticmethod
    def create_instance():
        return LocalHostController(ExecutionFeedback())

    def path_exists(self, path):
        return os.path.exists(path)

    def run(self, command):
        return fabric.api.local(command)

    def sudo(self, command):
        return self.run("sudo %s" % command)

    def cd(self, path):
        return fabric.api.lcd(path)

    def hide_output(self):
        return fabric.api.hide('stdout')

    def hide_command_and_output(self):
        return fabric.api.hide('running', 'stdout')

    def get(self, remote_path, local_path=None):
        raise Exception("Unsupported operation: %s.get()" % LocalHostController.__name__)


class HostControllerMode(object):

    LOCAL = 'local'
    REMOTE = 'remote'

    allowed_modes = [LOCAL, REMOTE]

    @staticmethod
    def parse(mode_key):
        mode = mode_key.lower()
        if mode not in HostControllerMode.allowed_modes:
{'fraction_non_alphanumeric': 0.09630851722004537, 'fraction_numerical': 0.0020622808826562177, 'mean_word_length': 3.3654365436543654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '920671', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1323, 'n_words': 401}