sos.utilities
— Utilites Interface¶
-
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.
-
-
sos.utilities.
convert_bytes
(bytes_, K=1024, M=1048576, G=1073741824, T=1099511627776L)[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.
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.
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)[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