utilities for use with doit

pip install dotils==0.1a



Utilities for use with doit.

dotils provides a group of functions and classes to help you automate your development process with doit. For the most part, this includes common file system tasks (file creation/deletion), but dotils also provides code to help with your build process.

It's perhaps best to show an example of how to use dotils.


"""Sample dodo file that shows how to use various aspects of dotils"""
import dotils

SAMPLE_FILE_NAME = './exampledir/'
SAMPLE_FILE_CONTENT = 'print "this is a test"'
SAMPLE_DIR_NAME = './exampledir'

def task_make_dir():
    """Sample task showing the use of make_dir"""
    return {'actions': [dotils.actions.make_dir(SAMPLE_DIR_NAME)]}

def task_write_file():
    """Sample task showing the use of write_file"""
    return {'actions': [
        dotils.actions.write_file(SAMPLE_FILE_NAME, SAMPLE_FILE_CONTENT)]}

def task_build_dir():
    """Sample task showing the use of build_directory"""
    return {'actions': [dotils.actions.build_directory(SAMPLE_DIR_NAME)]}

def task_remove_file():
    """Sample task showing the use of remove_file"""
    return {'actions': [dotils.actions.remove_file(SAMPLE_FILE_NAME)]}

def task_remove_dir():
    """Sample task showing the use of remove_dir"""
    return {'actions': [dotils.actions.remove_dir(SAMPLE_DIR_NAME)]}

The functions in the actions module return functions that do what you would expect from the name, i.e. dotils.actions.make_dir(SAMPLE_DIR_NAME) returns a function that will make that directory. This helps to make the actions list in each of your steps appear more like a list of actions -- instead of looking like a list of function names.

The only action that is not obvious is ...build_directory(SAMPLE_DIR_NAME). It is helpful to know the full signature of the function:

build_directory(srcdir, destdir=None, builders=DEFAULT_BUILDERS)

It takes all the files in a source directory (including subfolders) and "builds" them into the destination (same as source if not provided). What "builds" means is up to you: provide a mapping of extensions to classes. The classes need only to implement build_file(self, src_file, target_dir).