sos.archive — Archive Interface

class sos.archive.Archive[source]

Bases: object

Abstract base class for archives.

add_binary(content, dest)[source]
add_dir(path)[source]
add_file(src, dest=None, force=False)[source]
add_link(source, link_name)[source]
add_node(path, mode, device)[source]
add_string(content, dest, mode='w')[source]
classmethod archive_type()[source]

Returns the archive class’s name as a string.

cleanup()[source]

Clean up any temporary resources used by an Archive class.

finalize(method)[source]

Finalize an archive object via method. This may involve creating An archive that is subsequently compressed or simply closing an archive that supports in-line handling. If method is automatic then the following methods are tried in order: xz, gzip

get_archive_path()[source]

Return a string representing the path to the temporary archive. For archive classes that implement in-line handling this will be the archive file itself. Archives that use a directory based cache prior to packaging should return the path to the temporary directory where the report content is located

get_tmp_dir()[source]

Return a temporary directory that clients of the archive may use to write content to. The content of the path is guaranteed to be included in the generated archive.

log = <Logger sos (WARNING)>
log_debug(msg)[source]
log_error(msg)[source]
log_info(msg)[source]
log_warn(msg)[source]
name()[source]
name_max()[source]

Return the maximum file name length this archive can support. This is the lesser of the name length limit of the archive format and any temporary file system based cache.

set_debug(debug)[source]
class sos.archive.FileCacheArchive(name, tmpdir, policy, threads, enc_opts, sysroot, manifest=None)[source]

Bases: Archive

Abstract superclass for archive types that use a temporary cache directory in the file system.

add_binary(content, dest)[source]
add_dir(path)[source]

Create a directory in the archive.

Parameters:

path – the path in the host file system to add

add_file(src, dest=None, force=False)[source]
add_final_manifest_data(method)[source]

Adds component-agnostic data to the manifest so that individual SoSComponents do not need to redundantly add these manually

add_link(source, link_name)[source]
add_node(path, mode, device)[source]
add_string(content, dest, mode='w')[source]
check_path(src, path_type, dest=None, force=False)[source]

Check a new destination path in the archive.

Since it is possible for multiple plugins to collect the same paths, and since plugins can now run concurrently, it is possible for two threads to race in archive methods: historically the archive class only needed to test for the actual presence of a path, since it was impossible for another Archive client to enter the class while another method invocation was being dispatched.

Deal with this by implementing a locking scheme for operations that modify the path structure of the archive, and by testing explicitly for conflicts with any existing content at the specified destination path.

It is not an error to attempt to create a path that already exists in the archive so long as the type of the object to be added matches the type of object already found at the path.

It is an error to attempt to re-create an existing path with a different path type (for example, creating a symbolic link at a path already occupied by a regular file).

Parameters:
  • src – the source path to be copied to the archive

  • path_type – the type of object to be copied

  • dest – an optional destination path

  • force – force file creation even if the path exists

Returns:

An absolute destination path if the path should be copied now or None otherwise

cleanup()[source]

Clean up any temporary resources used by an Archive class.

dest_path(name)[source]
do_file_sub(path, regexp, subst)[source]

Apply a regexp substitution to a file in the archive.

Parameters:
  • path (str) – Path in the archive where the file can be found

  • regexp (str or compiled re object) – A regex to match the contents of the file

  • subst (str) – The substitution string to be used to replace matches within the file

Returns:

Number of replacements made

Return type:

int

finalize(method)[source]

Finalize an archive object via method. This may involve creating An archive that is subsequently compressed or simply closing an archive that supports in-line handling. If method is automatic then the following methods are tried in order: xz, gzip

get_archive_path()[source]

Return a string representing the path to the temporary archive. For archive classes that implement in-line handling this will be the archive file itself. Archives that use a directory based cache prior to packaging should return the path to the temporary directory where the report content is located

get_tmp_dir()[source]

Return a temporary directory that clients of the archive may use to write content to. The content of the path is guaranteed to be included in the generated archive.

join_sysroot(path)[source]
makedirs(path, mode=448)[source]

Create path, including leading components.

Used by sos.sosreport to set up sos_* directories.

name_max()[source]

Return the maximum file name length this archive can support. This is the lesser of the name length limit of the archive format and any temporary file system based cache.

open_file(path)[source]
rename_archive_root(cleaner)[source]

Rename the archive to an obfuscated version using an initialized SoSCleaner instance

class sos.archive.TarFileArchive(name, tmpdir, policy, threads, enc_opts, sysroot, manifest=None)[source]

Bases: FileCacheArchive

archive class using python TarFile to create tar archives

copy_permissions_filter(tarinfo)[source]
get_selinux_context(path)[source]
method = None
name()[source]
set_tarinfo_from_stat(tar_info, fstat, mode=None)[source]
class sos.archive.Archive[source]

Abstract base class for archives.

add_binary(content, dest)[source]
add_dir(path)[source]
add_file(src, dest=None, force=False)[source]
add_node(path, mode, device)[source]
add_string(content, dest, mode='w')[source]
classmethod archive_type()[source]

Returns the archive class’s name as a string.

cleanup()[source]

Clean up any temporary resources used by an Archive class.

finalize(method)[source]

Finalize an archive object via method. This may involve creating An archive that is subsequently compressed or simply closing an archive that supports in-line handling. If method is automatic then the following methods are tried in order: xz, gzip

get_archive_path()[source]

Return a string representing the path to the temporary archive. For archive classes that implement in-line handling this will be the archive file itself. Archives that use a directory based cache prior to packaging should return the path to the temporary directory where the report content is located

get_tmp_dir()[source]

Return a temporary directory that clients of the archive may use to write content to. The content of the path is guaranteed to be included in the generated archive.

log = <Logger sos (WARNING)>
log_debug(msg)[source]
log_error(msg)[source]
log_info(msg)[source]
log_warn(msg)[source]
name()[source]
name_max()[source]

Return the maximum file name length this archive can support. This is the lesser of the name length limit of the archive format and any temporary file system based cache.

set_debug(debug)[source]
class sos.archive.FileCacheArchive(name, tmpdir, policy, threads, enc_opts, sysroot, manifest=None)[source]

Abstract superclass for archive types that use a temporary cache directory in the file system.

add_binary(content, dest)[source]
add_dir(path)[source]

Create a directory in the archive.

Parameters:

path – the path in the host file system to add

add_file(src, dest=None, force=False)[source]
add_final_manifest_data(method)[source]

Adds component-agnostic data to the manifest so that individual SoSComponents do not need to redundantly add these manually

add_node(path, mode, device)[source]
add_string(content, dest, mode='w')[source]
check_path(src, path_type, dest=None, force=False)[source]

Check a new destination path in the archive.

Since it is possible for multiple plugins to collect the same paths, and since plugins can now run concurrently, it is possible for two threads to race in archive methods: historically the archive class only needed to test for the actual presence of a path, since it was impossible for another Archive client to enter the class while another method invocation was being dispatched.

Deal with this by implementing a locking scheme for operations that modify the path structure of the archive, and by testing explicitly for conflicts with any existing content at the specified destination path.

It is not an error to attempt to create a path that already exists in the archive so long as the type of the object to be added matches the type of object already found at the path.

It is an error to attempt to re-create an existing path with a different path type (for example, creating a symbolic link at a path already occupied by a regular file).

Parameters:
  • src – the source path to be copied to the archive

  • path_type – the type of object to be copied

  • dest – an optional destination path

  • force – force file creation even if the path exists

Returns:

An absolute destination path if the path should be copied now or None otherwise

cleanup()[source]

Clean up any temporary resources used by an Archive class.

dest_path(name)[source]
do_file_sub(path, regexp, subst)[source]

Apply a regexp substitution to a file in the archive.

Parameters:
  • path (str) – Path in the archive where the file can be found

  • regexp (str or compiled re object) – A regex to match the contents of the file

  • subst (str) – The substitution string to be used to replace matches within the file

Returns:

Number of replacements made

Return type:

int

finalize(method)[source]

Finalize an archive object via method. This may involve creating An archive that is subsequently compressed or simply closing an archive that supports in-line handling. If method is automatic then the following methods are tried in order: xz, gzip

get_archive_path()[source]

Return a string representing the path to the temporary archive. For archive classes that implement in-line handling this will be the archive file itself. Archives that use a directory based cache prior to packaging should return the path to the temporary directory where the report content is located

get_tmp_dir()[source]

Return a temporary directory that clients of the archive may use to write content to. The content of the path is guaranteed to be included in the generated archive.

join_sysroot(path)[source]
makedirs(path, mode=448)[source]

Create path, including leading components.

Used by sos.sosreport to set up sos_* directories.

name_max()[source]

Return the maximum file name length this archive can support. This is the lesser of the name length limit of the archive format and any temporary file system based cache.

open_file(path)[source]
rename_archive_root(cleaner)[source]

Rename the archive to an obfuscated version using an initialized SoSCleaner instance