ohno package

Submodules

ohno.exceptions module

exception ohno.exceptions.DirectoryNotFoundError(dirname, reason, *args, **kwargs)[source]

Bases: FileNotFoundError

Thrown if a directory is not found

exception ohno.exceptions.MissingEnvironmentVariable(varname, *args, **kwargs)[source]

Bases: RuntimeError

Thrown if a required environment variable is not provided.

exception ohno.exceptions.MissingImportError(name, reason, *args, **kwargs)[source]

Bases: ImportError

Thrown if a library is missing.

exception ohno.exceptions.NotSupportedError(reason, *args, **kwargs)[source]

Bases: NotImplementedError

Thrown if functionality isn’t supported, and not implemented.

exception ohno.exceptions.OutputParsingError(reason='', *args, **kwargs)[source]

Bases: ValueError

Thrown if an output cannot be correctly parsed

exception ohno.exceptions.UnrecognizedTargetError(name, reason='', *args, **kwargs)[source]

Bases: ValueError

Thrown if an unrecognized target is given for an action

ohno.version module

ohno.logger module

class ohno.logger.ColorizingStreamHandler(nocolor=False, stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, use_threads=False)[source]

Bases: logging.StreamHandler

BLACK = 0
BLUE = 4
BOLD_SEQ = '\x1b[1m'
COLOR_SEQ = '\x1b[%dm'
CYAN = 6
GREEN = 2
MAGENTA = 5
RED = 1
RESET_SEQ = '\x1b[0m'
WHITE = 7
YELLOW = 3
can_color_tty()[source]
colors = {'CRITICAL': 1, 'DEBUG': 4, 'ERROR': 1, 'INFO': 2, 'WARNING': 3}
decorate(record)[source]
emit(record)[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

property is_tty
class ohno.logger.Logger[source]

Bases: object

cleanup()[source]
debug(msg)[source]
error(msg)[source]
exit(msg, return_code=1)[source]
handler(msg)[source]
info(msg)[source]
location(msg)[source]
progress(done=None, total=None)[source]
set_level(level)[source]
set_stream_handler(stream_handler)[source]
shellcmd(msg)[source]
text_handler(msg)[source]

The default snakemake log handler. Prints the output to the console. :param msg: the log message dictionary :type msg: dict

warning(msg)[source]
ohno.logger.setup_logger(quiet=False, printshellcmds=False, nocolor=False, stdout=False, debug=False, use_threads=False, wms_monitor=None)[source]

ohno.utils module

ohno.utils.fileio module

ohno.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

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

Copy a file from a source to its destination.

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

Get the creation date, and fallback to modified date.

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

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

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

Get a temporary directory for an operation.

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

Get a temporary file with an optional prefix.

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

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

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

Create one or more directories

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

Print json pretty

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

Read a file.

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

Read a json file to a dictionary.

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

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

ohno.utils.fileio.rmdir_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

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

Write content to a filename

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

Write json to a filename

ohno.utils.terminal module

ohno.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)) –
ohno.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) –
ohno.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) –
ohno.utils.terminal.get_installdir()[source]

get_installdir returns the installation directory of the application

ohno.utils.terminal.get_user()[source]

Get the name of the user. We first try to import pwd, but fallback to extraction from the environment.

ohno.utils.terminal.get_userhome()[source]

get the user home based on the effective uid. If import of pwd fails (not supported for Windows) then fall back to environment variable.

ohno.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,) –
  • failed. (if none specified, will alert that command) –
ohno.utils.terminal.which(software=None, strip_newline=True)[source]

get_install will return the path to where Singularity (or another executable) is installed.

ohno.main module

ohno.main.client module

class ohno.main.client.Monitor[source]

Bases: object

Monitor a running process, collecting the output and parsing for errors.

We also parse those errors and return to the user in a useful format for submitting a bug report.

load(logfile)[source]

Parse a logfile and return the result.

run(command, message=None)[source]

Given a command, run it and capture (and parse) errors.

ohno.main.result module

class ohno.main.result.MarkdownResult(**kwargs)[source]

Bases: ohno.main.result.Result

parse()[source]
class ohno.main.result.Result(**kwargs)[source]

Bases: object

A base result handles parsing a command run.

property command
to_dict()[source]

ohno.main.executor module

ohno.main.executor.base module

class ohno.main.executor.base.Capturing[source]

Bases: object

capture output from stdout and stderr into capture object. This is based off of github.com/vsoch/gridtest but modified to write files. The stderr and stdout are set to temporary files at the init of the capture, and then they are closed when we exit. This means expected usage looks like:

with Capturing() as capture:
process = subprocess.Popen(…)

And then the output and error are retrieved from reading the files: and exposed as properties to the client:

capture.out capture.err

And cleanup means deleting these files, if they exist.

cleanup()[source]
property err

Return error stream. Returns empty string if empty or doesn’t exist. Returns (str) : error stream written to file

property out

Return output stream. Returns empty string if empty or doesn’t exist. Returns (str) : output stream written to file

set_stderr()[source]
set_stdout()[source]
class ohno.main.executor.base.ExecutorBase[source]

Bases: object

capture(cmd)[source]

capture is a helper function to capture a shell command. We use Capturing and then save attributes like the pid, output, error to it, and return to the calling function. For example:

capture = self.capture_command(cmd) self.pid = capture.pid self.returncode = capture.returncode self.out = capture.output self.err = capture.error

property command
decode(line)[source]

Given a line of output (error or regular) decode using the system default, if appropriate

execute(cmd=None, message=None)[source]
export()[source]

return data as json. This is intended to save to the task database. Any important executor specific metadata should be added to self.data

get_error()[source]
get_output()[source]
name = 'base'
summary()[source]

ohno.main.executor.shell module

class ohno.main.executor.shell.ShellExecutor(command=None)[source]

Bases: ohno.main.executor.base.ExecutorBase

Run a shell command and capture output.

property command
execute(cmd=None, message=None)[source]

Execute a system command and return output and error.

Execute should take a cmd (a string or list) and execute it according to the executor. Attributes should be set on the class that are added to self.export. Since the functions here are likely needed by most executors, we create a self._execute() class that is called instead, and can be used by the other executors.

get_error()[source]

Returns the error from shell command

get_output()[source]

Returns the output from shell command

name = 'shell'
reset(command=None)[source]

refresh output and error streams

set_command(cmd)[source]

Parse a newly provided command.

parse is called when a new command is provided to ensure we have a list. We don’t check that the executable is on the path, as the initialization might not occur in the runtime environment.

summary()[source]

ohno.client module

ohno.client.get_parser()[source]
ohno.client.main()[source]