Skip to content

Script

Class representing the sourcing of a script.

Script

Bases: Source

Script class for applying changes to the execution environment.

Source code in maestrowf/datastructures/environment/script.py
class Script(Source):
    """Script class for applying changes to the execution environment."""

    # TODO: Sourcing is an issue. We need to figure out a way to handle this.
    def __init__(self, source):
        """
        Initialize the Script class.

        :params source: The command for changing the execution environment.
        """
        self.source = source
        self._verification("Script initialized without complete settings. Set"
                           " source before calling methods.")

    def apply(self, cmds):
        """
        Apply the Script source to the specified list of commands.

        :param cmds: List of commands to add source to.
        :returns: List of commands with the source prepended.
        """
        return [self.source] + list(cmds)

    def _verify(self):
        """
        Verify the Script object's contents.

        :returns: True if the Script object is valid, False otherwise.
        """
        valid_param_pattern = re.compile(r"\w+")
        return bool(re.search(valid_param_pattern, self.source))

__init__(source)

Initialize the Script class.

Parameters:

Name Type Description Default
source

The command for changing the execution environment.

required
Source code in maestrowf/datastructures/environment/script.py
def __init__(self, source):
    """
    Initialize the Script class.

    :params source: The command for changing the execution environment.
    """
    self.source = source
    self._verification("Script initialized without complete settings. Set"
                       " source before calling methods.")

apply(cmds)

Apply the Script source to the specified list of commands.

Parameters:

Name Type Description Default
cmds

List of commands to add source to.

required

Returns:

Type Description

List of commands with the source prepended.

Source code in maestrowf/datastructures/environment/script.py
def apply(self, cmds):
    """
    Apply the Script source to the specified list of commands.

    :param cmds: List of commands to add source to.
    :returns: List of commands with the source prepended.
    """
    return [self.source] + list(cmds)