Exemplo n.º 1
0
def check_output_runner(cmd, stderr=None):
    # Used to run several utilities, like Pacman detect, AIX version, uname, SCM
    tmp_file = tempfile.mktemp()
    try:
        # We don't want stderr to print warnings that will mess the pristine outputs
        stderr = stderr or subprocess.PIPE
        cmd = cmd if isinstance(
            cmd, six.string_types) else subprocess.list2cmdline(cmd)
        command = "{} > {}".format(cmd, tmp_file)
        logger.info("Calling command: {}".format(command))
        process = subprocess.Popen(command, shell=True, stderr=stderr)
        stdout, stderr = process.communicate()
        logger.info("Return code: {}".format(int(process.returncode)))

        if process.returncode:
            # Only in case of error, we print also the stderr to know what happened
            raise CalledProcessErrorWithStderr(process.returncode,
                                               cmd,
                                               output=stderr)

        output = load(tmp_file)
        try:
            logger.info("Output: in file:{}\nstdout: {}\nstderr:{}".format(
                output, stdout, stderr))
        except Exception as exc:
            logger.error("Error logging command output: {}".format(exc))
        return output
    finally:
        try:
            os.unlink(tmp_file)
        except OSError:
            pass
Exemplo n.º 2
0
Arquivo: oss.py Projeto: theirix/conan
def check_output(cmd, folder=None, return_code=False, stderr=None):
    tmp_file = tempfile.mktemp()
    try:
        # We don't want stderr to print warnings that will mess the pristine outputs
        stderr = stderr or PIPE
        cmd = cmd if isinstance(
            cmd, six.string_types) else subprocess.list2cmdline(cmd)
        process = subprocess.Popen("{} > {}".format(cmd, tmp_file),
                                   shell=True,
                                   stderr=stderr,
                                   cwd=folder)

        _, stderr = process.communicate()

        if return_code:
            return process.returncode

        if process.returncode:
            # Only in case of error, we print also the stderr to know what happened
            raise CalledProcessErrorWithStderr(process.returncode,
                                               cmd,
                                               output=stderr)

        output = load(tmp_file)
        return output
    finally:
        try:
            os.unlink(tmp_file)
        except Exception:
            pass
Exemplo n.º 3
0
def check_output(cmd, folder=None, return_code=False, stderr=None):
    tmp_file = tempfile.mktemp()
    try:
        stderr = stderr or PIPE
        cmd = cmd if isinstance(
            cmd, six.string_types) else subprocess.list2cmdline(cmd)
        process = subprocess.Popen("{} > {}".format(cmd, tmp_file),
                                   shell=True,
                                   stderr=stderr,
                                   cwd=folder)
        process.communicate()

        if return_code:
            return process.returncode

        if process.returncode:
            raise CalledProcessError(process.returncode, cmd)

        output = load(tmp_file)
        return output
    finally:
        try:
            os.unlink(tmp_file)
        except Exception:
            pass
Exemplo n.º 4
0
Arquivo: oss.py Projeto: yochju/conan
def check_output(cmd, folder=None, return_code=False):
    tmp_file = tempfile.mktemp()
    try:
        process = subprocess.Popen("{} > {}".format(cmd, tmp_file),
                                   shell=True,
                                   stderr=PIPE,
                                   cwd=folder)
        process.communicate()

        if return_code:
            return process.returncode

        if process.returncode:
            raise CalledProcessError(process.returncode, cmd)

        output = load(tmp_file)
        return output
    finally:
        try:
            os.unlink(tmp_file)
        except:
            pass
Exemplo n.º 5
0
def check_output(cmd, folder=None, return_code=False, stderr=None):
    tmp_file = tempfile.mktemp()
    try:
        # We don't want stderr to print warnings that will mess the pristine outputs
        stderr = stderr or PIPE
        cmd = cmd if isinstance(
            cmd, six.string_types) else subprocess.list2cmdline(cmd)
        command = "{} > {}".format(cmd, tmp_file)
        logger.info("Calling command: {}".format(command))
        process = subprocess.Popen(command,
                                   shell=True,
                                   stderr=stderr,
                                   cwd=folder)
        stdout, stderr = process.communicate()
        logger.info("Return code: {}".format(int(process.returncode)))

        if return_code:
            return process.returncode

        if process.returncode:
            # Only in case of error, we print also the stderr to know what happened
            raise CalledProcessErrorWithStderr(process.returncode,
                                               cmd,
                                               output=stderr)

        output = load(tmp_file)
        try:
            logger.info("Output: in file:{}\nstdout: {}\nstderr:{}".format(
                output, stdout, stderr))
        except Exception as exc:
            logger.error("Error logging command output: {}".format(exc))
        return output
    finally:
        try:
            os.unlink(tmp_file)
        except Exception:
            pass
Exemplo n.º 6
0
 def get_cpu_period(self):
     return int(load("/sys/fs/cgroup/cpu/cpu.cfs_period_us"))
Exemplo n.º 7
0
 def get_cpu_quota(self):
     return int(load("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"))