Example #1
0
    def fn():
        with tempfile.TemporaryDirectory() as temp_dir:
            if os.path.exists("tmp"):
                for repository in [
                        f.name for f in os.scandir("tmp") if f.is_dir()
                ]:
                    shutil.copytree("tmp/" + repository,
                                    temp_dir + "/" + repository,
                                    symlinks=True)
            with cd(temp_dir):
                for step in task["steps"]:
                    # Load necessary execution plugin
                    plugin = importlib.import_module('execution.plugins.' +
                                                     step["plugin"])
                    # Set runtime directory properly for the step to execute
                    if "repository" in step and "path" in step:
                        with cd(step["repository"] + "/" + step["path"]):
                            result = execute_step(plugin.process, step,
                                                  context)
                    elif "repository" in step:
                        with cd(step["repository"]):
                            result = execute_step(plugin.process, step,
                                                  context)
                    else:
                        result = execute_step(plugin.process, step, context)

                    if (isinstance(result, bool) and
                            result is False) or (isinstance(result, dict)
                                                 and result["pass"] is False):
                        print("Step has broken execution - halting task")
                        break
Example #2
0
def initialize(task):
    for step in task["steps"]:
        plugin = importlib.import_module('execution.plugins.' + step["plugin"])
        if "params_from_context" in step and "params" not in step:
            step["params"] = {}
        if hasattr(plugin, "initialize") and callable(plugin.initialize):
            print(f"Initializing plugin {step['plugin']}")
            if "repository" in step and "path" in step and os.path.isdir(step["repository"] + "/" + step["path"]):
                with cd(step["repository"] + "/" + step["path"]):
                    plugin.initialize(step["params"])
            elif "repository" in step and os.path.isdir(step["repository"]):
                with cd(step["repository"]):
                    plugin.initialize(step["params"])
            else:
                plugin.initialize(step["params"])