command_interpreter.core – The core functionality

This module implements the core of the command interpreter and any part essential for running it

class vdat.command_interpreter.core.CommandInterpreter(command, command_config, selected=None, multiprocessing=False, processes=None)[source]

Interpret and execute the command.

See The interpreter section in the documentation for more details

All the custom errors are defined in vdat.command_interpreter.exceptions. The ones raised in the constructor are derived from from CIValidationError,

Parameters:
command : string

command to parse

command_config : dict

dictionary containing the instructions to execute the command. A deep copy is executed

selected : list-like, optional

None or a list of the selected items; if None no filtering of the primary files is done; otherwise must be an object supporting the membership test operator in.

multiprocessing : bool

run the command using multiprocessing

processes : int

number of processors to use

Raises:
CINoExeError

if the executable does not exists

CIParseError

if there is some error when extracting the keywords

CIKeywordError

for missing keywords or for keywords of wrong type

CIKeywordTypeError

if the type of the keywords is not among the known ones

make_signals()[source]

Get the signals from the signals and save them in attributes with the same names. Reimplement this method to use custom signals. Refers to the signals documentation for the list and names of signals to implement

run()[source]

Collect the files, expand and run the required command

All the custom errors raised here derive from CIRunError.

Raises:
CICommandFmtError

if the substitution of the command doesn’t work

_replace_alias()[source]

If the command configuration has the is_alias_of replace the executable name

_check_exe()[source]

Check that the executable can be found and replace it with the full path returned by distutils.spawn.find_executable()

_get_keys(command)[source]

Extract the keywords from the command

_validate_mandatory()[source]

Check that all the mandatory keywords are provided.

If mandatory is not found, return without doing anything

_validate_primary()[source]

Check that the primary key is present and that, if it has more that one value, only one primary key is present among the command keys

_validate_keywords()[source]

Check that all the requested keywords are in the configuration

_replace_primary()[source]

If the value of primary is a string, does nothing. Otherwise find which of the primaries is used in the command and replace ``self.config[‘primary’] with it.

Since _validate_primary already checks the primaries, this function can assume that the primary is used only once in the command.

_key_types(keys)[source]

Scan the keys and check that the interpreter knows how to deal with them.

Parameters:
keys : list of strings

keys extracted from the command

Returns:
primary_func : callable

function to call to get the list of primary files

keyword_map : dictionary

map non-primary keywords to the function used to handle them

Raises:
CIKeywordTypeError

if the type of the keyword is not known

_get_value_as_dict(key)[source]

Get the value of key from the configuration. If it’s a string, convert it to a dictionary with two entries:

  • type: plain
  • value: value

and re-add it in the configuration dictionary

Parameters:
key : string

key to get

Returns:
value : dictionary

dictionary defining the type

Raises:
CIKeywordError

if value is not a dictionary or a string

_filter_selected()[source]

Look for the existence of the filter_selected option and check that it is of the correct type and that selected is of the correct type

Returns:
filter_func : function

function that accepts one string (one element of the primary list) and returns True or False if that element is valid or not

_execute()[source]

Look for the existence of the execute option in the configuration and check that it is of the correct type.

Returns:
execute_func : function

function that accepts one string (one element of the primary list) and returns True or False if that element must be run or not

_true(*_, **__)[source]

returns always true