Esempio n. 1
0
def run_cli_command(
    command: Union[List[str], str],
    working_directory: str,
    use_shell: bool = False,
    output_as_text: bool = True,
    capture_output: bool = True,
    **kwargs,
):
    """Execute command line subprocess"""
    result = subprocess.run(
        command,
        shell=use_shell,
        cwd=working_directory,
        text=output_as_text,
        capture_output=capture_output,
        **kwargs,
    )

    if result.stderr:
        raise subprocess.CalledProcessError(returncode=result.returncode,
                                            cmd=result.args,
                                            stderr=result.stderr)
    if result.stdout:
        if "Encountered an error" in result.stdout:  # Handle for dbt stdout errors
            logger.error("dbt Error: {}".format(result.stdout))
            raise subprocess.CalledProcessError(returncode=result.returncode,
                                                cmd=result.args,
                                                stderr=result.stdout)

        logger.debug("Command Result:\n{}".format(result.stdout))

    return result.stdout
Esempio n. 2
0
 def wrapper(*args, **kwargs):
     try:
         return function(*args, **kwargs)
     except DbteaException as error:
         logger.error(
             f"\n{error}\n\n" +
             "For support, please create an issue at https://github.com/spectacles-ci/spectacles/issues"
             + "\n")
         sys.exit(error.exit_code)
     except KeyboardInterrupt as error:
         logger.debug(error, exc_info=True)
         logger.info("Spectacles was manually interrupted.")
         sys.exit(1)
     except Exception as error:
         logger.debug(error, exc_info=True)
         logger.error(
             f'\nEncountered unexpected {error.__class__.__name__}: "{error}"\n'
             f"Full error traceback logged to file.\n\n" +
             "For support, please create an issue at https://github.com/spectacles-ci/spectacles/issues"
             + "\n")
         sys.exit(1)