Exemplo n.º 1
0
def print_step_fail(step: Step, reason: str) -> None:
    """
    Print a diagnostic message to the console when a step failed.
    
    Parameters
    ----------
    step : Step
        Step that caused the fail.
    """
    if reason is None or reason is "":
        reason = ""

    console.error(f"{ICON_ERR} Step '{step.name}' failed! {reason}")
Exemplo n.º 2
0
def save_fruit_env(paths: List[str]) -> None:
    """
    Save the environmental variable FRUITPATH from the list of pathes. The saved variable will
    be a  ';' separated list.

    Parameters
    ----------
    paths : List[str]
        List of pathes
    """
    try:
        with open(DOT_FRUITPATH, 'w') as fp:
            fp.writelines(paths)
    except Exception as exc:
        console.error("The environmental variable FRUITPATH cannot be modified!")
        console.error(f"Reason: {str(exc)}")
Exemplo n.º 3
0
def load_fruit_env() -> List[str]:
    """
    Load the environment variable `fruitpath` and parse it into an array of strings.
    The environment variable has to be separated via ';'.

    Returns
    -------
    List[str]:
      List of pathes added by the user. For invalid environment variables an empty array will be added.
    """
    try:
        with open(DOT_FRUITPATH, 'r') as fp:
            pathlist = fp.readlines()
        return pathlist
    except Exception as exc:
        console.error(f"The environmental variable FRUITPATH cannot be loaded!")
        console.error(f"Reason {str(exc)}")
        return []
Exemplo n.º 4
0
def drop_path(path: str):
    """
    Remove an already 'picked-up' path from the global FRUITPATH.

    Parameters
    ----------
    path : str
        Path to remove. May be relative or absolute
    """
    abspath = os.path.abspath(path)
    pathlist = load_fruit_env()

    try:
        pathlist.remove(abspath)
        save_fruit_env(pathlist)
        console.echo(f"{abspath} was dropped!")
    except Exception as exc:
        console.error(f"The path {abspath} cannot be removed!")
        console.error(f"Reason: {str(exc)}")
Exemplo n.º 5
0
def print_summary_abort(last_target: Target, steps: List[Step]) -> None:
    """
    Print the summarized results of an aborted target as a table to the console. 
    All run steps & substeps and targets will be summarized.

    Parameters
    ----------

    last_target : Target
        Target that the summary belonds to

    steps : List[Step]
        List of executed steps
    """
    table = []
    for each_step in steps:
        # Determine the status icon
        if each_step.status == STATUS_OK:
            icon = ICON_OK
            status = "OK"
        elif each_step.status == STATUS_SKIPPED:
            icon = ICON_SKIP
            status = "Skipped"
        elif each_step.status == STATUS_ERR:
            icon = ICON_ERR
            status = "Failed"
        else:
            icon = ICON_UNKNOWN
            status = "Unknown"

        name = each_step.fullname
        xtime = "%.3f" % each_step.time
        table.append((icon, status, xtime, name))

    console.echo()
    console.echo(f"Summary of target '{last_target.name}':")
    console.echo()
    console.echo(
        tabulate.tabulate(table, headers=('', 'Status', 'Time', 'Name')))

    console.error(f"{ICON_ERR} Target '{last_target.name}' was unsuccessful!")
Exemplo n.º 6
0
 def make_multiple(self, *targets):
     """
     Make every listed target. When a target is not found the make process will be
     aborted.
     """
     try:
         # Call the make command on each passed target
         for each_targetname in targets:
             self.make_target(each_targetname)
     except AbortStepSignal as aerr:
         console.error("The make process was aborted! Reason: {}".format(
             str(aerr)))
         # Try to print the summary
         printing.print_summary_abort(self.__target_stack[0], self.__steps)
     except SkipStepSignal:
         console.error(
             "fruit.skip() may only be called from inside of a step!")
     except FailStepSignal:
         console.error(
             "fruit.fail() may only be called from inside of a step!")