API

ec

The main module, that allows the configuration of the importing script.

settings(**NewSettings)[source]

Sets the settings of ec.

Settings:
  • helper_tasks (bool): Allow helper tasks ($/*) in the shell (defaults to True).
  • dev_mode (bool): Enables the logging of a detailed traceback on exceptions (defaults to False).
  • clean (bool): cleans the existing settings before applying new settings.
call(__ec_func__, *Args, **KwArgs)[source]

Helps with calling the tasks with partial arguments (within the script being configured).

The unavailable args will be collected before calling the function.

Parameters:
  • __ec_func__ – A function that has been configured for ec.
  • *Args – Partial args for the function.
  • **KwArgs – Partial kwargs for the function.

Notes

  • The param name __ec_func__ is chosen, in order to avoid collision with the KwArgs.
task(__decorated__=None, *Args, **KwArgs)[source]

A decorator to make tasks out of functions.

Config:
  • name (str): The name of the task. Defaults to __decorated__.__name__.
  • desc (str): The description of the task (optional).
  • alias (str): The alias for the task (optional).
arg(name=None, **Config)[source]

A decorator to configure an argument of a task.

Config:
  • name (str): The name of the arg. When ommited the agument will be identified through the order of configuration.
  • desc (str): The description of the arg (optional).
  • type (type, CustomType, callable): The alias for the task (optional).

Notes

  • It always follows a @task or an @arg.
group(__decorated__=None, *Args, **KwArgs)[source]

A decorator to make groups out of classes.

Config:
  • name (str): The name of the group. Defaults to __decorated__.__name__.
  • desc (str): The description of the group (optional).
  • alias (str): The alias for the group (optional).
module(**Config)[source]

Helps with adding configs to Modules.

Note

Config is a same as that of group.

member(Imported, **Config)[source]

Helps with adding imported members to Scripts.

Note

Config depends upon the Imported. It could be that of a task or a group.

exit_hook(__decorated__=None, *Args, **KwArgs)[source]

A decorator that makes the decorated function to run while ec exits.

Parameters:
  • callable (callable) – The target callable.
  • once (bool) – Avoids adding a func to the hooks, if it has been added already. Defaults to True.

Note

Hooks are processedd in a LIFO order.

utils

A set of utility functions for the scripts.

class custom(validator, converter=None, **Config)[source]

Bases: ec.modules.classes.CustomType

Helps with creating dynamic CustomTypes on the fly.

Parameters:
  • validator (callable) – Validates the input.
  • converter (callable) – Converts the input. Defaults to None.
  • **Config (kwargs) – The configuration of the CustomType.
walk(TargetGroup=None)[source]

Walks the members of the given target, recursively.

Parameters:TargetGroup (Group) – The target to walk. Defaults to the BaseGroup.
Yields:Member
get(desc='', type=None, **KwArgs)[source]

Helps to interactively get user input.

Parameters:
  • desc (str) – The description for input.
  • type (type / CustomType) – The type of the input (defaults to None).

Notes

  • When ‘desc’ is not provided, the Kwarg ‘name’ and ‘type_str’ are expected; which will be used to generate a description.
  • KwArgs acts as a data container for unexpected attibutes that are used by underlying helpers.
static(cls)[source]

Converts the given class into a static one, by changing all the methods of it into static methods.

Parameters:cls (class) – The class to be converted.
exit(exit_code=0)[source]

A function to support exiting from exit hooks.

Could also be used to exit from the calling scripts in a thread safe manner.

interface

Allows the importing of ec, as a module.

setBase(Underlying)[source]

Sets the base for the interface to work on.

Parameters:Underlying (Group) – The Group set as the base, from which all the commands are resolved.
resolve(route)[source]

Resolves the member identified by the route.

Parameters:route (str) – The route route to resolve. Ex: group1/task1.
Returns:A Member, if the resolves one, or None if it doesn’t.
call(command, collect_missing=False)[source]

Calls a task, as if it were called from the command line.

Parameters:
  • command (str) – A route followed by params (as if it were entered in the shell).
  • collect_missing (bool) – Collects any missing argument for the command through the shell. Defaults to False.
Returns:

The return value of the called command.

force_config()[source]

Forces the configuration of the members of the calling module. So that the configured members would be available for manipulation.

Note

A call to this function will only be necessary when modifying an ec script witihin itself, as scripts are implicitly configured after their import.

add(TargetGroup, NewMember, Config=None, Args=None)[source]

Adds members to an existing group.

Parameters:
  • TargetGroup (Group) – The target group for the addition.
  • NewMember (Group / Task) – The member to be added.
  • Config (dict) – The config for the member.
  • Args (OrderedDict) – ArgConfig for the NewMember, if it’s a task (optional).