Just doit

Who?

Installation

pip install doit

Source

http://bitbucket.org/schettino72/doit

dodo.py

def task_hello_pyugrm():
    return {
        'actions': ['echo "Hallo Trollhoehle"'],
    }

$ doit
.  hello_pyugrm

dodo-1.py

def task_hello_pyugrm():
    def say_hello():
        print("Hallo Trollhoehle")

    return {
        'actions': [say_hello],
    }

def task_hello_pyugrm2():
    def say_hello(who, **kwargs):
        print("Hallo {}".format(who))

    return {
        'basename': 'hello_again',
        'actions': [(say_hello, ("Trollhoehle", ), )],
    }

$ doit -f dodo-1.py
.  hello_pyugrm
.  hello_again

$ doit list -f dodo-1.py
hello_pyugrm
hello_again

$ doit -f dodo-1.py hello_again
.  hello_again

Default Tasks

dodo-1-default_tasks.py

DOIT_CONFIG = {
    'default_tasks': ['hello_again']
}

def task_hello_pyugrm():
    def say_hello():
        print("Hallo Trollhoehle")

    return {
        'actions': [say_hello],
    }


def task_hello_pyugrm2():
    def say_hello(who, **kwargs):
        print("Hallo {}".format(who))

    return {
        'basename': 'hello_again',
        'actions': [(say_hello, ("Trollhoehle", ), )],
    }
$ doit -f dodo-1-default_tasks.py 
.  hello_again

Verbosity

$ doit --verbosity 2
.  hello_pyugrm
Hallo Trollhoehle

dodo-2.py

def task_hello_pyugrm():
    return {
        'actions': ['echo "Hallo Trollhoehle"'],
        'verbosity': 2,
    }
$ doit -f dodo-2.py
.  hello_pyugrm
Hallo Trollhoehle

File Dependencies

Linux/Mac: inotify Support

def task_show_greeting():
    return {
        'actions': ['cat greeting'],
        'verbosity': 2,
        'file_dep': ['greeting'],
    }
$ echo "Hallo Trollhoehle" > greeting
$ doit -f dodo-3.py
.  show_greeting
Hallo Trollhoehle
$ doit -f dodo-3.py
-- show_greeting

Forgetting Run Status

$ doit -f dodo-3.py
-- show_greeting
$ doit forget
forgeting all tasks
$ doit -f dodo-3.py
.  show_greeting
Hallo Trollhoehle

Targets

dodo-4.py

def task_hello_pyugrm():
    return {
        'actions': ['echo "Hallo Trollhoehle" > greeting'],
        'targets': ['greeting']
    }

def task_show_greeting():
    return {
        'actions': ['cat greeting'],
        'verbosity': 2,
        'file_dep': ['greeting'],
    }
$ doit -f dodo-4.py
.  hello_pyugrm
.  show_greeting
Hallo Trollhoehle
$ doit -f dodo-4.py
.  hello_pyugrm
-- show_greeting

Task Dependencies

dodo-5.py

def task_setup_environment():
    return {
        'actions': ['echo "Done"'],
        'task_dep': ['install_tools']
    }

def task_install_tools():
    return {
        'actions': ['pip install --upgrade flake8']
    }
$ doit -f dodo-5.py
.  install_tools
.  setup_environment

Task Groups

dodo-6.py

def task_setup_environment():
    return {
        'actions': None,
        'task_dep': ['install_tools']
    }


def task_install_tools():
    return {
        'actions': ['pip install --upgrade flake8']
    }
$ doit -f dodo-6.py
.  install_tools

Up-to-date Tasks

dodo-7.py

from doit.tools import run_once

def task_setup_environment():
    return {
        'actions': None,
        'task_dep': ['install_tools']
    }

def task_install_tools():
    return {
        'actions': ['pip install --upgrade flake8'],
        'uptodate': [run_once]
    }
$ doit -f dodo-7.py
.  install_tools
$ doit -f dodo-7.py
-- install_tools

More Up-to-date

Flake8 Runner

import os
from doit.tools import run_once

DOIT_CONFIG = {
    'continue': True
}

def task_run_flake8():
    for filename in os.listdir('.'):
        if filename.endswith('.py'):
            yield {
                'name': filename,
                'actions': ['flake8 {}'.format(filename)],
                'file_dep': [filename],
                'verbosity': 2,
                'task_dep': ['install_flake8']
            }

def task_install_flake8():
    return {
        'actions': ['pip install flake8'],
        'uptodate': [run_once]
    }
$ doit -f dodo-flake8.py
.  install_flake8
.  run_flake8:dodo.py
.  run_flake8:dodo-flake8.py
.  run_flake8:dodo-7.py
.  run_flake8:dodo-4.py
.  run_flake8:flake8-non_conform_file-2.py
.  run_flake8:dodo-5.py
.  run_flake8:dodo-3.py
.  run_flake8:dodo-6.py
.  run_flake8:dodo-2.py
.  run_flake8:dodo-1.py
.  run_flake8:flake8-non_conform_file.py
########################################
TaskFailed - taskid:run_flake8:flake8-non_conform_file-2.py
Command failed: 'flake8 flake8-non_conform_file-2.py' returned 1

[a lot of flake8 messages]


########################################
TaskFailed - taskid:run_flake8:flake8-non_conform_file.py
Command failed: 'flake8 flake8-non_conform_file.py' returned 1

[a lot of flake8 messages]


########################################
UnmetDependency - taskid:run_flake8
run_flake8:flake8-non_conform_file-2.py run_flake8:flake8-non_conform_file.py
$ doit -f dodo-flake8.py
-- install_flake8
-- run_flake8:dodo.py
-- run_flake8:dodo-flake8.py
-- run_flake8:dodo-7.py
-- run_flake8:dodo-4.py
.  run_flake8:flake8-non_conform_file-2.py
-- run_flake8:dodo-5.py
-- run_flake8:dodo-3.py
-- run_flake8:dodo-6.py
-- run_flake8:dodo-2.py
-- run_flake8:dodo-1.py
.  run_flake8:flake8-non_conform_file.py
########################################
TaskFailed - taskid:run_flake8:flake8-non_conform_file-2.py
Command failed: 'flake8 flake8-non_conform_file-2.py' returned 1

[a lot of flake8 messages]


########################################
TaskFailed - taskid:run_flake8:flake8-non_conform_file.py
Command failed: 'flake8 flake8-non_conform_file.py' returned 1

[a lot of flake8 messages]


########################################
UnmetDependency - taskid:run_flake8
run_flake8:flake8-non_conform_file-2.py run_flake8:flake8-non_conform_file.py

doit auto

$ doit auto -f dodo-flake8.py

Interactive Actions

dodo-8.py

from doit.tools import InteractiveAction

def task_connect_ssh():
    return {
        'actions': [InteractiveAction('ssh niko@localhost')]
    }
$ doit -f dodo-9.py
.  connect_ssh
niko@localhost's password:

Parameters

dodo-9.py

from doit.tools import InteractiveAction

def task_connect_ssh():
    return {
        'actions': [InteractiveAction('ssh %(username)s@%(host)s')],
        'params': [{'name': 'username',
                    'long': 'username',
                    'short': 'u',
                    'default': 'niko',
                    'help': 'The username to use.'},
                   {'name': 'host',
                    'long': 'server',
                    'short': 's',
                    'default': 'localhost'}
                   ]
    }
$ doit help -f dodo-9.py connect_ssh
connect_ssh
  -u ARG, --username=ARG    The username to use.
  -s ARG, --server=ARG
$ doit -f dodo-9.py connect_ssh -u edward --server prism.nsa.gov
.  connect_ssh
edward@prism.nsa.gov's password:

More?

/

#