sos.utilities — Utilites Interface

class sos.utilities.AsyncReader(channel, sizelimit, binary)[source]

Bases: threading.Thread

Used to limit command output to a given size without deadlocking sos.

Takes a sizelimit value in MB, and will compile stdout from Popen into a string that is limited to the given sizelimit.

get_contents()[source]

Returns the contents of the deque as a string

is_full

Checks if the deque is full, implying that output was truncated

run()[source]

Reads from the channel (pipe) that is the output pipe for a called Popen. As we are reading from the pipe, the output is added to a deque. After the size of the deque exceeds the sizelimit earlier (older) entries are removed.

This means the returned output is chunksize-sensitive, but is not really byte-sensitive.

class sos.utilities.ImporterHelper(package)[source]

Bases: object

Provides a list of modules that can be imported in a package. Importable modules are located along the module __path__ list and modules are files that end in .py.

get_modules()[source]

Returns the list of importable modules in the configured python package.

exception sos.utilities.SoSTimeoutError[source]

Bases: OSError

class sos.utilities.TempFileUtil(tmp_dir)[source]

Bases: object

clean()[source]
new()[source]
sos.utilities.convert_bytes(bytes_, K=1024, M=1048576, G=1073741824, T=1099511627776)[source]

Converts a number of bytes to a shorter, more human friendly format

sos.utilities.fileobj(path_or_file, mode='r')[source]

Returns a file-like object that can be used as a context manager

sos.utilities.find(file_pattern, top_dir, max_depth=None, path_pattern=None)[source]

Generator function to find files recursively. Usage:

for filename in find("*.properties", "/var/log/foobar"):
    print filename
sos.utilities.get_human_readable(size, precision=2)[source]
sos.utilities.grep(pattern, *files_or_paths)[source]

Returns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by line

sos.utilities.import_module(module_fqname, superclasses=None)[source]

Imports the module module_fqname and returns a list of defined classes from that module. If superclasses is defined then the classes returned will be subclasses of the specified superclass or superclasses. If superclasses is plural it must be a tuple of classes.

sos.utilities.is_executable(command)[source]

Returns if a command matches an executable on the PATH

sos.utilities.listdir(path, sysroot)[source]
sos.utilities.path_exists(path, sysroot)[source]
sos.utilities.path_isdir(path, sysroot)[source]
sos.utilities.path_isfile(path, sysroot)[source]
sos.utilities.path_islink(path, sysroot)[source]
sos.utilities.shell_out(cmd, timeout=30, chroot=None, runat=None)[source]

Shell out to an external command and return the output or the empty string in case of error.

sos.utilities.sos_get_command_output(command, timeout=300, stderr=False, chroot=None, chdir=None, env=None, foreground=False, binary=False, sizelimit=None, poller=None)[source]

Execute a command and return a dictionary of status and output, optionally changing root or current working directory before executing command.

sos.utilities.tail(filename, number_of_bytes)[source]

Returns the last number_of_bytes of filename