Kabira  K
Kabira K

Reputation: 2007

In python doit how to run task only when some condition is met

Something really simple I want to achieve with python doit module. I have task_entry and three other tasks: task_a, task_b, task_c. I want to control from task_entry which of the either tasks a, b, or c to get evaluated. Lets say there is a config file from which task entry finds out which among a, b, c to execute. I am not able to express this simple requirement in doit framework. file_dep only controls the order of execution and not if a task is selected at all. Below is the MWE:

# dodo.py
import configparser

config = configparser.ConfigParser()
config.read("config.ini")

def choose_task():
    task_to_run = config.get("config", "task_to_run")
    return {"task_dep": [task_to_run]}

def task_entry():
    return {
        "actions": None,
        "calc_dep": choose_task,
    }

def task_a():
    return {
        "actions": ["echo 'Task A'"],
    }

def task_b():
    return {
        "actions": ["echo 'Task B'"],
    }

def task_c():
    return {
        "actions": ["echo 'Task C'"],
    }

Currently all tasks, A, B, and C will run. I will like only the task specified in config file to run.

Upvotes: -1

Views: 206

Answers (1)

Kabira  K
Kabira K

Reputation: 2007

I figured how to solve this. Need to use DOIT_CONFIG to define the default_tasks so that only entry task runs. The calc_dep task will make sure that right task gets picked up as part of dependency.

Upvotes: 0

Related Questions