<commit_before>"""
In a lot of places we need to make system calls, mainly through subprocess.
Here we define them and reuse them with the added functionality of getting
logging and remote execution.

This allows us to only remote-execute the actual calls, not whole functions.
"""
from ceph_deploy.util.decorators import remote_compile
from ceph_deploy.util import context


def check_call(args, logger, conn, *a, **kw):
    command = ' '.join(args)
    logger.info('Running command: %s' % command)

    def remote_call(args, *a, **kw):
        import subprocess
        subprocess.check_call(
            args,
            *a,
            **kw
        )

    compile_ = remote_compile(conn, remote_call)
    with context.capsys(conn, logger):
        try:
            return compile_(args, *a, **kw)
        except Exception as err:
            if getattr(err, 'remote_traceback'):
                for line in err.remote_traceback:
                    logger.error(line)
            else:
                raise


def generic_remote(func, logger, conn, *a, **kw):
    """
    This generic remote wrapper will introspect the docstring from ``func`` to
    log out the action about to be done. It better be succinct.
    """
    action = getattr(func, 'func_doc', func.func_name)
    logger.info('Executing action: %s' % action)

    compile_ = remote_compile(conn, func)
    with context.capsys(conn, logger):
        try:
            return compile_(*a, **kw)
        except Exception as err:
            if getattr(err, 'remote_traceback'):
                for line in err.remote_traceback:
                    logger.error(line)
            else:
                raise<commit_msg>nicer API to do remote check_calls<commit_after>"""
In a lot of places we need to make system calls, mainly through subprocess.
Here we define them and reuse them with the added functionality of getting
logging and remote execution.

This allows us to only remote-execute the actual calls, not whole functions.
"""
from ceph_deploy.util.decorators import remote_compile
from ceph_deploy.util import context


def check_call(conn, logger, args, *a, **kw):
    """
    Wraps ``subprocess.check_call`` for a remote call via ``pushy``
    doing all the capturing and logging nicely upon failure/success

    :param args: The args to be passed onto ``check_call``
    """
    command = ' '.join(args)
    logger.info('Running command: %s' % command)

    def remote_call(args, *a, **kw):
        import subprocess
        subprocess.check_call(
            args,
            *a,
            **kw
        )

    with context.remote(conn, logger, remote_call) as call:
        return call(args, *a, **kw)
{'fraction_non_alphanumeric': 0.09253731343283582, 'fraction_numerical': 0.0, 'mean_word_length': 2.5137614678899083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '788121', 'n_tokens_mistral': 758, 'n_tokens_neox': 737, 'n_words': 274}