Example #1
0
    def run_and_capture(self):
        """
        Run a command and capture exceptions. This is a blocking call
        :returns: tuple of exitcode, error (or None)
        :rtype: int, str | None
        """

        subproc = Subproc().popen(
            [self._executable,  self._command] + self._args,
            stderr=subprocess.PIPE)

        err = ''
        while subproc.poll() is None:
            line = subproc.stderr.readline().decode('utf-8')
            err += line
            sys.stderr.write(line)
            sys.stderr.flush()

        exitcode = subproc.poll()
        # We only want to catch exceptions, not other stderr messages
        # (such as "task does not exist", so we look for the 'Traceback'
        # string.  This only works for python, so we'll need to revisit
        # this in the future when we support subcommands written in other
        # languages.
        err = ('Traceback' in err and err) or None

        return exitcode, err
Example #2
0
    def run_and_capture(self):
        """
        Run a command and capture exceptions. This is a blocking call
        :returns: tuple of exitcode, error (or None)
        :rtype: int, str | None
        """

        subproc = Subproc().popen(
            [self._executable,  self._command] + self._args,
            stderr=subprocess.PIPE)

        err = ''
        while subproc.poll() is None:
            line = subproc.stderr.readline().decode('utf-8')
            err += line
            sys.stderr.write(line)
            sys.stderr.flush()

        exitcode = subproc.poll()
        # We only want to catch exceptions, not other stderr messages
        # (such as "task does not exist", so we look for the 'Traceback'
        # string.  This only works for python, so we'll need to revisit
        # this in the future when we support subcommands written in other
        # languages.
        err = ('Traceback' in err and err) or None

        return exitcode, err
Example #3
0
def _execute_command(command):
    """
    :param command: a command to execute
    :type command: list of str
    :returns: stdout, stderr, the process return code
    :rtype: str, str, int
    """

    logger.info('Calling: %r', command)

    process = Subproc().popen(
        command,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)

    stdout, stderr = process.communicate()

    if process.returncode != 0:
        logger.error("Command script's stdout: %s", stdout)
        logger.error("Command script's stderr: %s", stderr)
    else:
        logger.info("Command script's stdout: %s", stdout)
        logger.info("Command script's stderr: %s", stderr)

    return stdout, stderr, process.returncode
Example #4
0
def _execute_command(command):
    """
    :param command: a command to execute
    :type command: list of str
    :returns: stdout, stderr, the process return code
    :rtype: str, str, int
    """

    logger.info('Calling: %r', command)

    process = Subproc().popen(
        command,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)

    stdout, stderr = process.communicate()

    if process.returncode != 0:
        logger.error("Command script's stdout: %s", stdout)
        logger.error("Command script's stderr: %s", stderr)
    else:
        logger.info("Command script's stdout: %s", stdout)
        logger.info("Command script's stderr: %s", stderr)

    return stdout, stderr, process.returncode
Example #5
0
def info(executable_path, path_noun):
    """Collects subcommand information

    :param executable_path: real path to the dcos subcommand
    :type executable_path: str
    :param path_noun: subcommand
    :type path_noun: str
    :returns: the subcommand information
    :rtype: str
    """

    out = Subproc().check_output([executable_path, path_noun, '--info'])

    return out.decode('utf-8').strip()
Example #6
0
def info(executable_path, path_noun):
    """Collects subcommand information

    :param executable_path: real path to the dcos subcommand
    :type executable_path: str
    :param path_noun: subcommand
    :type path_noun: str
    :returns: the subcommand information
    :rtype: str
    """

    out = Subproc().check_output(
        [executable_path, path_noun, '--info'])

    return out.decode('utf-8').strip()
Example #7
0
def config_schema(executable_path, noun=None):
    """Collects subcommand config schema

    :param executable_path: real path to the dcos subcommand
    :type executable_path: str
    :param noun: name of subcommand
    :type noun: str
    :returns: the subcommand config schema
    :rtype: dict
    """
    if noun is None:
        noun = noun(executable_path)

    out = Subproc().check_output([executable_path, noun, '--config-schema'])

    return json.loads(out.decode('utf-8'))
Example #8
0
def config_schema(executable_path, noun=None):
    """Collects subcommand config schema

    :param executable_path: real path to the dcos subcommand
    :type executable_path: str
    :param noun: name of subcommand
    :type noun: str
    :returns: the subcommand config schema
    :rtype: dict
    """
    if noun is None:
        noun = noun(executable_path)

    out = Subproc().check_output(
        [executable_path, noun, '--config-schema'])

    return json.loads(out.decode('utf-8'))