Previous topic

Building block

Next topic

Commands

This Page

Actions

class soclib_builder.action.Action

An action. This is a step in a build process, corresponding to a set of steps to perform to produce results. An action can be performed directly by Python code, or by running soclib_builder.command.Command objects.

  • Initialization

    __init__(dests, sources, **options)

    Creates a new Action object. It must declare its sources and destinations, and can contain an arbitrary list of optional parameters.

    Parameters:
    • dests – A list of paths strings or soclib_builder.bblock.BBlock objects considered as products of this action.
    • sources – A list of paths strings or soclib_builder.bblock.BBlock objects considered as inputs of this action.
    • options – An arbitrary set of key = value specifications.
  • Working with the action

    prepare()

    Prepare this action:

    • Create directories needed to host produced files
    • Rehash the state of the action: whether it is already done or yet to do.
    is_valid()
    Returns:whether all the output files exist, and are newer than any of the inputs
    add_depends(*users)

    Add a given list of soclib_builder.bblock.BBlock objects as users of this action. This is not necessarily a list of input objects, but can be bblocks needing completion of this action some time before their creation.

    Parameters:users – a list of soclib_builder.bblock.BBlock
  • Managing build steps

    Build steps must be added in order in the action. This is up to Action inheriting class to populate the build steps with the following methods.

    run_command(cmd, cwd = None)

    Add a command to the list of commands associated to this action.

    Parameters:
    create_file(bblock, contents)

    Add a file to create in the build steps.

    Parameters:
    • bblock – A bblock corresponding to a file
    • contents – A string containing the future contents of the file
  • Running the action

    process()

    Synchronously run all the steps involved in the action.

    source_changed()

    Notifies this action that at least one source file changed, and the action must recompute its completion state.

  • API used by the soclib_builder.todo.ToDo

    todo_launch(synchronous = False)

    Run all the associated steps of the action

    Parameters:synchronous – Whether to run the steps in background
    todo_state()
    Returns:one of Action.BLOCKED, Action.DONE or Action.TODO corresponding to the current action’s state.
    todo_can_be_processed()
    Returns:whether the action is ready to be performed
    why_blocked()

    Prints on sys.stdout why this action is blocked.

    todo_get_depends()

    Retrieve all the BBlock objects that are prerequisites of this action.

    todo_clean()

    Delete all products

  • Pretty printing helpers

    These methods can be reimplemented by subclassers in order to provide uniform output format among tools

    stdout_reformat(msg)

    Reformat the stdout of tools

    Parameters:msg – String containing a line of a stdout message
    Returns:A string reformated containing the same data
    stderr_reformat(msg)

    Reformat the stderr of tools

    Parameters:msg – String containing a line of a stderr message
    Returns:A string reformated containing the same data
class soclib_builder.textfile.TextFile(soclib_builder.action.Action)

A simple action that creates a file.

If file already exists, it will be overwritten only if its contents differs from the desired contents.

__init__(output, contents)

Creates a new textfile creation action that will contain the given contents.

Parameters:
  • output – filename of the created file
  • contents – future contents of the file
class soclib_builder.textfile.CxxSource(soclib_builder.textfile.TextFile)

All methods are inherited from soclib_builder.textfile.TextFile.