tunel.utils package

Submodules

tunel.utils.fileio module

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

Copy a file from a source to its destination.

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

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

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

Get a temporary directory for an operation.

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

Get a temporary file with an optional prefix.

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

mkdir_p attempts to get the same functionality as mkdir -p :param path: the path to create.

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

Create one or more directories

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

Print json pretty

tunel.utils.fileio.read_config_file(filename, sep='=')[source]

Given a config file with format KEY = VALUE, parse into dict

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

Read a file.

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

Read a json file to a dictionary.

tunel.utils.fileio.read_lines(filename)[source]

Given a file with multple lines, read into a list

tunel.utils.fileio.read_yaml(filename)[source]

Read yaml from file

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

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

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

Write content to a filename

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

Write json to a filename

tunel.utils.generate module

class tunel.utils.generate.RobotNamer[source]

Bases: object

generate(delim='-', length=4, chars='0123456789')[source]
Generate a robot name. Inspiration from Haikunator, but much more

poorly implemented ;)

tunel.utils.terminal module

tunel.utils.terminal.check_install(software, quiet=True, command='--version')[source]

check_install will attempt to run the singularity command, and return True if installed. The command line utils will not run without this check.

Parameters:
  • software (the software to check if installed) –

  • quiet (should we be quiet? (default True)) –

  • command (the command to use to check (defaults to --version)) –

tunel.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) –

tunel.utils.terminal.confirm_uninstall(filename, force=False)[source]

confirm if the user wants to uninstall a module

Parameters:
  • filename (the file that will be removed) –

  • force (if the user wants to skip the prompt) –

tunel.utils.terminal.get_installdir()[source]

get_installdir returns the installation directory of the application

tunel.utils.terminal.run_command(cmd, stream=False, quiet=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,) –

  • failed. (if none specified, will alert that command) –

tunel.utils.terminal.which(software, strip_newline=True)[source]

get_install will return the path to where an executable is installed.

Module contents