How to use the sarge.Command function in sarge

To help you get started, we’ve selected a few sarge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SFDO-Tooling / CumulusCI / cumulusci / tasks / ant.py View on Github external
def _run_ant_target(self, target, env):
        verbose = self.task_config.options__verbose in ('True','true')
            
        # Execute the command
        if verbose:
            cmd = 'ant %s' % target
        else:
            cmd = '%s/ci/ant_wrapper.sh %s' % (CUMULUSCI_PATH, target)
        p = sarge.Command(cmd, stdout=sarge.Capture(buffer_size=-1), env=env)
        p.run(async=True)
    
        # Print the stdout buffer until the command completes and capture all lines in log for reference in exceptions
        log = []
        while p.returncode is None:
            for line in p.stdout:
                log.append(line.rstrip())
                self.logger.info(line.rstrip())
            p.poll()
   
        # Check the return code, raise the appropriate exception if needed
        if p.returncode:
            logtxt = '\n'.join(log)
            try:
                if logtxt.find('All Component Failures:') != -1:
                    raise DeploymentException(logtxt)
github SFDO-Tooling / CumulusCI / cumulusci / tasks / salesforcedx.py View on Github external
def _call_salesforce_dx(self, command, options=None):
        full_command = 'heroku ' + command
        if options:
            full_command += ' {}'.format(options)

        full_command += ' -u {}'.format(self.org_config.username)
        
        self.logger.info('Running: {}'.format(full_command))
        p = sarge.Command(full_command, stdout=sarge.Capture(buffer_size=-1))
        p.run()

        output = []
        for line in p.stdout:
            self.logger.info(line)

        if p.returncode:
            message = '{}: {}'.format(p.returncode, p.stdout)
            self.logger.error(message)
            raise SalesforceDXException(message)
github SFDO-Tooling / CumulusCI / cumulusci / core / sfdx.py View on Github external
Be sure to quote user input that is part of the command using `sarge.shell_format`.

    Returns a `sarge` Command instance with returncode, stdout, stderr
    """
    command = "sfdx {}".format(command)
    if args is not None:
        for arg in args:
            command += " " + sarge.shell_quote(arg)
    if username:
        command += sarge.shell_format(" -u {0}", username)
    if log_note:
        logger.info("{} with command: {}".format(log_note, command))
    # Avoid logging access token
    if access_token:
        command += sarge.shell_format(" -u {0}", access_token)
    p = sarge.Command(
        command,
        stdout=sarge.Capture(buffer_size=-1) if capture_output else None,
        stderr=sarge.Capture(buffer_size=-1) if capture_output else None,
        shell=True,
        env=env,
    )
    p.run()
    if capture_output:
        p.stdout_text = io.TextIOWrapper(p.stdout, encoding=sys.stdout.encoding)
        p.stderr_text = io.TextIOWrapper(p.stderr, encoding=sys.stdout.encoding)
    if check_return and p.returncode:
        raise Exception(f"Command exited with return code {p.returncode}")
    return p
github SFDO-Tooling / CumulusCI / cumulusci / utils.py View on Github external
def get_git_config(config_key):
    p = sarge.Command(
        sarge.shell_format('git config --get "{0!s}"', config_key),
        stderr=sarge.Capture(buffer_size=-1),
        stdout=sarge.Capture(buffer_size=-1),
        shell=True,
    )
    p.run()
    config_value = (
        io.TextIOWrapper(p.stdout, encoding=sys.stdout.encoding).read().strip()
    )

    return config_value if config_value and not p.returncode else None

sarge

A wrapper for subprocess which provides command pipeline functionality.

BSD-2-Clause
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis