How to use the spython.logger.decodeUtf8String function in spython

To help you get started, we’ve selected a few spython 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 singularityhub / singularity-cli / spython / utils / terminal.py View on Github external
sudo_options: string or list of strings that will be passed as options to sudo
    """
    cmd = _process_sudo_cmd(cmd, sudo, sudo_options)

    stdout = None
    if capture:
        stdout = subprocess.PIPE

    # Use the parent stdout and stderr
    process = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=stdout)
    lines = []
    found_match = False

    for line in process.communicate():
        if line:
            line = decodeUtf8String(line)
            lines.append(line)
            if re.search(no_newline_regexp, line) and found_match:
                if not quiet:
                    sys.stdout.write(line)
                found_match = True
            else:
                if not quiet:
                    sys.stdout.write(line)
                    print(line.rstrip())
                found_match = False

    output = {"message": lines, "return_code": process.returncode}

    return output
github singularityhub / singularity-cli / spython / logger / message.py View on Github external
def write(self, stream, message):
        '''write will write a message to a stream,
        first checking the encoding
        '''
        stream.write(decodeUtf8String(message))
github singularityhub / singularity-cli / spython / main / base / logger.py View on Github external
def println(self, output, quiet=False):
    '''print will print the output, given that quiet is not True. This
       function also serves to convert output in bytes to utf-8

       Parameters
       ==========
       output: the string to print
       quiet: a runtime variable to over-ride the default.

    '''
    if not self.quiet and not quiet:
        print(decodeUtf8String(output))