qme.main.executor package

Submodules

qme.main.executor.base module

Copyright (C) 2020 Vanessa Sochat.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

class qme.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 qme.main.executor.base.ExecutorBase(taskid)[source]

Bases: object

A qme executor exists to translate a terminal command into a parsed job (shown in the dashboard) and expose one or more actions for it. The base executor will work for any generic command, generates status based on return codes, and exposes basic options to cancel (kill) or re-run.

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
execute(cmd=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_actions()[source]

return list of actions to expose

get_error()[source]
get_output()[source]
get_setting(key, default=None)[source]

Get a setting, meaning that we first check the environment, then the config file, and then (if provided) a default.

name = 'base'
run_action(name, data, **kwargs)[source]

Check for a named action in the executors list. This is called from the queue that can also add the data for the task as “data.” The user should be able to run an action by name, e.g., executor.action(‘status’, data) and take key word arguments, which is exposed by a task as task.run_action(‘status’, data)

summary()[source]

qme.main.executor.shell module

Copyright (C) 2020 Vanessa Sochat.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

class qme.main.executor.shell.ShellExecutor(taskid=None, command=None)[source]

Bases: qme.main.executor.base.ExecutorBase

A shell executor is the most basic of executors to run some shell command. We use the default functions provided by the BaseExecutor class to store the command, run, get the return code, and retry.

property command
decode(line)[source]

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

execute(cmd=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 :rtype: str

get_output()[source]

Returns the output from shell command :rtype: str

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

refresh output and error streams

set_command(cmd)[source]

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]

Module contents

Copyright (C) 2020 Vanessa Sochat.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

qme.main.executor.get_executor(command=None, config=None)[source]

get executor will return the correct executor depending on a command (or other string) matching a regular expression. If nothing matches, we default to a shell executor. Each non-shell executor should expose a common “matches” function (provided by the base class) that will handle parsing the command (a list) to a single string, and checking if it matches a regular expression.

qme.main.executor.get_named_executor(name, taskid=None, config=None)[source]

get a named executor, meaning determining based on name and not command

qme.main.executor.matches(Executor, command)[source]

Given a command, determine if it matches the regular expression that determines to use the executor or not. This applies to all executors except for the shell executor. This means that all non-shell classes need to have a matchstring defined.