container_guts.utils package

Submodules

container_guts.utils.fileio module

container_guts.utils.fileio.can_be_deleted(path, ignore_files=None)[source]

A path can be deleted if it contains no entries, or if the only files are in ignore_files

container_guts.utils.fileio.copyfile(source, destination, force=True)[source]

Copy a file from a source to its destination.

container_guts.utils.fileio.creation_date(filename)[source]

Get the creation date, and fallback to modified date.

container_guts.utils.fileio.get_file_hash(image_path, algorithm='sha256')[source]

Return an sha256 hash of the file based on a criteria level.

container_guts.utils.fileio.get_tmpdir(tmpdir=None, prefix='', create=True)[source]

Get a temporary directory for an operation.

container_guts.utils.fileio.get_tmpfile(tmpdir=None, prefix='')[source]

Get a temporary file with an optional prefix.

container_guts.utils.fileio.mkdir_p(path)[source]

Make a directory path if it does not exist, akin to mkdir -p

container_guts.utils.fileio.mkdirp(dirnames)[source]

Create one or more directories

container_guts.utils.fileio.print_json(json_obj)[source]

Print json pretty

container_guts.utils.fileio.read_file(filename, mode='r')[source]

Read a file.

container_guts.utils.fileio.read_json(filename, mode='r')[source]

Read a json file to a dictionary.

container_guts.utils.fileio.recursive_find(base, pattern=None)[source]

Find filenames that match a particular pattern, and yield them.

container_guts.utils.fileio.remove_to_base(path, base_path)[source]

Delete the tree under $path and all the parents up to $base_path as long as they are empty

container_guts.utils.fileio.write_file(filename, content, mode='w', exec=False)[source]

Write content to a filename

container_guts.utils.fileio.write_json(json_obj, filename, mode='w')[source]

Write json to a filename

container_guts.utils.terminal module

container_guts.utils.terminal.confirm_action(question, force=False)[source]

confirm if the user wants to perform a certain action

Parameters

question: the question that will be asked force: if the user wants to skip the prompt

container_guts.utils.terminal.ensure_no_extra(extra)[source]

Ensure no extra arguments (in case typos)

container_guts.utils.terminal.get_installdir()[source]
container_guts.utils.terminal.get_userhome()[source]

Get the user home based on the effective uid.

container_guts.utils.terminal.run_command(cmd, sudo=False, stream=False)[source]

run_command uses subprocess to send a command to the terminal.

Parameters

cmd: the command to send, should be a list for subprocess error_message: the error message to give to user if fails, if none specified, will alert that command failed.

Module contents